在 Kohana ORM 中使用同一个表的两个不同外键引用表
table user:
|id|name|employee_priority_id|user_priority_id|
table priority:
|id|name|
正如您所看到的,同一个表有两个外部字段。但 Kohana ORM 默认会查找名为priority_id 的字段,该字段不存在。
有没有办法让 Kohana ORM 知道这两个字段是该表的外键。
table user:
|id|name|employee_priority_id|user_priority_id|
table priority:
|id|name|
As you can see, there are two foreign fields to the same table. But Kohana ORM default looks for a field called priority_id, which doesn't exist.
Is there a way to let Kohana ORM know that those two fields are an foreign key to that table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按照记录使用“别名”@ http://docs.kohanaphp.com/libraries /orm/advanced#aliasingenhancing_the_meaning_of_your_relationships
因此,在您的情况下,您的 User_Model 将是:
顺便说一句,根据 Kohana 的约定,表名称应该采用复数形式,除非您覆盖 $table_name,例如:
You can use 'aliasing' as documented @ http://docs.kohanaphp.com/libraries/orm/advanced#aliasingenhancing_the_meaning_of_your_relationships
So in your case, your User_Model would be:
BTW, according to Kohana's convention table names ought to be in plural form unless you override the $table_name, e.g: