Union relationships

Hello i have 2 resources. Accounts and Payments. Each payment has 2 relationships to accounts
relationships do
belongs_to :debit_account, Budget.Account
belongs_to :credit_account, Budget.Account
end
relationships do
belongs_to :debit_account, Budget.Account
belongs_to :credit_account, Budget.Account
end
And i want to have one relationship in Account
relationships do
has_many :payments, Budget.Payment
end
relationships do
has_many :payments, Budget.Payment
end
Is there a way how i could have payments relationship to hold both those so i could have one list with all payments to order/paginate/filter on it.
4 Replies
ZachDaniel
ZachDaniel•3y ago
So you basically want payments to be accounts where debit_account_id == id or credit_account_id == id? You can do that with manual relationships, and you can describe how to join on them using AshPostgres.ManualRelationship
ZachDaniel
ZachDaniel•3y ago
Ash HQ
Guide: Join Manual Relationships
Read the "Join Manual Relationships" guide on Ash HQ
roberts.gulans
roberts.gulansOP•3y ago
Thanks mate. Unreal job you have made.
ZachDaniel
ZachDaniel•3y ago
Thanks! 🙇

Did you find this page helpful?