#-- # Copyright (C) 2008 Dimitrij Denissenko # Please read LICENSE document for more information. #++ class TicketPropertyType < ActiveRecord::Base has_many :ticket_properties, :dependent => :destroy, :order => 'ticket_properties.rank, ticket_properties.id' belongs_to :project validates_presence_of :project_id validates_uniqueness_of :name, :scope => :project_id, :allow_nil => true validates_format_of :name, :with => %r{^([A-Z][a-z]*)( [A-Z][a-z]*)*$}, :unless => lambda {|i| i.name.blank? } validates_length_of :name, :in => 2..20 def class_name self.name.gsub(%r{ }, '') end def caption "#{self.project.name}: #{self.name}" end def global? false end def self.default_order(with_associations = false) 'ticket_property_types.rank, ticket_property_types.id' end def self.find_including_associations(id) options = { :conditions => ['ticket_property_types.id = ?', id], :include => [:project, :ticket_properties], :order => 'projects.name, ' + default_order(true) } if result = TicketPropertyType.find(:first, options) result else raise ActiveRecord::RecordNotFound, "Couldn't find #{name} with ID=#{id}" end end end