English 中文(简体)
Assistance with CakePHP model relationships
原标题:
  • 时间:2009-11-10 21:31:01
  •  标签:
  • orm
  • cakephp

How would I represent the following in a CakePHP model?

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

Cart
====
cart_id
....

Carts_Products
==============
cart_id
product_id
quantity
最佳回答

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
问题回答

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

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

carts
=====
id
create_date
...

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





相关问题
Entity Framework with File-Based Database

I am in the process of developing a desktop application that needs a database. The application is currently targeted to SQL Express 2005 and works wonderfully. However, I m not crazy about having ...

Assistance with CakePHP model relationships

How would I represent the following in a CakePHP model? Product ======= product_id .... Cart ==== cart_id .... Carts_Products ============== cart_id product_id quantity

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How are Models (in MVC) and DAOs supposed to interact?

How are models and DAOs supposed to interact? I m in the process of putting together a simple login module and I m unsure where to put the "business logic." If I put the logic with the data in the ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签