1:m关系:保存订单而不同时保存新的付款方式?

时间:2014-10-23 20:38:29

标签: doctrine-orm doctrine

我在下面有这些实体。它们之间有1:m的关系。

MetodoPagoPayingMethod,已保存在数据库中:"信用卡","现金"等等。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

0 个答案:

没有答案