implementing “update if exists” in Doctrine ORM

后端 未结 4 2011
野趣味
野趣味 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 02:13

    The only thing I can think of is to query first for the entity if it exists otherwise create new entity.

    if(!$entity = Doctrine::getTable('Foo')->find(/*[insert id]*/))
    {
       $entity = new Foo();
    }
    /*do logic here*/
    $entity->save();
    

提交回复
热议问题