Squeel查询比较2个变量

时间:2012-02-14 01:36:15

标签: ruby-on-rails squeel

使用squeel,我能够生成以下请求

Payment.joins(:account => :preference).where({:account => {:preference => {:currency => :currency } } }).to_sql
=> SELECT "payments".* FROM "payments" INNER JOIN "accounts" ON "accounts"."id" = "payments"."account_id" INNER JOIN "preferences" ON "preferences"."account_id" = "accounts"."id" WHERE "preferences"."currency" = "preferences"."currency"

然而,如何获得? (资本变动)

=> SELECT "payments".* FROM "payments" INNER JOIN "accounts" ON "accounts"."id" = "payments"."account_id" INNER JOIN "preferences" ON "preferences"."account_id" = "accounts"."id" WHERE "preferences"."currency" = "PAYMENTS"."currency"

如果解决方案与meta_where一起正常工作,那就更好了; - )

1 个答案:

答案 0 :(得分:0)

感谢IRC人员hron84,injekt和SIGe

以下是解决方案:

Payment.joins(:account => :preference).where{account.preference.currency == ~currency }.to_sql