DISCLAIMER: Everything here assumes we have a normalized model. Please assume this as a condition for your analysis. Please do not suggest to de-normilize, since this is not part of the question.
I have the following query:
SELECT META(t).id AS taskKey, t.title, t.description, t.type assig AS assignee, u AS createdBy, ARRAY_AGG(DISTINCT c) AS comments, ARRAY_AGG(DISTINCT attch) AS attachments FROM testBucket t LEFT JOIN testBucket c ON KEY c.parentKey FOR t LEFT JOIN testBucket attch ON KEY attch.parentKey FOR t LEFT JOIN testBucket assig ON KEYS t.assigneeUserKey LEFT JOIN testBucket u ON KEYS t.createdBy WHERE t.documentType = 'Task' AND c.documentType = 'Comment' AND attch.documentType = 'Attachment' AND assig.documentType = 'User' AND u.documentType = 'User' AND t.assigneeUserKey = 'XXXXXX' GROUP BY META(t).id
The model corresponds to normalized documents for tasks. Each task keeps tracking about who created it and could be assigned to a user. And finally, each task has 0 or more comments and 0 or more attachments. Each document has a documentType field.
The query does work for tasks containing both comments and attachments. But it doesn’t if one of them is missing. It’s somehow clear that the left side on a “ON KEY” join is the child entity (comments and attachments in this case), so it would be expected for this query to bring only matches with records on the left side of the join. The unsupported RIGHT JOIN would do the trick in this case. Is there any option that could work for this model?