mysql - Rails One-One Relationship- Foreign Key Location -


i have 2 models, address , country. address contains basic address info (line1,line2,city,etc.) , has 1 one relationship country.

the countries table read-only, don't want change.

i have forms creating country_id column in "addresses" table, it's looking address_id in country table.

how tell rails use country_id in addresses table lookup country?

here models like:

class address < activerecord::base    belongs_to :consultant    has_one :country    accepts_nested_attributes_for :country    end  class country < activerecord::base    belongs_to :address end 

thanks!

from belongs_to documentation:

this method should used if class contains foreign key.

so code should be:

class address < activerecord::base   has_to :consultant   belongs_to :country   accepts_nested_attributes_for :country    end  class country < activerecord::base   has_one :address end 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -