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])
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With