Ruby on Rails ActiveRecord: eager loading issue with foreign and primary key
The eager loading on Ruby on Rails is not working properly for the following scenario.
First we had a model called marks which has the following fields
id, student, subject,开发者_JAVA技巧 markthe student is a string column which has the active directory login value, later on for reporting functionality we introduce another table called user which has the following fields
id, ad_name, full_nameNow on the Mark model, we have added the belongs to class
belongs_to :student_details, :class_name => "User", :foreign_key => "student", :primary_key => "ad_name"
and when loading using the ActiveRecord's find method we are passing in the include conditon for eager loading
Marks.find(:all, :include => :reserved_user)
but when the find is executed, for each and every mark a student select query executed.
Is this a known bug in ROR? or am i missing something?
See ticket. There is a patch attached in comments
精彩评论