I am trying to build a query to search using multiple conditions.
I have tried use Active Record and Areal, both result same exception:
SystemStackError: stack level too deep
def search
table = Model
relation = table[:user_id].eq(user.id)
params.each do |param|
param.each do |attr, value|
relation = relation.or(table[attr].eq(value).and(table[attr].eq(value)).and(table[attr].eq(value)))
end
end
Model.where(relation)
end
This should output a query like:
WHERE (table.attr1 = '1' AND table.attr2 = '5' AND table.attr3 = '7') OR (table.attr1 = '4' AND table.attr2 = '3' AND table.attr3.= '5')
It works when params has small number of hash conditions:
params=[{attr1: 1, attr2: 2, attr3: 4}, {attr1: 4, attr2: 2, attr3: 8}]
However my params has much more than 1000 hash inside for a big query and it this case i got the exception:
SystemStackError: stack level too deep:
I am trying to build a query to search using multiple conditions.
I have tried use Active Record and Areal, both result same exception: SystemStackError: stack level too deep
This should output a query like:
It works when
params
has small number of hash conditions: params=[{attr1: 1, attr2: 2, attr3: 4}, {attr1: 4, attr2: 2, attr3: 8}]However my params has much more than 1000 hash inside for a big query and it this case i got the exception: SystemStackError: stack level too deep:
I have tried a lot of different ways to code this but I always got the same exception.
My question is if there is a limit of number of nodes/conditions or I am doing something really bad here? Is there a way to make this work?