I have a little bit of code in my model that looks like this:
query = open
if options.has_key? "user_id"
query = query.where({
:user_id => user_id
})
end
if options.has_key? "shop_id"
query = query.where({
:shop_id => shop_id
})
end
Out of curiosity, is there a way I can tell my query object to simply “retain” the where clauses I’m assigning it (say if both :shop_id and :user_id exist). Thus preventing me from always having to assign the result back to the local query variable?
why not use scopes
for example you will have:
then to call both of them