2015-12-18 37 views
0

問題我有這個有很多通過我的模型出於某種原因,我不斷收到此錯誤和幫助將不勝感激。有很多通過關聯不工作在升級導軌3到導軌4應用

錯誤

ActiveRecord::HasManyThroughAssociationNotFoundError (Could not find the association #<Proc:[email protected]/home/dev/testapp/app/models/work_order.rb:12> in model WorkOrder)

has_many :demand_supply_links, 
      :through => proc {"select * from demand_supply_link 
            where supply_type = 'WO'" + 
            " and supply_base_id = '" + "#{base_id}" + 
            "' and supply_lot_id = '" + "#{lot_id}" + 
            "' and supply_split_id = '" + "#{split_id}" + "'"} 

,我使用低谷協會

def setup(session) 
    if [email protected]_order.nil? 
    @demand_supply = @work_order.demand_supply_links.first 
    end 
end 
+1

發佈您的代碼包含模型協會 – Bijendra

+0

我編輯我的問題@Bijendra – Snowman288

回答

1

爲什麼不直接定義一個方法爲它而不是has_many :through? e.g

def demand_supply_links 
    DemandSupplyLink.where(supply_type: 'WO', 
          supply_base_id: base_id, 
          supply_lot_id: lot_id, 
          supply_split_id: split_id) 
end 

這將執行您所請求的相同的操作,並不涉及原始的SQL。它也會比字符串連接更好地處理衛生問題。

+0

哈哈謝謝我只是想過,實際上做到這一點之前,我可以檢查我的問題。 @engineersmnky – Snowman288