如何在 Kohana 3 ORM 关系中指定两个键
我有一个“答案”表和一个“用户”表。我需要链接它们,但我必须在两个表上使用自定义键(即我不在其中任何一个表中使用“id”)。两个表都有连接它们的“facebook_id”字段。
在答案模型中,我定义了一个“belongs_to”用户,并且可以定义答案的外键,但是我怎么能说“在两个表上使用 facebook_id 将答案链接到用户”呢?
I have a "answers" table and a "users" table. I need to link them but I have to use custom keys on both tables (i.e. I'm not using 'id' in any of them). Both tables have the "facebook_id" field which connects them.
In the Answer model I define a "belongs_to" User, and I can define Answer's foreign_key, but how can I say "link Answer to User using facebook_id on both tables"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来唯一可能的方法是将模型
_primary_key
更改为facebook_id
在调查 ORM 类结构后,您会看到表像这样连接
正如您所提到的你可以使用
但这会导致
但是如果你像这样将答案的主键从 id 更改为 facebook_id
那么当然最终查询会导致
It appears the only way this is possible is by changing your models
_primary_key
tofacebook_id
Upon investigation of the ORM class structure you'll see the tables are joined like so
As you mentioned you can use
But that would result in
But if you change the primary key on answers from id to facebook_id like so
Then of course the final query would result in