tracks/app/models/dependency.rb

18 lines
607 B
Ruby
Raw Permalink Normal View History

class Dependency < ActiveRecord::Base
2012-09-19 17:13:29 +02:00
# touch to make sure todo caches for predecessor and successor are invalidated
2014-08-14 21:05:05 -05:00
2012-09-19 17:13:29 +02:00
belongs_to :predecessor, :foreign_key => 'predecessor_id', :class_name => 'Todo', :touch => true
belongs_to :successor, :foreign_key => 'successor_id', :class_name => 'Todo', :touch => true
2014-08-14 21:05:05 -05:00
2015-03-16 00:03:34 +01:00
validate :check_circular_dependencies
def check_circular_dependencies
unless predecessor.nil? or successor.nil?
errors.add("Depends on:", "Adding '#{successor.specification}' would create a circular dependency") if successor.is_successor?(predecessor)
end
end
end