diff --git a/lib/ancestry/instance_methods.rb b/lib/ancestry/instance_methods.rb index f7244bc2..231276eb 100644 --- a/lib/ancestry/instance_methods.rb +++ b/lib/ancestry/instance_methods.rb @@ -296,7 +296,8 @@ def unscoped_descendants # Validates the ancestry, but can also be applied if validation is bypassed to determine if children should be affected def sane_ancestry? - ancestry.nil? || (ancestry.to_s =~ Ancestry::ANCESTRY_PATTERN && !ancestor_ids.include?(self.id)) + ancestry_value = read_attribute(self.ancestry_base_class.ancestry_column) + ancestry_value.nil? || (ancestry_value.to_s =~ Ancestry::ANCESTRY_PATTERN && !ancestor_ids.include?(self.id)) end def unscoped_find id diff --git a/test/concerns/has_ancestry_test.rb b/test/concerns/has_ancestry_test.rb index 7593e4a9..4e7c8a51 100644 --- a/test/concerns/has_ancestry_test.rb +++ b/test/concerns/has_ancestry_test.rb @@ -57,6 +57,18 @@ def test_descendants_move_with_node end end + def test_set_parent_with_non_default_ancestry_column + AncestryTestDatabase.with_model :depth => 3, :width => 3, :ancestry_column => :alternative_ancestry do |model, roots| + root1, root2, root3 = roots.map(&:first) + assert_no_difference 'root1.descendants.size' do + assert_difference 'root2.descendants.size', root1.subtree.size do + root1.parent = root2 + root1.save! + end + end + end + end + def test_setup_test_nodes AncestryTestDatabase.with_model :depth => 3, :width => 3 do |model, roots| assert_equal Array, roots.class