mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-06 09:18:50 +01:00
fix #1754
This commit is contained in:
parent
5718eac5c3
commit
0edc263c7e
3 changed files with 11 additions and 13 deletions
|
|
@ -5,5 +5,13 @@ class Dependency < ActiveRecord::Base
|
|||
belongs_to :predecessor, :foreign_key => 'predecessor_id', :class_name => 'Todo', :touch => true
|
||||
belongs_to :successor, :foreign_key => 'successor_id', :class_name => 'Todo', :touch => true
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,6 @@ class Todo < ActiveRecord::Base
|
|||
validates_presence_of :show_from, :if => :deferred?
|
||||
validates_presence_of :context
|
||||
validate :check_show_from_in_future
|
||||
validate :check_circular_dependencies
|
||||
|
||||
def check_show_from_in_future
|
||||
if show_from_changed? # only check on change of show_from
|
||||
|
|
@ -125,14 +124,6 @@ class Todo < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def check_circular_dependencies
|
||||
unless @predecessor_array.nil? # Only validate predecessors if they changed
|
||||
@predecessor_array.each do |todo|
|
||||
errors.add("Depends on:", "Adding '#{todo.specification}' would create a circular dependency") if is_successor?(todo)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(*args)
|
||||
super(*args)
|
||||
@predecessor_array = nil # Used for deferred save of predecessors
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue