1

This is my status code array = [1,2,3,4,5], and in my Claim table status_code is there. In that I store status code. Now I want find those Claim that have status code [1,2,4]. Then How can I find.

I write this query : Claim.where("status_code IN (1,2)") that workings but I need to pass array. So How can I pass array in 'In' query.

Thanks For Help.

2
  • You can see the generated SQL: Claim.where(status_code: [1,2,3]).to_sql || Another tip: Claim.where(status_code: 1..5) Commented Apr 7, 2014 at 17:59
  • 1
    What kind of type is status_code? Commented Apr 7, 2014 at 18:00

1 Answer 1

2

Assuming status_code is integer type. You can directly use the array in where clause.

array = [1,2,3,4,5]
Claim.where(status_code: array)

OR

array = [1,2,3,4,5]
Claim.where('claims.status_code IN (?)', array)
Sign up to request clarification or add additional context in comments.

1 Comment

Why is it that you can't just put the array directly in the query?

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.