1

Say I have a User class with a json type address field that has keys for city and country like this: adress: {city: 'NY', country: 'USA'} and I want to get all the users that live in an array of country names like: country_names = ['Iran', 'Iraq', 'Yemen']. How do can I do it in Ruby on Rails?

I've tried:

User.where("address->>'country' IN ?", country_names)

but I get a syntax error. what is the correct way?

1 Answer 1

1

The list of values of the IN clause should be enclosed by parentheses:

User.where("address->>'country' IN (?)", country_names)
Sign up to request clarification or add additional context in comments.

Comments

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.