2014-07-17 11:48
浏览 68

Symfony - doctrine PreUpdateEventArgs错误

I'm working on something with Sonata Admin and I'm trying to update an entity instance that has child instances associated to it and I get the following error.

ContextErrorException: Catchable Fatal Error: Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given, called in ROOT\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 995 and defined in ROOT\vendor\doctrine\orm\lib\Doctrine\ORM\Event\PreUpdateEventArgs.php line 47

To put it in words, I'm trying to save an object called invoice and along with that I'm saving the order objects associated to the invoice.

Here is my code:

    $invoice = ....; //I get this as a parameter to the method
    $manager = $this->getDoctrine()->getManager();
    foreach ($invoice->getOrders() as $order) {
        /** @var Order $order */

The $orders member is annotated as this

 * @ORM\OneToMany(targetEntity="Order", mappedBy="invoice", cascade={"persist"}, orphanRemoval=false)

The strange thing is, if I have only one $order object associated to the invoice everything runs smoothly, but when there are at least 2 everything goes boom.

After some debugging I saw that it is trying to save the second $order object twice and the second time it crashes.

I saw Symfony2 postUpdate listener not working. That one does not have answers and it looks like a different case to me (but not sure).

It makes no difference if I have cascade={"persist"} or not.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题