我的模型Passage
表明has_many
翻译和has_one
音译。我想在给定资源ID的情况下过滤关联。
class Passage < ActiveRecord::Base
has_many :translations, class_name: 'Content::Translation', foreign_key: 'passage_key'
has_one :transliteration, class_name: 'Content::Transliteration', foreign_key: 'passage_key'
end
class Content::Translation < ActiveRecord::Base
belongs_to :resource, class_name: 'Content::Resource'
belongs_to :passage, class_name: 'Passage', foreign_key: 'passage_key'
end
class Content::Transliteration < ActiveRecord::Base
belongs_to :resource, class_name: 'Content::Resource'
belongs_to :passage, class_name: 'Passage', foreign_key: 'passage_key'
end
鉴于我有一系列资源ID,我希望过滤Content::Translation
和Content::Transliteration
关联,我该怎么做?