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

Chaperone Tree Relations #259

Closed
tylernathanreed opened this issue Sep 5, 2024 · 0 comments · Fixed by #264
Closed

Chaperone Tree Relations #259

tylernathanreed opened this issue Sep 5, 2024 · 0 comments · Fixed by #264

Comments

@tylernathanreed
Copy link
Contributor

tylernathanreed commented Sep 5, 2024

I was recently working on something where I pulled in a tree, and I needed to access information regarding ancestors of the tree. Tapping into these relations caused database queries, despite the models being within the collection already. This resulted in loading 5x the number of models as I had records in the table.

The solution for something like this would be to manually load in the parent/ancestor relations, so that if these relations are called, they load models already in memory, rather than reaching out to the database again.

See #260 for the solution I used to fix this.

In my personal project, I implemented this as a macro. However, I'd like to see this implemented into the package itself.

tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 5, 2024
tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 5, 2024
tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 5, 2024
tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 6, 2024
tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 6, 2024
tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 6, 2024
tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 6, 2024
tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 6, 2024
tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 6, 2024
tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 6, 2024
tylernathanreed added a commit to tylernathanreed/laravel-adjacency-list that referenced this issue Sep 6, 2024
staudenmeir added a commit that referenced this issue Oct 6, 2024
* #259: Added method to load in relations.

* #259: Fixed typo

* #259: Added missing include

* #259: Added attributes to be used with test

* #259: Updated to match schema

* #259: Added initial test

* #259: Updated attribute names

* #259: Updated to use display path

* #259: Added missing include

* #259: Sort results to ensure consistency across database platforms

* #259: More sorting to ensure consistency across database platforms

* Update src/Eloquent/Collection.php

Co-authored-by: Sander Muller <[email protected]>

* Update src/Eloquent/Collection.php

Co-authored-by: Sander Muller <[email protected]>

* Update tests/Tree/Models/User.php

Co-authored-by: Sander Muller <[email protected]>

* Update tests/Tree/Models/User.php

Co-authored-by: Sander Muller <[email protected]>

* Update src/Eloquent/Collection.php

Co-authored-by: Sander Muller <[email protected]>

* Update tests/Tree/CollectionTest.php

Co-authored-by: Sander Muller <[email protected]>

* Fix loading of missing models

* Refactoring

* Refactoring

---------

Co-authored-by: Jonas Staudenmeir <[email protected]>
Co-authored-by: Sander Muller <[email protected]>
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

Successfully merging a pull request may close this issue.

1 participant