collab/app/models/task.rb
2010-03-15 11:47:32 -04:00

32 lines
793 B
Ruby

class Task < ActiveRecord::Base
belongs_to :project
has_many :tasks, :foreign_key => :parent
belongs_to :owner, :class_name => "User", :foreign_key => "owner_id"
belongs_to :assignee, :class_name => "User", :foreign_key => 'assigned_id'
#named scopes
named_scope :parents, :conditions => {:parent => nil}
#validations
validates_presence_of :name, :description, :project_id
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
end