Doctrine2,更新关系而不提取它

时间:2012-02-20 15:33:57

标签: php orm doctrine doctrine-orm relationship

  

可能重复:
  Doctrine 2, inserting an entity with associations, is there a way to just use the FK of the associations instead of retrieving the entity?

执行以下代码时,我实际上需要从数据库中获取$ type,以便能够更新它与$ asset的关系。

// $asset_id and $type_id originate from the request object

$asset = $em->find('My\Entity\Asset', $asset_id);
$type  = $em->find('My\Entity\AssetType', $type_id);

$asset->setType($type);

$em->persist($asset);
$em->flush();

有没有办法在没有实际获取$ type实体的情况下使用ORM库执行此操作?实际上只是将type_id列设置为$type_id的值就足够了,我不需要实际类型实体,因此可以向DB保存请求。

修改: 解决方案:When inserting an entity with associations, is there a way to just use the FK instead of retrieving the entity?

0 个答案:

没有答案