sql - RAILS: has_one association based on non PK column -


i have following tables:

users    [id | name | type]  types   [id | title] 

i need setup has_one association ('users'.type => 'types'.id). but, understand, when write like:

user.rb

has_one :type 

it seems create relation between 'users'.id , 'types'.id. how specify 'users'.type => 'types'.id has_one association?

finally found solution:

user.rb

belongs_to :type 

type.rb

has_many :users, foreign_key: "type_id" 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -