【发布时间】:2012-03-09 05:54:29
【问题描述】:
我想知道是否有一种“正确的”Rails (3.1) 方法可以在不使用查找器 SQL 的情况下执行此操作。
我有一个 STI 层次结构:
class Party
class Person < Party
class Organisation < Party
相关方通过party_relationships 表和模型加入,外键为party_id 和related_party_id
我希望能够做到的是:
class Party
# Should return all party_relationships where the related_party is a Person
has_many :person_relationships
# Should return all party_relationships where the related_party is an Organisation
has_many :organisation_relationships
end
在 Rails 3.1 中最好的方法是什么?
【问题讨论】:
标签: ruby-on-rails associations has-many-through has-many scopes