GithubHelp home page GithubHelp logo

Set depth at rebuild! about awesome_nested_set HOT 7 OPEN

diesl avatar diesl commented on June 15, 2024 2
Set depth at rebuild!

from awesome_nested_set.

Comments (7)

parndt avatar parndt commented on June 15, 2024

Thanks @diesl - can you please debug this a little on your local?
If you use bundle open awesome_nested_set to open the gem in your editor, and put debugging statements (like require 'pry';binding.pry or puts) inside the method compute_level then we can maybe see what the code is thinking about your table.

The relevant method is here

def compute_level
node, nesting = determine_depth
node == self ? ancestors.count : node.level + nesting
end

from awesome_nested_set.

stale avatar stale commented on June 15, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from awesome_nested_set.

diesl avatar diesl commented on June 15, 2024

Not stale, I still need to debug

from awesome_nested_set.

mentalic avatar mentalic commented on June 15, 2024

This is still valid. We ended up doing Category.all.each do |c| c.save;end;0 after rebuild in order to recall the depth.

from awesome_nested_set.

diesl avatar diesl commented on June 15, 2024

@parndt Finally I had some time for debugging.

I added a puts statement at the beginning of def compute_level. I did not get any output during Model.rebuild! and after checking the gem code, indeed I do not see any code triggering the computation of the depth during the rebuild:

def rebuild!
# Don't rebuild a valid tree.
return true if model.valid?
root_nodes.each do |root_node|
# setup index for this scope
indices[scope_for_rebuild.call(root_node)] ||= 0
set_left_and_rights(root_node)
reset_counter_cache(root_node)
end
end

I would expect that depth is set during rebuild. Do I have some misconception here?


Seems like you already discovered this behavior many years ago:

Yes, I've been noticing this too.. It seems the depth only gets built when you run save or move_to commands.

Originally posted by @parndt in #116 (comment)

from awesome_nested_set.

parndt avatar parndt commented on June 15, 2024

@diesl thanks - I would expect if depth is being used that it gets set during rebuild! so I think that's how it should work (keen for this to be made to happen!)

from awesome_nested_set.

iainbeeston avatar iainbeeston commented on June 15, 2024

I just noticed this as well. I've also noticed that calling set_depth_for_self_and_descendants! on the root doesn't calculate the depth correctly either. At the moment my workaround is to call rebuild! followed by set_depth! on each node (which will only work for small numbers of nodes...)

from awesome_nested_set.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.