Skip to content

Error using hash_tree method #76

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

Closed
kurtronshausen opened this issue Aug 27, 2013 · 3 comments
Closed

Error using hash_tree method #76

kurtronshausen opened this issue Aug 27, 2013 · 3 comments

Comments

@kurtronshausen
Copy link

I'm receiving the following error then calling the tree_view method. I am using uuids for primary keys, but that might not be the problem here. It looks like it's dying because the result from hash_tree_scope isn't properly sorted by depth.

Adding

order by depth

to line 38 of /lib/closure_tree/hash_tree.rb kinda makes it "work", but I know that's not the correct fix. Wish I could fix it properly, but I'm still really new to ruby and rails.

Loading development environment (Rails 4.0.0)
irb(main):001:0> Organization.tree_view
NoMethodError: undefined method `tree_view' for #<Class:0x007ff1c087cd50>
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
        from (irb):1
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'
irb(main):002:0> Organization.hash_tree
  Organization Load (8.0ms)  SELECT "organizations".* FROM "organizations" INNER JOIN (
 SELECT descendant_id, MAX(generations) as depth
 FROM "organization_hierarchies"
 GROUP BY descendant_id

 ) AS generation_depth
 ON "organizations".id = generation_depth.descendant_id
NoMethodError: undefined method `[]=' for nil:NilClass
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/closure_tree-4.2.7/lib/closure_tree/hash_tree.rb:52:in `block in build_hash_tree'
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:13:in `each'
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/relation/delegation.rb:13:in `each'
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/closure_tree-4.2.7/lib/closure_tree/hash_tree.rb:47:in `build_hash_tree'
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/closure_tree-4.2.7/lib/closure_tree/hash_tree.rb:23:in `hash_tree'
        from (irb):2
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
        from /home/vagrant/rubies/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

@tulak
Copy link
Contributor

tulak commented Aug 28, 2013

I was having this issue too. A pull request #71 that fixes this have been merged into the master but It wasn't released yet as a new version on rubygems.

@kurtronshausen
Copy link
Author

Works, thanks!

@jetamartin
Copy link

I have exactly the same issue. Maybe this problem wasn't completely fixed??

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

No branches or pull requests

3 participants