mercredi 19 octobre 2016

OR in where clause when working with nested includes or joins with association

I have to use OR in where clause when working with nested includes with association. i have ruby query some thing as :

Inventory.includes(:category,:inventory_tiers,:modifiers=>[:modifier_measures,:modifier_tiers]).where(:categories => { category_tag: 'Dry'},:location_id =>12,:inventory_tiers => {:tier => 1}),modifiers:{category_tag:"Wet"},modifier_tiers:{tier:1})

in which where clause uses AND for all condition. but i want to use OR for last two condition something as :

Inventory.includes(:category,:inventory_tiers,:modifiers=>[:modifier_measures,:modifier_tiers]).where("categories.category_tag=? AND location_id=? AND inventory_tiers.tier = ? OR modifiers.category_tag=? OR modifier_tiers.tier=?", "Wet",12,1,"Wet",1).select("inventories.id,inventories.name,inventories.photo,inventory_tiers.sell_price, modifiers.id,modifiers.name,modifiers.price,modifier_measures.id as measure_id,modifier_measures.name as measure,modifier_measures.price as measure_price,modifier_measures.measure_value")

but its not working. how i can write ?.

Aucun commentaire:

Enregistrer un commentaire