Skip to content

Commit

Permalink
fix relations
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilfronczak committed Dec 8, 2022
1 parent 5607b2c commit da5b28d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mikroorm-nested-set",
"version": "1.1.1",
"version": "1.1.2",
"types": "src/index.d.ts",
"description": "Package for MikroORM nested set feature",
"main": "src/index.js",
Expand Down
5 changes: 3 additions & 2 deletions src/repository/nested-set-subject.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ export abstract class NestedSetSubjectRepository<T extends NestedSetSubjectAbstr

if(options.relations) {
for(const relation of options.relations) {
preparedQuery.leftJoinAndSelect(relation.relationName, relation.alias)
preparedQuery.joinAndSelect(relation.relationName, relation.alias)
}
}


const subjects = (await preparedQuery.execute()).map(subject => this.map(subject))
subjects.forEach(subject => subject.children = [])

for(const subject of subjects) {

const children = subjects.filter(innerSubject => innerSubject?.parent?.getIdentifier() === subject.getIdentifier())

if(children && children.length >=1) {
subject.children.add(...children)
subject.children.push(...children)
}
}

Expand Down

0 comments on commit da5b28d

Please sign in to comment.