Dynamic nested preload #4008
Answered
by
arnauddoub
arnauddoub
asked this question in
Help
-
Hello I need to dynamically load nested relationships by passing an object of this format const inputObject = {
user: {
profil: true
},
} The code it should execute Post.query().preload('user', (query) => query.preload('profil')) But I don't know if it is possible to create a function that transforms this |
Beta Was this translation helpful? Give feedback.
Answered by
arnauddoub
Dec 12, 2022
Replies: 1 comment
-
I figured out how to do what I wanted private loadDefaultRelations(query: any, relations: any) {
for (const relation in relations) {
if (Object.values(relations[relation])[0]) {
query.preload(relation, (newQuery: any) => this.loadDefaultRelations(newQuery, relations[relation]))
} else {
query.preload(relation)
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
arnauddoub
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I figured out how to do what I wanted