Some query methods are not callable when using the onQuery hook in Lucid relationships #1482
-
Hi,' @manyToMany(() => User, {
pivotTable: "forum_user",
onQuery: (query) => query.apply((scopes) => scopes.byRoles(["moderator"])),
})
public moderators: ManyToMany<typeof User>; I am working on a forum with users who have different roles. I have a Would love your insights as regards this change and possible alternatives for my use case. Thanks again |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey @Obapelumi. Yes this happened because now the subqueries used by @manyToMany(() => User, {
pivotTable: "forum_user",
onQuery: (query) => {
if (!query.isRelatedQuery) { return }
query.apply((scopes) => scopes.byRoles(["moderator"]))
},
})
public moderators: ManyToMany<typeof User>; I have plans to provide separate hooks for sub-queries and related queries |
Beta Was this translation helpful? Give feedback.
-
I think this can be fixed. The issue is coming from here microsoft/TypeScript#571, but can be handled easily. Will work on the fix on the weekend |
Beta Was this translation helpful? Give feedback.
Hey @Obapelumi. Yes this happened because now the subqueries used by
withCount
,whereHas
andhas
methods also invokes this method. You need to wrap your code inside a conditional and it should work fine.I have plans to provide separate hooks for sub-queries and related queries