5

The following command is useful in pulling out all Styles with a certain feature:

Style.joins(:style_features).where('style_features.feature_id= ?', 1)

Is it possible to do the same thing, but for a series of features? As in:

Style.joins(:style_features).where('style_features.feature_id= ?', [1, 2, 3])

2 Answers 2

12

You can simply do:

Style.joins(:style_features).where(style_features: { feature_id: [1, 2, 3] })

This query will let Rails deal with the SQL query depending on the DataBase Adapter you defined.

Sign up to request clarification or add additional context in comments.

Comments

1

you can try with Style.joins(:style_features).where('style_features.feature_id in (?)', [1, 2, 3])

MrYoshiji Answer is better then me if looking at rails way

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.