Symfony2 Doctrine2,是否有'REPLACE INTO'函数


Symfony2 Doctrine2, is there a 'REPLACE INTO' function?

我做了一些研究,显然Doctrine不支持REPLACE INTO,所以我想知道是否有等效的?如果主键不存在,Doctrine是否有办法只执行INSERT INTO ?

类似:

$em = $this->getDoctrine()->getManager();
$em->replace($entity);
$em->flush();

还是我必须把它写成一个条件?如果实体存在,更新,否则插入?

如果主键不存在,可以使用FindOneBy

$entity = $entity->getRepository('Entiy'YOurEntiry')
->findOneBy(array('field1'=>$value,...));

$entity->setField($field);
$entity->flush($entity);