Creating a Rails Relationship with a Custom Name

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

But I want to keep the owner of the main administrator company on the company model, but I want to do this with a custom name.

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

How to do it in Rails 3?

+5
source share
1 answer

your company needs another field

owner_id :integer

then add to company

belongs_to :owner, :class_name => "User"
+14
source

All Articles