に深くネストされた団体のレコードを検索:私は次のモデルを持っているレール
class Book < ApplicationRecord
has_many :chapters
end
class Chapter < ApplicationRecord
belongs_to :book
has_many :pages
end
class Page < ApplicationRecord
belongs_to :chapter
has_many :paragraphs
end
class Paragrpah < ApplicationRecord
belongs_to :page
end
今、私は、特定の本の中ですべての段落のリストを取得したいです。何かのように:私はこれを行うと
@parapgraphs = Paragraph.pages.chapters.book.where(:title => 'My Book')
、私が手:私はRailsの4.2とRuby 2.2
章の方法は、のように「の章」でなければなりません:Parapoints.includes(page:{chapter::book})。ここで(books:{title():@ title:=> 'My Book') – bkunzi01
@parapgraphs = Paragraphs.pages.chapter.book.where : '私の本' }) '(http://stackoverflow.com/questions/18082096/rails-4-scope-to-find-parents-with-no-children/に似ています) – MrYoshiji