I'm stuck with something that is killing me! So, I have
Order HABTM Product (with a products_order join table)
The join table looks like id | product_id | order_id | quantity | price
At the moment, when I'm making a find call I have the following result
[...]
'Product' => array(
(int) 0 => array(
'id' => '137',
'category_id' => '2',
'restaurant_id' => '10000',
'title' => 'Salade Quan',
'description' => 'Crudités Chinoises, Porc, Crabe, Crevettes',
'price' => '9',
'tva_id' => '2',
'img' => null,
'img_small' => '',
'img_medium' => '',
'maj_img' => '2012-10-24 15:38:56',
'ProductsOrder' => array(
'id' => '35415',
'product_id' => '137',
'order_id' => '15417',
'quantity' => '1',
'price' => '9',
'tva_id' => '2',
'meal' => null
)
),
[...]
But I would like to add more data on a specific product of an order. Typically, a meat product can have a side order / one or multiple sauces ... So, I thought about adding a hasMany relation to a model that represent the join table.
I created the model ProductsOrder which represent the products_order join table. I created a new table extras_order and his model and added a hasMany relation to ProductsOrder model.
And I call the find method like that :
$q = $this->Order->find('first', array(
'conditions' => array(
'Order.id' => $id,
),
'contain' => array(
'Product.Restaurant' => array('title'),
'State' => array('title'),
'Coursier' => array('full_name'),
'Product',
'Product.restaurant_id != ' . AppController::ID_RESTAURANT,
'AddressB' => array('Cp'),
'AddressD' => array('Cp'),
'Customer',
'ProductsOrder'
))
);
But it is not working which make me thing this is not a good solution. I only get
[...]
'ProductsOrder' => array(),
[...]
What do you think ?
Is it a good approach for you ? Where to store additional data of an order ?
Thanks in advance !
EDIT : I finally end up by adding a field in the join table and thinking about adding my extras in json.