Rails Active Record Query with 3 tables with 1 having both information

Viewed 99

I have an User, Payment, and PaymentRefund, Invoice tables

Voucher has_many Payments
Payment belongs_to User belongs_to Invoice
PaymentRefund has User and has Payment
Invoice has_many Payments

I have this query

User.joins(:payment).where('payments.status': 'settled', 'payments.invoice_id': @invoice.id)

What I want is this including User objects that do is not part of the PaymentRefund. Can someone help me with this active record query?

Currently getting this by

vouchers = Voucher.joins(:payment).where('payments.status': 'settled')

payment_refunds = PaymentRefunds.where(user_id: @user, invoice_id: invoice.id)
vouchers - payment_refunds
0 Answers
Related