New Discussion

Notifications

You’re not receiving notifications from this thread.

Is it possible to make multiple belongs_to or has_one association?

0
Rails

I have a table Operations with two columns referenced to Accounts. One column is called debit_id and other credit_id. Model looks like

    belongs_to :debit,  class_name: :Account, optional: true
    belongs_to :credit, class_name: :Account, optional: true

So I want to include reference to Ledger model that is referenced in Accounts model from Operations. I don't have direct account_id in my Operations I need some workaraound as far as it's impossible to do smth like that

has_one :ledger, through: :debit
has_one :ledger, through: :credit

Is it possible at all in Rails?

Join the discussion
Create an account Log in

Learning Ruby on Rails? Join our newsletter.

We won't send you spam. Unsubscribe at any time.