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 ])