implementing “update if exists” in Doctrine ORM

后端 未结 4 2010
野趣味
野趣味 2020-12-10 01:46

I am trying to INSERT OR UPDATE IF EXISTS in one transaction.

in mysql, I would generally use DUPLICATE KEY (\"UPDATE ON

4条回答
  •  无人及你
    2020-12-10 01:55

    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();
    

提交回复
热议问题