closure_tree
closure_tree copied to clipboard
root is nil until record is persisted
I'm currently migrating from awesome_nested_set to this beautiful gem and I noticed that #root for an entry returns nil until the record got saved even if a parent is set.
My current workaround (but I don't know if it breaks anything):
has_closure_tree # MUST BE AFTER attr_accessible/self.table_name=
# fix root being nil until persisted
def root
super || (parent && parent.root)
end
Sorry for the response delay--I agree that your assumption of how .root() should work, and would welcome a pull request. Please include a test against saved and unsaved model instances.
FWIW I think this would warrant a major version increment, and I'm completely fine with that.