mandytrex / workout_buddy

0 stars 0 forks source link

Active Record Associations #1

Closed mandytrex closed 9 years ago

mandytrex commented 9 years ago

Hey, I have having a difficult time with one of my relationships. screen shot 2015-01-21 at 9 39 34 am

Attached is a copy of my ERD and my most up to date code is pushed. The relationship I am confused with lies within my Groups Table, the attribute "coordinator_id" -- I would like for this to reference the user_id of the user who created the group. I've reviewed the Active Record associations/migrations documentation and I think my issue is not being certain of what exactly to search for within those documentations to resolve my issue. Let me know if I can explain this better in person

Thanks, Amanda

@htella @DrRobotmck

htella commented 9 years ago

Got this.

htella commented 9 years ago

Does a Group have_many Users and it also has a special User called a coordinator. Is that what you're going for?

mandytrex commented 9 years ago

Yes, I want the user who started the group to be saved as the coordinator for group. So I want that user's ID to be saved as the group's coordinator_id.

Is this possible?

@htella

mandytrex commented 9 years ago

And yes to your first question, a group has many users as well

htella commented 9 years ago

Yup, add an association on Groups that looks like

belongs_to :coordinator, :class_name => 'User', :foreign_key => 'coordinator_id'

Check this out for more of an example. Look the first answer.

http://stackoverflow.com/questions/2684843/belongs-to-with-class-name-option-fails

mandytrex commented 9 years ago

Thank you!