Answer the question
In order to leave comments, you need to log in
What connection can be created in Rails in this case?
I want to create a functional 'boss-assistant'.
At the beginning, so that a person could send a request for an addition to the circle of his assistants, and those to confirm. It may be that a person can be an assistant to two or three bosses. Therefore, a self-joining relationship cannot be used here.
All will be taken from the User table.
So I think, create an Assistant table, where the fields will be:
main_id - id of the main
assistant_id - id of the assistant
status - status.
But I don't know how to apply links in User.
How to solve the problem or are there other options?
Answer the question
In order to leave comments, you need to log in
Try like this:
# пользователь
class User < ActiveRecord::Base
has_many :bosses, through: :boss_assistants, :source => :user
has_many :assistans, through: :boss_assistants, :source => :user
end
# связь
class BossAssistant < ActiveRecord::Base
belongs_to :boss, :class_name => 'User', :foreign_key => 'boss_id'
belongs_to :assistant, :class_name => 'User', :foreign_key => 'assistant_id'
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question