【发布时间】:2010-06-19 10:54:37
【问题描述】:
我有一个有很多战斗的用户模型。战斗属于用户。
战斗表中有两个外键引用回用户PK——challenge_id和challenge_id。
诀窍是如何在 User 模型上编写 has_many 关联,以便它返回 user_id = challenger_id 或 challengee_id 的战斗?
【问题讨论】:
-
猜猜这比想象的要简单:has_many :fights, :foreign_key => 'challenge_id or challengee_id'
标签: ruby-on-rails associations foreign-key-relationship has-many belongs-to