0

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")
1
  • it should be table name in order clause like supplies Commented May 14, 2019 at 12:11

1 Answer 1

2

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")
Sign up to request clarification or add additional context in comments.

3 Comments

I am getting this error: PG::AmbiguousColumn: ERROR: column reference "seller_id" is ambiguous LINE 1: ... ON "supplies"."id" = "stocks"."supply_id" WHERE (seller_id ...
you must have seller_id in both tables. stocks.seller_id will solve your problem.
@BhimasenRautaray use table name with column name in where clause query like "stocks.seller_id = ?" this will resolve the exception

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.