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.

Rails 3 - Active Record Query that uses includes and select

#6735

I'm shifting my Rails 2 code to Rails 3. I've an active record query

Group.find(:all, :select => 'groups.name',:include => :owner)

In model groups.rb, i've an association defined:
belongs_to :owner, :class_name => "Member", :foreign_key =>"owner_id"

I'm getting an error while running above query:

ActiveModel::MissingAttributeError: missing attribute: owner_id

from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/association_preload.rb:328:in `block in preload_belongs_to_association'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/association_preload.rb:327:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/association_preload.rb:327:in `preload_belongs_to_association'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/association_preload.rb:121:in `block in preload_one_association'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/association_preload.rb:115:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/association_preload.rb:115:in `preload_one_association'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/association_preload.rb:92:in `preload_associations'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/relation.rb:68:in `block in to_a'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/relation.rb:68:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/relation.rb:68:in `to_a'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/relation/finder_methods.rb:143:in `all'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/relation/finder_methods.rb:105:in `find'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/relation/finder_methods.rb:101:in `find'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.6/lib/active_record/base.rb:439:in `find'
from (irb):18
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.6/lib/rails/commands/console.rb:44:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.6/lib/rails/commands/console.rb:8:in `start'

I'm using Rails 3.0.6. Seems like there's a bug introduced in the ActiveRecord 3.0.6. Kindly look into this issue and fix.

Thanks,

Atif

Reported by anathematism · April 21st, 2011 @ 07:40 AM

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

Activity

  1. anathematism
    anathematism
    • Assigned user changed from Yehuda Katz (wycats) to rails

    April 22nd, 2011 @ 06:59 AM

  2. anathematism
    anathematism
    • Assigned user cleared.

    Any update on this?

    April 29th, 2011 @ 06:45 AM