implementing "update if exists" in Doctrine ORM
According to https://www.vivait.co.uk/labs/updating-entities-when-an-insert-has-a-duplicate-key-in-doctrine this can be achieved with $entityManager->merge()
.
$entity = new Table();$entity->setId(1);$entity->setValue('TEST');$entityManager->merge($entity);$entityManager->flush();
Doctrine supports REPLACE INTO
using the replace()
method. This should work exactly like the ON DUPLICATE KEY UPDATE
you were looking for.
Docs: Replacing Records