Christian Bankester
Christian Bankester

Reputation: 2124

How do I create a has_and_belongs_to_many association with one main record

Let's say I have the models Developers and Projects, and developers has_and_belongs_to_many projects and projects has_and_belongs_to_many developers. What is the best way to set up the associations where one of the developer's projects should be his main project?

Upvotes: 2

Views: 105

Answers (1)

Evan Cordell
Evan Cordell

Reputation: 4118

I would go with:

Developer

has_and_belongs_to_many :projects
has_one :main_project, :class_name => "Project"

Assuming the classes are Developer and Project.

Upvotes: 2

Related Questions