Skip to content

Commit

Permalink
add-initial-associations
Browse files Browse the repository at this point in the history
The field declarations have been created by the generators, but not the associations. Go ahead and add the associations, just below the `fields do ... end` declaration in each model, as follows:

SHOW_PATCH
  • Loading branch information
bryanlarsen committed Nov 14, 2011
1 parent 6342472 commit b481500
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/project.rb
Expand Up @@ -7,6 +7,8 @@ class Project < ActiveRecord::Base
timestamps
end

has_many :stories, :dependent => :destroy

# --- Permissions --- #

def create_permitted?
Expand Down
4 changes: 4 additions & 0 deletions app/models/story.rb
Expand Up @@ -9,6 +9,10 @@ class Story < ActiveRecord::Base
timestamps
end

belongs_to :project

has_many :tasks, :dependent => :destroy

# --- Permissions --- #

def create_permitted?
Expand Down
5 changes: 5 additions & 0 deletions app/models/task.rb
Expand Up @@ -7,6 +7,11 @@ class Task < ActiveRecord::Base
timestamps
end

belongs_to :story

has_many :task_assignments, :dependent => :destroy
has_many :users, :through => :task_assignments

# --- Permissions --- #

def create_permitted?
Expand Down
3 changes: 3 additions & 0 deletions app/models/task_assignment.rb
Expand Up @@ -6,6 +6,9 @@ class TaskAssignment < ActiveRecord::Base
timestamps
end

belongs_to :user
belongs_to :task

# --- Permissions --- #

def create_permitted?
Expand Down
5 changes: 5 additions & 0 deletions app/models/user.rb
Expand Up @@ -9,6 +9,11 @@ class User < ActiveRecord::Base
timestamps
end

validates_presence_of :name

has_many :task_assignments, :dependent => :destroy
has_many :tasks, :through => :task_assignments

# This gives admin rights and an :active state to the first sign-up.
# Just remove it if you don't want that
before_create do |user|
Expand Down

0 comments on commit b481500

Please sign in to comment.