在MetaWhere 中,我使用循环、if else 语句将条件组合到 sql 变量中。
sql = {}
email_starts_with = "vany%"
sql["growth"] = 0..200
sql = sql & (:rating > 50)
sql = sql & (:email =~ email_starts_with)
.....
.....
User.where(sql).to_sql
=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"growth\" BETWEEN 0 AND 200 AND \"users\".\"rating\" > 50 AND \"users\".\"email\" ILIKE 'vany%'"
user = User.where(sql).first
=> #<User id: 1, .................................. >
我怎样才能使用Squeel做同样的事情?
谢谢你的帮助)