Replies: 1 comment
-
class User {
@hasMany(() => Post, {
foreignKey: 'user_id' ,
onQuery: (query) => {
if (!query.isRelatedSubQuery) {
query.preload('comments')
}
}
})
public posts: HasMany<typeof Post>
...
} using it like: user.preload('post') will load comments of a posts too. I have something like this set up, currently can't check the code but it should work. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Everyone,
I want to ask if this is a bug or if the behavior is just like this.
Assuming I have a user with a post and every post has comments.
I want to get the list of comments with the "creator" of the post.
My query is like this:
but when getting the result, the user under the post is undefined
Result
after disabling the "preloadRelation" in the "Comment" model then that's time I can get the user through the comments model
Re-run the query
Result
Conclusion
I assume the preload will not run twice on the same relationship
These are the models
User Model
Post Model
Comment Model
Beta Was this translation helpful? Give feedback.
All reactions