fix/multiple.includes.nestedResources #373
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pull Request introduces several changes to address a key issue and improve the functionality and testing of the application:
Problem Solved: The application was previously unable to handle queries for a resource with multiple nested resources simultaneously. If multiple nested resources were included in the query, only the last one was returned. This issue has been resolved with the changes in this PR.
Enhancement in
knex-processor.ts
: TheparseOperationIncludedRelationships
function has been updated to ensure that theacumRelationships
object correctly accumulates relationships without overwriting existing ones. This is achieved by spreading the existing relationships before adding a new one. This change is part of the solution to the problem described above.Refactoring in
serializer.ts
: The serialization process has been simplified. Previously, the code was creating a new array with uniquetype_id
combinations fromincludedData
and then mapping over this array to find the corresponding items inincludedData
. This has been replaced with a direct return ofincludedData
, which simplifies the code and may improve performance.Addition of a new test in
nestedResources.test.ts
: A new test has been added to verify the correct retrieval of the first article's author's votes and comments. This test will help ensure that the application's data retrieval and serialization processes are working as expected, and that multiple nested resources can be retrieved simultaneously.