Answer the question
In order to leave comments, you need to log in
How to properly link tables in Rails?
There are two tables:
hospitals
id | name | ............ | main_doctor_id
doctors
id | fio | ...... | hospital_id
I now bind like this:
Hospital.rb
has_many :doctors
belongs_to :doctor, foreign_key: :main_doctor_id
Doctor.rb
belongs_to :hospital
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question