0
我有以下協會成立Rails的預先加載的條件
class bookinghdr
belongs_to :agent
end
class bookingitem
belongs_to :bookinghdr, :include => agent
end
所以我期待能做到以下幾點:
named_scope :prepay, :include=>["bookinghdr"], :conditions => ["bookinghdr.agent.agenttype = 'PP'"]
,並在我的控制器做:
b = Bookingitem.prepay
但是,這給了我一個ActiveRecord :: StatementInvalid:Mysql ::錯誤:未知列'bookinghdr.agent.agenttyp E」
但是如果我不包括條件子句然後我得到一個記錄上,我可以這樣做:
b = Bookingitem.prepay
b[0].bookinghdr.agent.agenttype
沒有任何錯誤!
我不想得到所有記錄,然後遍歷它們以找到代理人擁有'PP @標誌'的記錄。我希望AR能爲我做到這一點。
有人有任何想法如何實現這一目標?