1

I have a simple query that I'm attempting to construct.
I want to pass in parameters to the query.

Product.where('id = ?', 1)

Easy as right.. What to do if the field list and the values are arrays

fields = ['id = ? ', 'type_id = ?', 'brand_id = ?']
values = [1, 1, 1]
Product.where(fields.join(' and '), values)  #does not compute, does not compute!

Anyone know how to pass in the values for a parametrized query?

1
  • FYI: prepared statement !== parametrized query Commented Jan 22, 2013 at 6:55

1 Answer 1

5

You can use * to convert an array into a parameter list:

fields = ['id = ?','type_id = ?','brand_id = ?']
values = [1, 1, 1]
Product.where(fields.join(' and '), *values) 
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.