nsturgis/Task_galaxy — pull request #1 by hchood (2014-09-16 15:05:06+00:00)
Title: Hh review

Hey Nick,

Good job. This is mostly right, with a few issues:

**Need a `UserTaskList` join table.** The main one is that you should have a join table between `User` and `TaskList`, since it's a many-to-many relationship: a `User` can have many `TaskList`s, and a `TaskList` can have many `User`s. The `has_and_belongs_to_many` is kind of a way around this, but it's deprecated and the better practice is to create a join table and set up your associations like so:

```ruby
# migration to create the join table
class CreateUserTaskLists < ActiveRecord::Migration
def change
create_table :user_task_lists do |t|
t.integer :user_id, null: false
t.integer :task_list_id, null: false

t.timestamps
end
end
end
```
```ruby
# app/models/user_task_list.rb
class UserTaskList < ActiveRecord::Base
belongs_to :user
belongs_to :task_list
end
```
```ruby
# app/models/task_list.rb
class TaskList < ActiveRecord::Base
has_many :user_task_lists
has_many :users, through: :user_task_lists

# ...
end
```

```ruby
# app/models/user.rb
class User < ActiveRecord::Base
# instead of has_and_belongs_to_many, use a join table with a has_many through association
has_many :user_task_lists
has_many :task_lists, through: :user_task_lists

# ...
end
```