我有一个库存模型和一个供应模型,而库存属于供应模型。
我想根据供应模型的“ date_received”属性对库存记录进行排序
Stock.where("seller_id = ? AND status = ? AND product_id = ?", @seller_id, "Approved", list_item.product_id)
我在以下方面遇到错误:
Stock.includes(:supply).where("seller_id = ? AND status = ? AND product_id = ?", @seller_id, "Approved", list_item.product_id).order("supply.date_received")
答案 0 :(得分:2)
应该是supplies
而不是supply
试试,
Stock.includes(:supply).where("seller_id = ? AND status = ? AND product_id = ?", @seller_id, "Approved", list_item.product_id).order("supplies.date_received")