具有 HABTM 关系的 HABTM 连接表
如果我在 HTBTM 关系中有以下数据库表名称:
**dressess**
id
**dressess_categories**
id
dress_id
category_id
**categories**
id
我如何为 HABTM 关系创建数据库表名称需要在 dressess_categories 表中,例如:
**dressess_categories**
id
**colors_dress_categories** <--- It is named right?
id
dress_category_id <--- It is named right?
color_id
**colors**
id
提前致谢。
If i have the following database table names in a HTBTM relantionship:
**dressess**
id
**dressess_categories**
id
dress_id
category_id
**categories**
id
How do I have to create the database table names for an HABTM relationship need it in dressess_categories table, for example:
**dressess_categories**
id
**colors_dress_categories** <--- It is named right?
id
dress_category_id <--- It is named right?
color_id
**colors**
id
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,连接表需要按字母顺序排列模型名称,以便 CakePHP 能够自动识别它们:
现在解决手头的问题:如果我正确理解您的问题,您正在尝试在
Color< 之间创建 HABTM 关联/code> 用于不同 HABTM 关系的模型和连接表?这是不可能的。 (或者如果是的话,这将是一场蛋糕黑客马拉松)。
首先,停止考虑数据库表之间的关系。 CakePHP 模型之间定义关系,并由表驱动它们。为了完成此任务,您需要做的是创建四个模型:
像这样定义关系:
以及五个具有适当外键的表:
First, the join table needs to have the model names in alphabetical order for CakePHP to recognize them automagically:
Now for the problem at hand: If I understand your question correctly, you are trying to create a HABTM association between a
Color
model and the join table that is used for a different HABTM relationship? This is not possible. (or if it is, it will be a cake-hack-a-thon).First, stop thinking of relationships as they relate between database tables. Relationships are defined between CakePHP Models, and the tables drive them. What you will need to do in order to accomplish this task is make four models:
Define relationships like so:
And five tables with the appropriate foreign keys: