开发者

How do I save related data in CakePHP?

开发者 https://www.devze.com 2023-04-06 05:18 出处:网络
I have a \'websites\' and \'products\' table. The a product can be attached to differentwebsites. So I created a new table called \'attached_products\'.开发者_JAVA百科 It has the fields id, website_id

I have a 'websites' and 'products' table. The a product can be attached to different websites. So I created a new table called 'attached_products'.开发者_JAVA百科 It has the fields id, website_id and product_id.

So I have two questions for now, the first one is how do I save a website that will appear something like this in the attached_products table:

id | website_id | product_id
1  |     4      |    3
2  |     4      |    5
3  |     4      |    6
4  |     4      |    10

the above means four products with ids 3,5,6,10 were attached to a website with an id of 4

my second question is, how do I modify the record for example I want to remove the two products attached to a website?

I'm new to CakePHP, many thanks for any help! :)


You have the right idea about what you're doing. Read about HABTM relationship in Cake book. You should learn more about Cake (from simple to complicated things). That one is pretty hard for a newcomer.

0

精彩评论

暂无评论...
验证码 换一张
取 消