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

hash_tree doesn't eager load children #155

Open
villesundberg opened this issue May 28, 2015 · 1 comment
Open

hash_tree doesn't eager load children #155

villesundberg opened this issue May 28, 2015 · 1 comment

Comments

@villesundberg
Copy link

The current implementation of hash_tree doesn't connect the returned objects together.

1 node = Node.find_by_id(1)
2 tree = node.hash_tree
3 tree.keys.first.children

Line 3 above will hit the database again, even though the children of node 1 have already been retrieved. It would be reasonable to expect line 2 to construct the tree so that calls to children or parent don't hit the database.

Is this by design, or would this be a desirable improvement?

@villesundberg villesundberg changed the title Hash tree doesn't eager load children hash_tree doesn't eager load children May 28, 2015
@villesundberg villesundberg changed the title hash_tree doesn't eager load children hash_tree doesn't eager load children May 28, 2015
@transoceanic2000
Copy link

An alternative (which would be useful) would be to have a hash_tree-like method that just returned the primary key IDs of the records in the tree, not the full records. This could then be used to pluck the actual items out of a collection that has been hashed by ID (e.g. using .index_by(&:id) on the end of an AR relation).

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

3 participants