Closed
Description
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>'
Metadata
Metadata
Assignees
Labels
No labels