Answer the question
In order to leave comments, you need to log in
Which link to use in Rails in this example?
There is a table Users (users) and Assistants (assistants), where each user can have several assistants (from users).
Moreover, Assistants have the following structure:
id | main_id (main) | user_id (assistant)
Which link is better to use here (and how), given that all data in Assistants will be taken from Users ???
Answer the question
In order to leave comments, you need to log in
The Assistants table is not needed here, but you just need to set up the associations correctly:
User.rb
has_many :assistants, class_name: 'User', foreign_key: 'main_id', primary_key: 'id'
belongs_to :main, class_name: 'User'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question