Properly Setting up Rails Associations for "Favoriting" Items

I’m writing my first Rails app and I’m stuck at the database level. I
have
2 models: User and Mission. They are connected very unremarkably like
so:

User has_many :missions, dependent: :destroy
Mission belongs_to :user

I would like other users to be able to interact with missions by either:
liking
them
and/or marking them as completed

This is all very vanilla stuff here, but I’m struggling with adding this
additional layer of interaction into the models.

I started by creating a table Connection with attributes user_id
mission_id
liked:booleancompleted:boolean

I added the following:

User has_many :connections, dependent: :destroy
Connection belongs_to :user
Connection belongs_to :mission

Do I need a has_many :through relationship? I’m trying to preserve the
ownership between a User and a Mission ( belongs_to association ). I’m
reading about polymorphic associations and am wondering if they are
applicable? Any help would be greatly appreciated. Thanks!

On 3 March 2012 20:22, Kevin P. [email protected] wrote:

additional layer of interaction into the models.

I started by creating a tableConnectionwith
attributesuser_idmission_idliked:booleancompleted:boolean

Since each mission belongs to just one user you can achieve what you
want just by adding the liked and completed booleans to the missions
table. You do not need another table.

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs