I'm trying to implement includes in has_many
/ belongs_to
association similar to this example:
class Author < ApplicationRecord
has_many :books, -> { includes :line_items }
end
class Book < ApplicationRecord
belongs_to :author
has_many :line_items
end
class LineItem < ApplicationRecord
belongs_to :book
end
At the moment when I do @author.books
I see in my console it loads Book
and LineItem
and shows records of Book
, no records for LineItem
. I get undefined method error when I try @author.books.line_items
. Nor does @author.line_items
work.
How do I get LineItem
records for Author
, please? Thank you!