collab/app/models/task.rb

32 lines
824 B
Ruby
Raw Normal View History

2010-03-04 06:22:45 +00:00
class Task < ActiveRecord::Base
belongs_to :project
has_many :tasks, :foreign_key => :parent
2010-03-05 06:48:00 +00:00
belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
belongs_to :assignee, :class_name => "User", :foreign_key => 'assigned_id'
#named scopes
2010-03-04 22:42:09 +00:00
named_scope :parents, :conditions => {:parent => nil}
2010-03-05 06:48:00 +00:00
#validations
2010-03-04 06:22:45 +00:00
validates_presence_of :name, :description, :project_id
validates_associated :project
2010-03-05 06:48:00 +00:00
validate :assignee_validation, :owner_validation
def assignee_validation
unless assigned_id.blank?
unless User.exists?(assigned_id)
errors.add :assignee, "Assignee doesn't exist"
end
end
end
def owner_validation
unless owner_id.blank?
unless User.exists?(owner_id)
errors.add :owner, "Owner doesn't exist"
end
end
end
2010-03-04 06:22:45 +00:00
end