0
我想在ActiveRecord
一个has_one
关系的查询来选择附加字段选择选项。在使用Lambda:的HAS_ONE关系
的问题是:选择查询的内容必须每选择查询点火时间进行评估,因为我得到一个存储过程的附加字段的值,我需要在运行时传递参数。
我会想象它这样莫名其妙地工作:
class User < ActiveRecord::Base
has_one :profile, :select => lambda { "SELECT profiles.*, my_stored_procedure(#{Time.now}) as virtual_attribute" }
end
我不能使用的范围,因为我需要使用预取上includes
父模型这种关系:
User.includes(:profile).find(1,2,3)
也作为二级预取型号:
OtherModel.includes(:user => [ :profile ])