开发者

Ruby on Rails ActiveRecord: eager loading issue with foreign and primary key

开发者 https://www.devze.com 2022-12-28 09:15 出处:网络
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

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技巧 mark

the 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_name

Now 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

0

精彩评论

暂无评论...
验证码 换一张
取 消