With Doctrine 2, if you have (for example) a tournament with 2 sponsors (ids 1 and 2), and a user then removes sponsor 1 and adds sponsor 3 in one action (like from a list), what is the best way to sync the changes to the database, so that there is only one delete query and one insert query?

The UI will provide me with the new set of ids, for example "1,3", and I need to use that to determine what has been added, and what has been removed.

1 Answer
1

I had the same situation for linking books to authors. If I wanted to update the author list (via pivot aka linking table) I would just remove all author ids from the pivot table where book_id = 1, then add the new list of authors. This way you don't have to introduce complex logic to determine diffs. Also, it's best if this is wrapped in a transaction.