phalcon php开关更新为插入

phalcon php开关更新为插入,php,phalcon,Php,Phalcon,出于某种原因,phalcon将我的订单替换为插入而不是更新(我可以在日志中看到) 我可能缺少覆盖插入更新的内容。。。那太多了。这是一个特殊的模型,不遵循公共ID模式(如果有帮助的话) 在日志中,我可以看到: [Mon Oct 13 23:49:49.698965 2014] [:error] [pid 379] [client 82.113.121.157:60949] PHP Fatal error: Uncaught exception 'PDOException' with messag

出于某种原因,phalcon将我的订单替换为插入而不是更新(我可以在日志中看到)

我可能缺少覆盖插入更新的内容。。。那太多了。这是一个特殊的模型,不遵循公共ID模式(如果有帮助的话)

在日志中,我可以看到:

[Mon Oct 13 23:49:49.698965 2014] [:error] [pid 379] [client 82.113.121.157:60949] PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "voucher_voucher_code_idx"' in /var/www/api/index.php:41\nStack trace:\n
#0 [internal function]: PDOStatement->execute()\n
#1 [internal function]: Phalcon\\Db\\Adapter\\Pdo->executePrepared(Object(PDOStatement), Array, Array)\n
#2 [internal function]: Phalcon\\Db\\Adapter\\Pdo->execute('INSERT INTO "vo...', Array, Array)\n
#3 [internal function]: Phalcon\\Db\\Adapter->insert('vouchers', Array, Array, Array)\n
#4 [internal function]: Phalcon\\Mvc\\Model->_doLowInsert(Object(Phalcon\\Mvc\\Model\\MetaData\\Memory), Object(Phalcon\\Db\\Adapter\\Pdo\\Postgresql), 'vouchers', false)\n
#5 [internal function]: Phalcon\\Mvc\\Model->save()\n
#6 [internal function]: Phalcon\\Mvc\\Model->update(Array)\n
#7 [internal function]: Phalcon\\Mvc\\Model\\Query->_executeUpdate(Array, Array, NULL)\n
#8 [internal function]: Phalcon\\Mvc\\Model\\Query->execute(Array, NULL)\n
#9 /var/www/api/index.php(41): Phalcon\\Mvc\\Model\\Manager->executeQue in /var/www/api/index.php on line 41

有什么想法吗?

我也有过类似的行为。
似乎Phalcon需要主键上的update
where
子句来更新该特定行。我添加了
id
作为主键,一切正常。
在您的情况下,将
凭证\u code
设置为该表的主键。

希望这有帮助

您能附上与此相关的日志条目吗?感谢您的快速回复。我编辑了这个问题以包含日志。
/var/www/api/index.php(39):Phalcon\\Mvc\\Model->save()
没错,这是我的第二次尝试。我已经更新了新日志。谢谢你的输入。我放弃了这个,但我会给你的解决方案打分,因为它现在是有意义的。
[Mon Oct 13 23:49:49.698965 2014] [:error] [pid 379] [client 82.113.121.157:60949] PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "voucher_voucher_code_idx"' in /var/www/api/index.php:41\nStack trace:\n
#0 [internal function]: PDOStatement->execute()\n
#1 [internal function]: Phalcon\\Db\\Adapter\\Pdo->executePrepared(Object(PDOStatement), Array, Array)\n
#2 [internal function]: Phalcon\\Db\\Adapter\\Pdo->execute('INSERT INTO "vo...', Array, Array)\n
#3 [internal function]: Phalcon\\Db\\Adapter->insert('vouchers', Array, Array, Array)\n
#4 [internal function]: Phalcon\\Mvc\\Model->_doLowInsert(Object(Phalcon\\Mvc\\Model\\MetaData\\Memory), Object(Phalcon\\Db\\Adapter\\Pdo\\Postgresql), 'vouchers', false)\n
#5 [internal function]: Phalcon\\Mvc\\Model->save()\n
#6 [internal function]: Phalcon\\Mvc\\Model->update(Array)\n
#7 [internal function]: Phalcon\\Mvc\\Model\\Query->_executeUpdate(Array, Array, NULL)\n
#8 [internal function]: Phalcon\\Mvc\\Model\\Query->execute(Array, NULL)\n
#9 /var/www/api/index.php(41): Phalcon\\Mvc\\Model\\Manager->executeQue in /var/www/api/index.php on line 41