Saturday, 17 August 2013

link table in cakephp and habtm

link table in cakephp and habtm

Before any advice to read google and etc, i must write that i read a lot
of articles and blogs, and for now i cant figure out how to use HABTM in
my case... ;]
I have order system with 3 tables and 3 models:
ORDERS (order_id, customer_id, paymenyOption, etc...)
ITEMS (item_id, size, color, etc...)
CUSTOMERS (customer_id, name, telephone, etc...)
For now i have relationship between ORDERS<->CUSTOMERS (which works fine),
but i need to have 'link table' in which will be order_id, product_id,
quantity.
To be clear,
one order can have many items
one items can be in many orders
one customer can have many orders (but one order can have one customer)
(normal order-system philoshopy)
I dont know if i must use hasMany or hasAndBelongsTo, and make another
model for 'link table'?
Can anyone explain me this beautiful sh** in cakephp 2.x ? ;-)

No comments:

Post a Comment