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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -