Search code examples
ruby-on-railssqueel

Squeel query comparing 2 variables


Using squeel, I'm able to generate the following request

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"

However, how to get? (CHANGE IN CAPITAL)

=> 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"

If the solution work fine with meta_where as well that's even better ;-)


Solution

  • Thanks to IRC guys hron84, injekt and SIGe

    Here's the solution :

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