Fix implication antecedents with aliases

This commit is contained in:
Toks
2013-12-28 18:56:34 -05:00
parent f628a4c0ff
commit 9caa41d30a
2 changed files with 28 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ class TagImplication < ActiveRecord::Base
validates_presence_of :creator_id, :antecedent_name, :consequent_name
validates_uniqueness_of :antecedent_name, :scope => :consequent_name
validate :absence_of_circular_relation
validate :antecedent_is_not_aliased
validate :consequent_is_not_aliased
module DescendantMethods
@@ -126,6 +127,14 @@ class TagImplication < ActiveRecord::Base
end
end
def antecedent_is_not_aliased
# We don't want to implicate a -> b if a is already aliased to c
if TagAlias.exists?(["antecedent_name = ?", antecedent_name])
self.errors[:base] << "Antecedent tag must not be aliased to another tag"
false
end
end
def consequent_is_not_aliased
# We don't want to implicate a -> b if b is already aliased to c
if TagAlias.exists?(["antecedent_name = ?", consequent_name])