Hello everyone,

I'm a beginner Rails developer and right now am building a sample project
to show off at some job apply. The app is rather simple, I guess, but I
have come to some doubts on what associations to chose and why.

Basically a User can create a bill(being its creditor) and the billing can
have many other Users(as their debtors), so you can track up billings you
share with other persons, like rent, market, food orders etc, and control
what each one got to pay you.

Right now I have the following model:

class User < ActiveRecord::Base
has_many :billings, foreign_key: "creditor_id", dependent: :destroy
has_many :debts, foreign_key: "debtor_id", dependent: :destroy
end

class Billing < ActiveRecord::Base
belongs_to :creditor, class_name: "User"
has_many :debts, dependent: :destroy
end

class Debt < ActiveRecord::Base
belongs_to :billing
belongs_to :user
end

would this be the better approach? Or something like:
User has_many billings through debts
Billing has_many debts ?

And in that case, would appreciate some help to model those associations,
because I'm still kinda lost on this flow.

Thanks in advance,
Diego Dillenburg Bueno

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAOHSkmE893vhkwHsna6e5Ax4fCZipg965brtieXtr9Ui6OAVdw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to