Hi Couchbase Gurus,
How do I re-use my JOIN Clause on properties that came from the same document types.
I have field assignedTo
and createdBy
these fields come from the same document type which is user
.
Is there a way I could re-use the JOIN Clause for the both fields?
currently what I did is I have 2 JOIN Clauses: for (assignedTo and createdBy)
LEFT JOIN `bucket` AS `users` ON META(`users`).id = `tasks-details`.createdBy AND `users`.`type` = 'user' AND `users`.tenant = 'tenant::bucket' LEFT JOIN `bucket` AS `users1` ON META(`users1`).id = `tasks-details`.assignedTo AND `users1`.`type` = 'user' AND `users1`.tenant = 'tenant::bucket'
Below is my full N1QL Query.
SELECT meta(`tasks-details`).id, `tasks-details`.task, `tasks-details`.name, `tasks-details`.status, {'id': META(`users1`).id,'firstName': `users1`.firstName,'lastName': `users1`.lastName} AS assignedTo, {'id': META(`users`).id,'firstName': `users`.firstName,'lastName': `users`.lastName} AS createdBy, {'id': META(locations).id,'name': locations.name} AS location FROM `bucket` AS `tasks-details` LEFT JOIN `bucket` AS `users` ON META(`users`).id = `tasks-details`.createdBy AND `users`.`type` = 'user' AND `users`.tenant = 'tenant::bucket' LEFT JOIN `bucket` AS `users1` ON META(`users1`).id = `tasks-details`.assignedTo AND `users1`.`type` = 'user' AND `users1`.tenant = 'tenant::bucket' LEFT JOIN `bucket` AS locations ON META(locations).id IN `tasks-details`.location AND locations.`type` = 'location' AND locations.tenant = 'tenant::bucket' WHERE `tasks-details`.`type` = 'task-detail' AND `tasks-details`.tenant = 'tenant::bucket' AND `tasks-details`.createdBy = 'bucket::user::53fe5737-9b8c-4c8b-b9d7-87521055b995' ORDER BY DECODE( LOWER(`tasks-details`.dueDate),"",NULL,LOWER(`tasks-details`.dueDate) ) DESC NULLS LAST
Need Help thanks.