Answer the question
In order to leave comments, you need to log in
Is it possible to group a query by OR in WHERE using Ransack?
Product.search(product_properties_property_id_eq: 'x', product_propertries_value_eq: 'y')
WHERE (("product_properties"."value" = 'x' AND "product_properties"."property_id" = 'y'))
WHERE (("product_properties"."value" = 'x' OR "product_properties"."property_id" = 'y'))
WHERE(
( product_properties.value = 'x' AND product_properties.property_id = 'y' ) OR
( product_properties.value = 'x1' AND product_properties.property_id = 'y1' ) OR
( product_properties.value = 'x2' AND product_properties.property_id = 'y2' ) OR
)
Answer the question
In order to leave comments, you need to log in
why do you need OR or Ransack for this? use scopes in the model.
def self.properties( properties ) # properties = [1, 2, 3]
if properties.present?
if properties.first == 'all' # я делал себе для выборки товаров со всеми параметрами
properties = Product_property.all.pluck(:property_id)
where(property_id: properties)
else
where(property_id: properties) # WHERE .property_id IN (value1,value2,...);
end
end
end
Product.properties(params[:properties])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question