我在下面有这些实体。它们之间有1:m的关系。
MetodoPago
已PayingMethod
,已保存在数据库中:"信用卡","现金"等等。Pedido
为{ {1}}。
现在我想将付费方式与订单相关联,所以我有这个代码:
Order
此代码的问题:在保存新订单的同时,还保存了新的MetodoPago !!我对此感兴趣,因为我已经保存了所有可用的付费方式。
我的尝试:我试过这个二传手:
$pedido = new Pedido();
$repositoryMetodoPago = $this->getDoctrine()->getRepository('ProjectBackendBundle:MetodoPago');
$metodoPago = $repositoryMetodoPago->find(1);
$pedido->setMetodoPago($metodoPago);
$em = $this->getDoctrine()->getManager();
$em->persist($pedido);
$em->flush();
但是当我尝试运行上面的代码时,我得到了
public function setMetodoPago(\Project\BackendBundle\Entity\MetodoPago $metodoPago = null)
{
$this->metodoPago = $metodoPago->getId();
return $this;
}
Sooo ..我该怎么办?这些是诱惑:
Warning: spl_object_hash() expects parameter 1 to be object, integer given in /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1389