Rails过滤两个相关模型

时间:2016-05-19 09:04:46

标签: ruby-on-rails

我的模型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::TranslationContent::Transliteration关联,我该怎么做?

0 个答案:

没有答案