[v5] Missing relationship intellisense inside model methods #1872
-
What is the proper way to fetch all records for a given relationship from inside the model? Even though it actually works as expected, the following code: public async getRoles () {
return await this.related('roles').query()
} Will show the following intellisense error on
It's a bug or I'm missing something? 🤔 UPDATE: Here's what expected when I hit ctrl + space: |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
I don't know in which file you are (the model or a controller), but I think you can't simply use "this" as the wanted keyword User. |
Beta Was this translation helpful? Give feedback.
-
@thetutlage Any thoughts on that? I think the |
Beta Was this translation helpful? Give feedback.
-
Inside model:
roles relationship has to be preloaded. This is how I use it and unsure if it's right or wrong approach |
Beta Was this translation helpful? Give feedback.
-
I've found a simple and clever workaround for this issue on this comment. Basically, aliasing public async getRoles () {
const user: User = this
return await user.related('roles').query()
} |
Beta Was this translation helpful? Give feedback.
I've found a simple and clever workaround for this issue on this comment.
Basically, aliasing
this
does the trick.