Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a Rails relationship with a custom name

I have a model called company and one called user, and User belongs to Company and Company has many Users.

But I want to store on the company model the master company admin user, but I want to do it with a custom name.

So, i want to do this: comapany.owner.name .

How can I do this in Rails 3?

like image 951
Mateus Pinheiro Avatar asked Feb 24 '11 15:02

Mateus Pinheiro


1 Answers

your Company needs one additional field

owner_id :integer

then add to Company

belongs_to :owner, :class_name => "User"
like image 142
m4risU Avatar answered Sep 22 '22 17:09

m4risU