Doctrine2.5 getReference和merge update无效

时间:2016-05-04 18:15:48

标签: doctrine-orm merge

我在使用Doctrine 2.5时遇到一个奇怪的问题,同时尝试更新我的表UserProfile,其中我的列BusinessActivity是一个外键。

案例1)使用getReference()

update可以使用,但不适用于BusinessActivity列。

$myid = 6;
$businessActivity = $entityManger->getReference('BusinessActivity', 6);

//$businessActivity proxy object was created correctly with id 6
$userDetails->setBusinessActivity($businessActivity);

$entityManger->merge($userDetails);

// FLUSH AND COMMIT

案例2)使用存储工作从DB创建对象

$rep               = $entityManager->getRepository('BusinessActivity');
$businessActivity  = $rep->findOneBy(array('idActivity' => 6);

$userDetails->setBusinessActivity($businessActivity);

//FLUSH AND COMMIT

当然,我已经有了id,我不想用findOneBy执行查询。

为什么会这样?

0 个答案:

没有答案