Open Merkur39 opened 3 years ago
.include
is used to query for the other documents, to fetch their contents. Here you do not need to query the groups, since you are not filtering on any of their attributes. I think what you want is:
const queryDefinition = Q(CONTACTS_DOCTYPE).where({
'relationships.groups.data': { $elemMatch: { _id: groupId } }
})
const { data: contacts } = await client.query(queryDefinition)
BY the way, the second part of the code, building the contactEntityList could be simplified with the use of filter
. Here, a new array is built at each iteration, which is inefficient.
Since we provide a few static helpers to manipulate relationships, we're hiding our internal structure. By internal structure, I mean relationships.group.data
for instance.
I think it can be easier to provide something like :
Q(CONTACTS_DOCTYPE).whereRelationships({ relName : { $elemMatch: { _id: groupId } )
or something similar, that hides this relationships.relName.data
Yes I agree that we should provide a utility since we hide the data.
I think it's the relationship class that should provide the utility, as this is it that knows the internal structure.
Q(CONTACTS_DOCTYPE).where(HasMany.queryForItem({ _id: groupId }))
Hi! It would be good to be able to retrieve data that only has this or that ID from the same relationship
In these examples I imagine a solution which modifies the parameter of the
.include()
method ofQueryDefinition
And to go to the end of this idea, I propose an example of theIncluded
variableI don't believe it's currently possible to recover my data with this kind of filter, and I don't know if that would be the best way to implement it, but the idea is there :)
Today I do it in 2 steps