Eager loading a has_many :through (Rails3)

Hello all,

I’ve been trying out Rails 3 and can’t get past this issue:

I have a simple has_many :through:

class Author < ActiveRecord::Base
has_many :author_series
has_many :series, :through => :author_series
end

class Series < ActiveRecord::Base
has_many :author_series
has_many :authors, :through => :author_series
end

In my controller I would like to eager load all of the authors:

@series = Series.includes(:authors).all

This will eager load the intermediate class, but only loads the first
author record. When I iterate the others, they are each fetched
individually (N+1).

Any help would be appreciated.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs