This project is archived and is in readonly mode.
ActiveRecord :include doesn't work with foreign keys
Reported by johnny | June 11th, 2009 @ 03:04 PM | in 2.x
When creating a belongs_to association in an ActiveRecord model it's possible to have the model eager load the associated model. For example:
class Student < ActiveRecord::Base
belongs_to :lecturer
end
Using: Student.find(:all, :include => :lecturer) - should bring all the students and their lecturers, resulting in a query like "SELECT * from lecturers WHERE id IN (1, 2, 3)".
However, if we use a foreign key like so:
class Student < ActiveRecord::Base
belongs_to :lecturer, :foreign_key => :some_key
end
Using the above find will eager load only the lecturer for the first student. The rest will be lazy loaded.
Comments and changes to this ticket
-
CancelProfileIsBroken August 2nd, 2009 @ 11:13 AM
- Tag changed from :include, activerecord, foreign_key to :include, activerecord, bugmash, foreign_key
-
Cristi Balan August 8th, 2009 @ 11:36 AM
- Tag changed from :include, activerecord, bugmash, foreign_key to :include, activerecord, bugmash, foreign_key, patch
not reproducible
Added a patch with a test that proves it's working correctly.
-
Gabe da Silveira August 9th, 2009 @ 12:09 PM
not reproducible for me either. this would be a major bug that people would notice quickly. Must be some local interaction you're having Johnny.
-
CancelProfileIsBroken August 9th, 2009 @ 08:03 PM
- Tag changed from :include, activerecord, bugmash, foreign_key, patch to :include, activerecord, foreign_key, patch
- State changed from new to invalid
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>