Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

root is nil until record is persisted #254

Open
2called-chaos opened this issue Feb 23, 2017 · 1 comment
Open

root is nil until record is persisted #254

2called-chaos opened this issue Feb 23, 2017 · 1 comment

Comments

@2called-chaos
Copy link

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
@mceachen
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants