0

使用 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 上也能正常工作,那就更好了 ;-)

4

1 回答 1

0

感谢 IRC 人员 hron84、injekt 和 SIGe

这是解决方案:

Payment.joins(:account => :preference).where{account.preference.currency == ~currency }.to_sql
于 2012-02-14T10:40:28.820 回答