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

feat: add relations option to tree queries #7981

Merged
merged 7 commits into from
Aug 4, 2021
Merged

feat: add relations option to tree queries #7981

merged 7 commits into from
Aug 4, 2021

Conversation

TheProgrammer21
Copy link
Contributor

@TheProgrammer21 TheProgrammer21 commented Jul 29, 2021

Add possibility to load relations of tree entities

Description of change

The change adds an optional options parameter to the findTrees() function.
The only option that can currently be set is relations which is an array of all relations that should be loaded for the entities. It works the same way as the relations array for the find() method.

Example:

await connection.getTreeRepository(Category).findTrees({ relations: ["sites"] });

Results in:

[
  Category {
    pk: 1,
    title: 'Category 1',
    sites: [ [Site], [Site] ],
    childCategories: [ [Category] ]
  },
  Category {
    pk: 2,
    title: 'Category 2',
    sites: [],
    childCategories: []
  }
]

Because findTrees() is depending on the findDescendantsTree() and findRoots() functions those two also implement this new optional options parameter.

Currently it is not possible to load relations for tree entities in a single query. This is a much requested and needed feature, it would be great if it could be merged very soon!

I created test cases to ensure the functionality.

Closes: #7974 #4564

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

Could you please tell me when you are planning to merge this pull request? Thank you!

TheProgrammer21 and others added 2 commits July 30, 2021 00:34
Add possibility to load relations of tree entities

Closes: #7974 #4564
remove unused declaration to satisfy linting.
@TheProgrammer21 TheProgrammer21 changed the title feat: add relation option to tree queries feat: add relations option to tree queries Jul 31, 2021
docs/tree-entities.md Outdated Show resolved Hide resolved
Copy link
Contributor Author

@TheProgrammer21 TheProgrammer21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to update the files manually because deactivating prettifier didn't change anything automatically. Could you please add the information to the development/contribution guide?

Everything should be updated as requested now!

@TheProgrammer21
Copy link
Contributor Author

@pleerock / @imnotjames Can this functionality be merged now?

@pleerock pleerock merged commit ca26297 into typeorm:master Aug 4, 2021
@pleerock
Copy link
Member

pleerock commented Aug 4, 2021

Thank you for contribution! 🎉

@isabela-morais
Copy link

@pleerock / @imnotjames Do you have any prediction of when this will be released?

@spiotr12
Copy link

could the same options be added to findDescendants, findAncestors and findAncestorsTree?

@TheProgrammer21
Copy link
Contributor Author

could the same options be added to findDescendants, findAncestors and findAncestorsTree?

findDescendantsTree also has this property since this pull request - the other 2 not. You can create an issue for those 2.

@spiotr12
Copy link

could the same options be added to findDescendants, findAncestors and findAncestorsTree?

findDescendantsTree also has this property since this pull request - the other 2 not. You can create an issue for those 2.

Created: #8076

@TheProgrammer21 TheProgrammer21 deleted the new-feature branch August 13, 2021 18:58
@ab958
Copy link

ab958 commented Sep 19, 2023

there is no where and select available in .findTrees

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 this pull request may close these issues.

feat: Adding relations option to findTrees()
6 participants