ruby - Making two associations to same model column in Rails -


i'm pretty new rails. i'm trying setup associations model in rails.

i have user model columns: id, user_name, email

now trying create model expense has associations user model. purpose of model create expense , associate expense 2 different users same model user. association second user split amount between 2 users.

this i'm intending while creating model expense:

$ rails generate model expense amount:decimal user:references split_with:references 

now how associate split_with user model, since both references associate same user model's id of 2 users?

you can refer same model 2 different ways:

class expense < activerecord::base   belongs_to :user   belongs_to :approving_user,     class_name: 'user' end 

this require columns user_id , approving_user_id present. can adjust generated migration , model code match this.

as sure index: true set on these columns.


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -