I have the following models:
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
Now I want to get a list of all paragraphs in a specific book. Something like:
@parapgraphs = Paragraph.pages.chapters.book.where(:title => 'My Book')
When I do this, I get:
undefined method 'chapters' for 'pages'
I'm using Rails 4.2 and Ruby 2.2