This project is archived and is in readonly mode.
Interpolated association conditions and Eager loading
Reported by Bogdan Gusiev | December 12th, 2010 @ 01:41 PM
Suppose we have association like this:
has_one :company_relation, :foreign_key => :company_id, :primary_key => :company_id,
:conditions => 'company_relations.owner_id = #{self.owner_id}'
In this case eager loading by this association fail because conditions are evaluated in class but not in each instance
Model.all(:include => :company_relation)
NoMethodError: undefined method `owner_id' for #<Class:0xb6635838>
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:381:in `interpolate_sql_for_preload'
from /var/lib/gems/1.8/gems/will_paginate-2.3.12/lib/will_paginate/finder.rb:170:in `method_missing'
from (eval):1:in `interpolate_sql_for_preload'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:386:in `append_conditions'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:366:in `find_associated_records'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:230:in `preload_has_one_association'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:120:in `send'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:120:in `preload_one_association'
from /var/lib/gems/1.8/gems/activesupport-2.3.8/lib/active_support/ordered_hash.rb:115:in `each'
from /var/lib/gems/1.8/gems/activesupport-2.3.8/lib/active_support/ordered_hash.rb:115:in `each'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:114:in `preload_one_association'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:91:in `preload_associations'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:90:in `preload_associations'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:90:in `each'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/association_preload.rb:90:in `preload_associations'
from /var/lib/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1580:in `find_every'
Comments and changes to this ticket
-
Mick Staugaard January 20th, 2011 @ 08:38 PM
This is a dark corner case in ActiveRecord, and it looks like this feature has been removed from ActiveRecord 3.
Not continuing my patch.
-
rails April 21st, 2011 @ 01:00 AM
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails April 21st, 2011 @ 01:00 AM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>