Permalink
Browse files

changed parent assignment

  • Loading branch information...
1 parent cac3261 commit ff2cca415a07457adb82484aa987f109f879d1fc @sled committed Jul 7, 2011
Showing with 4 additions and 3 deletions.
  1. +4 −3 lib/mongoid_acts_as_tree.rb
View
7 lib/mongoid_acts_as_tree.rb
@@ -51,19 +51,20 @@ def acts_as_tree(options = {})
end
# overwrite parent=
- def parent_with_checking=(new_parent)
+ def parent_with_checking=(new_parent)
if new_parent.present?
if new_parent != self.parent && new_parent.is_a?(Mongoid::Acts::Tree)
+ # chain to original relation
+ parent_without_checking=(new_parent)
self.write_attribute parent_id_field, new_parent.id
new_parent.children.push self, false
end
else
+ parent_without_checking=(nil)
self.write_attribute parent_id_field, nil
self.path = []
self.depth = 0
end
- # chain to original relation
- parent_without_checking=(new_parent)
end
# use advise-around pattern to intercept mongoid relation

0 comments on commit ff2cca4

Please sign in to comment.