D
D
dimitriy162014-03-31 21:28:59
Ruby on Rails
dimitriy16, 2014-03-31 21:28:59

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

On cyberforum, they suggested to write in Hospital.rb: this thing:
belongs_to :doctor, as: :main_doctor, foreign_key: :main_doctor_id
But for me it swears at the as argument .
Tell me how to connect correctly and how to get main_doctor for each Hospital.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dexdev, 2014-03-31
@dimitriy16

has_many :executors, :class_name => 'Post', :foreign_key => 'executor_id'

something like that...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question