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

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 c675195
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/models/project.rb
Expand Up @@ -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 --- #

Expand Down
7 changes: 6 additions & 1 deletion app/models/story.rb
Expand Up @@ -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 --- #

Expand Down
7 changes: 6 additions & 1 deletion app/models/task.rb
Expand Up @@ -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 --- #

Expand Down
5 changes: 4 additions & 1 deletion app/models/task_assignment.rb
Expand Up @@ -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 --- #

Expand Down
7 changes: 6 additions & 1 deletion app/models/user.rb
Expand Up @@ -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
Expand Down

0 comments on commit c675195

Please sign in to comment.