I have this SQL query to select some of my offers and it works as expected.
SELECT * FROM `offers` WHERE region='26'
AND EXISTS (
SELECT * FROM `modificator_values` WHERE
`modificator_values`.`offer_id`=`offers`.`id` AND
(modificator_values.modificator_id = "5") AND (modificator_values.data = "data1")
)
AND EXISTS (
SELECT * FROM `modificator_values` WHERE
`modificator_values`.`offer_id`=`offers`.`id` AND
(modificator_values.modificator_id = "8") AND (modificator_values.data = "data2")
)
Is there a way to optimize it and do it using ActiveRecord query API?