Cakephp 关系
我有一些模型不是默认的 cakephp 格式
user(id, name...)
1 Harsha ...
2 John ....
dishes(id, name, Price ...)
1 "Cheese Pizza" 6
2 "Zinger Burger" 3
餐厅(id,名称,......)
1 "KFC" ...
2 "Pizza Hut" ...
模块(id,名称)值(用户,菜肴,餐厅)
1 "Users"
2 "Dishes"
3 "Restaurant"
项目(id,module_id,item_id)< /strong>
1 1 1 (refers to User Harsha)
2 3 2 (refers to Pizza hut)
3 2 2 (refers to Zinger Burger)
4 1 2 (refers to User John)
其中 item_id 指的是用户、菜肴或休息的 ID,具体取决于 module_id
评论(id、parent_id、评论、时间、item_id、commenter_id)
1 0 "Best Burger in the world" "time" 3 1 (refers to Harsha reviewing Zinger Burger)
2 1 "Yes i love Zingers tooo" time 3 2 ( refers to John replying to Harsha's Review)
我对如何绘制有点混乱建立cakephp中的关系
I have a few models which are not in the default cakephp format
user(id, name....)
1 Harsha ...
2 John ....
dishes(id, name, price ...)
1 "Cheese Pizza" 6
2 "Zinger Burger" 3
restaurants (id, name, .....)
1 "KFC" ...
2 "Pizza Hut" ...
module(id, name) values (User, Dishes, Restaurants)
1 "Users"
2 "Dishes"
3 "Restaurant"
items (id, module_id, item_id)
1 1 1 (refers to User Harsha)
2 3 2 (refers to Pizza hut)
3 2 2 (refers to Zinger Burger)
4 1 2 (refers to User John)
where item_id refers to the Id of Users, Dishes or Rests Depending on the module_id
reviews (id, parent_id, review, time, item_id, commenter_id)
1 0 "Best Burger in the world" "time" 3 1 (refers to Harsha reviewing Zinger Burger)
2 1 "Yes i love Zingers tooo" time 3 2 ( refers to John replying to Harsha's Review)
I am a little messged up on how to draw up the relationships in cakephp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在此页面的书中: http://book.cakephp.org/ view/1039/Associations-Linking-Models-Together 您将找到可以在关系上设置的可能键的指南,例如
假设评论和项目是其关联中的子项,对于关系的两端,您可以将foreignKey 设置为“item_id”。
例如:
很难更精确,但您还没有提供任何数据模型。要通过模块处理模型的选择,您需要在模型的某个位置编写一些代码,具体代码取决于您访问数据的方式。
然而,在我看来,现在是重组数据库的好时机!
In the book at this page: http://book.cakephp.org/view/1039/Associations-Linking-Models-Together you'll find a guide to the possible keys you can set on the relationship, e.g.
Assuming reviews and items are children in their associations, for both ends of the relationships, you'd set the foreignKey as 'item_id'.
Something like:
It's difficult to be more precise, but you haven't provided any datamodel. To handle the selection of Model via the Module, you'll need to write some code on a model somewhere, which one(s) depends on how you access the data.
However, it looks to me like a good time to restructure the database!