Reputation: 301
I have a stock model and supply model and stock belongs to supply model.
I want to sort stock records based on "date_received" attribute of supply model
Stock.where("seller_id = ? AND status = ? AND product_id = ?", @seller_id, "Approved", list_item.product_id)
I am getting error for below:
Stock.includes(:supply).where("seller_id = ? AND status = ? AND product_id = ?", @seller_id, "Approved", list_item.product_id).order("supply.date_received")
Upvotes: 0
Views: 39
Reputation: 828
there just should be supplies
instead of supply
Try,
Stock.includes(:supply).where("seller_id = ? AND status = ? AND product_id = ?", @seller_id, "Approved", list_item.product_id).order("supplies.date_received")
Upvotes: 2