I'm doing a ManyToMany Unidirectional relation from Orders to Products that one order can have many products and one product can be in many orders.
See my code:
/**
* @ManyToMany(targetEntity="Product")
* @JoinTable(name="dc_order_products",
* joinColumns={@JoinColumn(name="order_id", referencedColumnName="id")},
* inverseJoinColumns={
* @JoinColumn(name="product_id", referencedColumnName="id"),
* @JoinColumn(name="product_price", referencedColumnName="product_price")
* })
**/
protected $order_products;
I didn't find in all the google how to use multiple @JoinColumns in inverseJoinColumns so i just copied the first one and separated by comma.
The problem is, when i run the project with this code:
$p = new \Entities\Product(get_date(), 'Product Name', 'Description', 39, 85, 0, 0, 1);
$em->persist($p);
$em->flush();
$o = new \Entities\Order($u->getUserId(), get_date(), 1, 150);
$o->addOrderProduct($p);
$em->persist($o);
$em->flush();
It gives to me:
Integrity constraint violation: 1048 Column 'product_price' cannot be null
But the price is defined, i did a print_r in product object and there it was.
What i missing?