We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

ODM Updating with save cause duplicate entries

Hello guys!

I'm fighting with a problem for a considerable time, and I can't find a nice way to fix my issue.

Let's say I have two tables:

uses (id, name)

uses_phone (id, user_id, phone)

Supposing I have created a users (1, 'Mary') and her phones users_phones (1, 1, '123') (2, 1, '333')

If I want to update Mary, to change her name to "Maria":

The save() method will NOT delete the actual records in users_phone, but will insert new entries, and then I will have:

1, 1, 123
2, 1, 333
3, 1, 123
4, 1, 333

Which is the best way to solve this issue? I'm a bit confused. I like using Model instead PHQL (I like it too, but Models with ODM seems quie magic).

Thanks for reading and please forgive my bad English.

Can you update your question with the code used to save records? Also be sure to check your model afterSave() or other similar event methods.

Having this same problem. Extremely frustrating. Code:


Creates duplicate entries. How is this even possible when using update()?


We has same issue and creation of PRIMARY KEY for table solved it for us. Hope it will help you as well!