Permalink
Browse files

add-initial-associations

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

We're also adding counter\_cache columns to make it easier to sort on the count.
  • Loading branch information...
bryanlarsen authored and iox committed Jun 3, 2013
1 parent a916322 commit c6751956e927a10084a21ce7870b5f2b9539222e
Showing with 26 additions and 5 deletions.
  1. +4 −1 app/models/project.rb
  2. +6 −1 app/models/story.rb
  3. +6 −1 app/models/task.rb
  4. +4 −1 app/models/task_assignment.rb
  5. +6 −1 app/models/user.rb
View
@@ -4,9 +4,12 @@ class Project < ActiveRecord::Base
fields do
name :string
+ stories_count :integer, :default => 0, :null => false
timestamps
end
- attr_accessible :name
+ attr_accessible :name, :stories
+
+ has_many :stories, :dependent => :destroy, :inverse_of => :project
# --- Permissions --- #
View
@@ -6,9 +6,14 @@ class Story < ActiveRecord::Base
title :string
body :text
status :string
+ tasks_count :integer, :default => 0, :null => false
timestamps
end
- attr_accessible :title, :body, :status
+ attr_accessible :title, :body, :status, :status_id, :project, :project_id, :tasks
+
+ belongs_to :project, :inverse_of => :stories, :counter_cache => true
+
+ has_many :tasks, :dependent => :destroy, :inverse_of => :story
# --- Permissions --- #
View
@@ -6,7 +6,12 @@ class Task < ActiveRecord::Base
description :string
timestamps
end
- attr_accessible :description
+ attr_accessible :description, :story, :story_id, :task_assignments, :users
+
+ belongs_to :story, :inverse_of => :tasks, :counter_cache => true
+
+ has_many :task_assignments, :dependent => :destroy, :inverse_of => :task
+ has_many :users, :through => :task_assignments
# --- Permissions --- #
@@ -5,7 +5,10 @@ class TaskAssignment < ActiveRecord::Base
fields do
timestamps
end
- attr_accessible
+ attr_accessible :user, :user_id, :task, :task_id
+
+ belongs_to :user, :inverse_of => :task_assignments
+ belongs_to :task, :inverse_of => :task_assignments
# --- Permissions --- #
View
@@ -8,7 +8,12 @@ class User < ActiveRecord::Base
administrator :boolean, :default => false
timestamps
end
- attr_accessible :name, :email_address, :password, :password_confirmation
+ attr_accessible :name, :email_address, :password, :password_confirmation, :task_assignments, :tasks
+
+ validates_presence_of :name
+
+ has_many :task_assignments, :dependent => :destroy, :inverse_of => :user
+ 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

0 comments on commit c675195

Please sign in to comment.