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
Deeply Nested Children #12
Comments
Take a look at my fork: http://github.com/retoo/awesome_nested_set/tree/master I've done something similar: In this case I wanted the corresponding level of each subelement, but the same system could be used to 'walk' through the tree knowning the current path or recursivly iterate through it. etc. |
Sounds reasonable. Want to work up a patch with tests? |
I've written some tests for each_with_level and pushed them to my repo. FYI, I've rebased my first commit to your current master. Two things I'm still a bit unsure about.
I plan to add other helpers (like the each_with_path) when I get to it. Perhaps some further tests with sub-trees wouldn't hurt. |
Just in case somebody is needing this in-memory building of the tree: Here's the code (also on http://gist.github.com/322213 )
This can be called like: In your view, just call the partial on child_nodes like this: |
Here an helper who is the equivalent of #nested_set_options helper but with only one DB query (http://gist.github.com/551311). With the help of #each_with_level method and my helper, I think you can close this issue. |
Could someone introduce a pull request which improves performance related to this in the core library? (Is it still an issue?) |
@retoo 's solution worked for me. But I think this thing is a must-be as a built-in function. |
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. |
There is a
descendants
method, however this fetches all descendants into a flat collection. Often times one wants a nested collection of descendants where they can iterate through children and sub-children at each level.It would be great if there was a method called
nested_children
or something which would call descendants but then remap the nesting in memory. So callingnested_children
on a child would not trigger an SQL call but return the sub-children mapped in memory. One could use recursion to display this. For example:I believe this would also help improve performance on the select helper method since isn't this currently performing a separate SQL query each time the children are fetched?
The text was updated successfully, but these errors were encountered: