ik heb een object "Order" en dat object heeft een array van orderDetails (classe: "OrderDetail").
Bij een nieuwe order wil ik zowel de order als de orderdetails in de database stoppen, en dat lukt perfect behalve de relatie tussen de twee objecten. Het "order_id" veld in de order_detail tabel blijft leeg. Hoe kan ik dat voorkomen?
Code waar ik de insert doe:
$order = $form->getData();
$this->om->persist($order);
$this->om->flush($order);
Dump van $order
object(Jds\ApiBundle\Entity\Order)[439]
protected 'id' => null
protected 'orderDate' =>
object(DateTime)[611]
public 'date' => string '2015-01-15 13:42:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)
protected 'orderDetails' =>
object(Doctrine\Common\Collections\ArrayCollection)[440]
private '_elements' =>
array (size=2)
0 =>
object(Jds\ApiBundle\Entity\OrderDetail)[667]
protected 'id' => null
protected 'product' =>
object(Jds\ApiBundle\Entity\Product)[736]
...
protected 'price' => float 1
protected 'amount' => int 2
protected 'order' => null
1 =>
object(Jds\ApiBundle\Entity\OrderDetail)[702]
protected 'id' => null
protected 'product' =>
object(Jds\ApiBundle\Entity\Product)[749]
...
protected 'price' => float 1
protected 'amount' => int 5
protected 'order' => null
Order-entity:
<?php
/**
* @ORM\Entity()
* @ORM\Table(name="the_order")
*/
class Order implements OrderInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer", length=6)
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"orderList"})
*/
protected $id;
/**
* @ORM\Column(type="datetime", nullable=false)
* @Serializer\Groups({"orderList"})
*/
protected $orderDate;
//protected $orderedBy;
//protected $handledBy;
/**
* @ORM\OneToMany(targetEntity="OrderDetail", mappedBy="order")
* @Serializer\Groups({"orderList"})
**/
protected $orderDetails;
[/code]
OrderDetail-entity
<?php
/**
* @ORM\Entity()
* @ORM\Table(name="order_detail")
*/
class OrderDetail
{
/**
* @ORM\Id
* @ORM\Column(type="integer", length=8)
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Product")
* @Serializer\Groups({"orderList"})
*/
protected $product;
/**
* @ORM\Column(type="decimal", precision=4, scale=2)
*/
protected $price;
/**
* @ORM\Column(type="integer", length=2)
* @Serializer\Groups({"orderList"})
*/
protected $amount;
/**
* @ORM\ManyToOne(targetEntity="Order", inversedBy="orderDetails")
**/
protected $order;
[/code]