tags:

views:

76

answers:

2

How would I represent the following in a CakePHP model?

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

Cart
====
cart_id
....

Carts_Products
==============
cart_id
product_id
quantity
A: 

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

jkndrkn
"RTFM" isn't a very helpful response. Next time, try (gently) explaining that it's pretty well covered in such-and-such section of the docs, and (if possible) provide a link. See deizel's response for a great example.
Travis Leleu
Thanks. I did find a relevant documentation page and use neutral language, but perhaps my response was interpreted as aggressive due to its terseness?
jkndrkn
It was the implication that he hadn't already tried reading that page 'carefully' that came off sounding harsh.I believe that if you have the time to post the link, you could also post a copy pasted example from the page.This lets them see the code here, as well as gives them a visual clue in the code snippet as to what part of the page they should be more careful reading.
Abba Bryant
+2  A: 

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
deizel