Placing the foreign key in rails model belongs_to association
I am a beginner to rails framework. I have a fundamental question.

I am trying to define some models and their association referring the popular rails guides. My association looks like below.

    class Person < ActiveRecord::Base
      has_one :head
    end
    
    class Head < ActiveRecord::Base
      belongs_to :person
    end

Here, I need to add the foreign_key (Persons's primary key) in the table 'head'.

Now, if I need to get the 'head' of a 'person', rails need to scan through the head table and match the person_id. 

The straight forward way I would think is to add the foreign key in 'person' table. Then I can directly refer the 'head' from 'person' with it's ID.

It appears that rails convention is not performance friendly. Am I missing something here?

Thanks in advance for your help. 

Ar
Placing the foreign key in rails model belongs_to association
===

I am a beginner to rails framework. I have a fundamental question.

I am trying to define some models and their association referring the popular rails guides. My association looks like below.

    class Person < ActiveRecord::Base
      has_one :head
    end
    
    class Head < ActiveRecord::Base
      belongs_to :person
    end

Here, I need to add the foreign_key (Persons's primary key) in the table 'head'.

Now, if I need to get the 'head' of a 'person', rails need to scan through the head table and match the person_id. 

The straight forward way I would think is to add the foreign key in 'person' table. Then I can directly refer the 'head' from 'person' with it's ID.

It appears that rails convention is not performance friendly. Am I missing something here?

Thanks in advance for your help. 

Ar