closure_tree icon indicating copy to clipboard operation
closure_tree copied to clipboard

root is nil until record is persisted

Open 2called-chaos opened this issue 8 years ago • 1 comments

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

2called-chaos avatar Feb 23 '17 15:02 2called-chaos

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.

mceachen avatar Apr 14 '17 17:04 mceachen