我正在尝试通过Rails生成这个SQL语句:
SELECT * FROM reward_cards
INNER JOIN reward_card_payments
ON reward_card_payments.reward_card_id = reward_cards.id
INNER JOIN payments
ON payments.id = reward_card_payments.payment_id AND payments.amount < 0;
是否存在类似于此的'rails'方式:
RewardsCard.joins(reward_card_payments => {:payments => payments.amount < 0})
答案 0 :(得分:0)
我能找到的最佳方式是
RewardsCard.joins(:reward_card_payments).joins(
'INNER JOIN payments
ON payments.id = reward_card_payments.payment_id AND payments.amount < 0'
)