Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Association pre-loading fails with has_and_belongs_to_many (2.1.0)

#363

Association pre-loading fails with has_and_belongs_to_many if additional includes are defined.

class User < ActiveRecord::Base
  has_and_belongs_to_many :groups, :include => [:permissions] # works if :include => [:permissions] is NOT specified
end
class Group < ActiveRecord::Base
  has_and_belongs_to_many :permissions
end
class Permission < ActiveRecord::Base
end
User.find 1, :include => [:groups]

NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:45:in `add_preloaded_records_to_collection'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:63:in `set_association_collection_records'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:61:in `each'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:61:in `set_association_collection_records'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:109:in `preload_has_and_belongs_to_many_association'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:40:in `send'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:40:in `preload_one_association'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:38:in `each'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:38:in `preload_one_association'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:17:in `preload_associations'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:16:in `preload_associations'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:16:in `each'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:16:in `preload_associations'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1343:in `find_every'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1376:in `find_one'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1362:in `find_from_ids'
	from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:537:in `find'
	from (irb):8

Reported by Dimitrij Denissenko · June 7th, 2008 @ 04:36 PM

State: duplicate
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Dimitrij Denissenko
    Dimitrij Denissenko

    Might be related to [#306]

    June 7th, 2008 @ 04:38 PM

  2. Dimitrij Denissenko
  3. Pratik
    Pratik
    • State changed from new to duplicate
    • Tag set to activerecord, association_preload, bug, eager_loading

    July 23rd, 2008 @ 02:11 PM