0
votes

How would I represent the following in a CakePHP model?

Product
=======
product_id
....

Cart
====
cart_id
....

Carts_Products
==============
cart_id
product_id
quantity
3

3 Answers

2
votes

Since you are storing data in your join table (for a HABTM relation), you're situation looks quite similar to Rail's 'through' relation (seen at the bottom of this diagram). As such, you will want to create a model for that table and use Cake's 'with' relation setting seen on the HABTM page of the book. You should then be able to access the data stored on the join table. By convention...

  • your tables should be named products, carts, carts_products
  • your models should be named Product, Cart, CartsProduct
0
votes

I would also add that (for CakePHP2) the column names for product and cart need to change.

products
========
id
name
...

carts
=====
id
create_date
...
-1
votes

I believe the answer to your question will be revealed on careful reading of this documentation page.