|
|
|
@ -177,6 +177,14 @@ class Relation < ActiveRecord::Base |
|
|
|
|
changed.include?('relation_type') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def relation_type_was |
|
|
|
|
if changes['relation_type'] |
|
|
|
|
changes['relation_type'].first |
|
|
|
|
else |
|
|
|
|
relation_type |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def relation_type |
|
|
|
|
if @relation_type.present? |
|
|
|
|
@relation_type |
|
|
|
@ -247,6 +255,8 @@ class Relation < ActiveRecord::Base |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
|
|
def shared_hierarchy? |
|
|
|
|
to_from = hierarchy_but_not_self(to: to, from: from) |
|
|
|
|
from_to = hierarchy_but_not_self(to: from, from: to) |
|
|
|
@ -256,8 +266,6 @@ class Relation < ActiveRecord::Base |
|
|
|
|
.any? |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
|
|
def validate_sanity_of_relation |
|
|
|
|
return unless from && to |
|
|
|
|
|
|
|
|
@ -268,11 +276,15 @@ class Relation < ActiveRecord::Base |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def set_type_column |
|
|
|
|
return unless relation_type |
|
|
|
|
if relation_type_changed? && relation_type_was |
|
|
|
|
was_column = self.class.relation_column(relation_type_was) |
|
|
|
|
send("#{was_column}=", 0) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
column = self.class.relation_column(relation_type) |
|
|
|
|
return unless relation_type |
|
|
|
|
new_column = self.class.relation_column(relation_type) |
|
|
|
|
|
|
|
|
|
send("#{column}=", 1) |
|
|
|
|
send("#{new_column}=", 1) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# Reverses the relation if needed so that it gets stored in the proper way |
|
|
|
|