This is the way it is supposed to be. From the Rails Doc
The distinction is in where you place the foreign key (it goes on the table for the class declaring the belongs_to association)
This means that since your Address
model declares the belongs_to
, that is where the foreign key should be placed.
What rails does behind the scenes when you search for user.address
is does a search for the Address
that has a user_id
equal to the current user
's id.
Something like:
Select * From addresses where user_id = <current_user>.id