Query on Join Fields #9683
Replies: 4 comments 6 replies
-
The join field doesn't support querying yet. We should mention this in the docs until this can be added. For now you will need to first query the related collection and use the relationship IDs from the first query like this:
I want to be able to support this in one request in the future. |
Beta Was this translation helpful? Give feedback.
-
Plus one for this feature! Got also this case for access control. Suppose we got students assigned to classrooms. Now we need to do a big fetch of every student before even querying the rooms.. |
Beta Was this translation helpful? Give feedback.
-
This seems to be quite a limiting issue for the join field. For example, the following use case should be a common one, but the (to me) obvious approach does not work. Situation Problem export const groupMember: Access<Group> = async ({ req: { user } }) => {
if (!user) return false
return { 'members.user': { equals: user.id } }
} Where Horrible workaround export const groupMember: Access<Group> = async ({ req: { user, payload } }) => {
if (!user) return false
const groupIds = await payload.find({
collection: 'group-members',
select: { group: true },
where: { user: { equals: user.id } },
limit: 100,
depth: 0,
})
return { id: { in: groupIds.docs.map(({ group }) => group) } }
} Result could (should! for the reader thinking about using this...) be set to context of course to make it less painful, but it's not what I'd like to see. @DanRibbens is it correct that this is indeed not supported, and am I correct that it cannot be avoided when using a join field here? |
Beta Was this translation helpful? Give feedback.
-
Hi, is there any way to query a collection by filtering on the join field?
For example, I have a bi-directional relationship for category and posts
How do I query for categories that the "relatedPosts" is not empty?
I tried something like
but this is giving error
Error: syntax error at or near "not"
. None of other filters like equals, in etc works.If I try with filters like "relatedPosts.doc", it is giving the error
Error: The following path cannot be queried: relatedPosts.docs
Beta Was this translation helpful? Give feedback.
All reactions