squeel

Squeel and rails… dynamic where clause

这一生的挚爱 提交于 2019-12-02 01:19:56
问题 Using Squeel, in a rails app, I have a hash of conditions: {'trans' => 'manual'} which i eventually plan on moving into an array... so i can also have an operator assignment. [[field,operator,value][field,operator,value]] I want to use a Model method, which for now i omit the operator and am I just trying == to get this to work... however, what i have below does not work. def self.with_conditions(conditions) joins{car}.where do conditions.map {|key,value| (key==value) }.inject(:&) end end I

Squeel and rails… dynamic where clause

情到浓时终转凉″ 提交于 2019-12-01 22:10:37
Using Squeel, in a rails app, I have a hash of conditions: {'trans' => 'manual'} which i eventually plan on moving into an array... so i can also have an operator assignment. [[field,operator,value][field,operator,value]] I want to use a Model method, which for now i omit the operator and am I just trying == to get this to work... however, what i have below does not work. def self.with_conditions(conditions) joins{car}.where do conditions.map {|key,value| (key==value) }.inject(:&) end end I also tried this: def self.with_conditions(conditions) joins{car}.where do query = nil conditions.each do