'typeORM Postgres how to add to left join function an "and where" condition from another table column?
I'm coding a big query to retrieve information about orders. Now I'm trying to left join a table (It works fine) but to enhance the query I would like to add on-where condition to the left-join function. Is it possible?
let containerBuilder = getManager()
.createQueryBuilder(Container, 'container')
.leftJoinAndSelect('container.surrenderDetails', 'surrenderDetails')
.leftJoinAndSelect('surrenderDetails.shipper', 'shipper')
.leftJoinAndSelect('shipper.shipperRenditionAddress', 'shipperRenditionAddress')
.leftJoinAndSelect('shipperRenditionAddress.node', 'node')
.orderBy('containersHistory.id', 'DESC');
This queryBuilder works fine but I would like to add a where condition inside the leftJoinAndSelect function, I coded the same query in pgAdmin 4 to retrieve the specific information I want but I'm not sure if I can reply the same logic with typeOrm. Do you have any idea? Thanks!
SELECT "con"."id", "con"."containerType", "con"."trackingId", "con"."originNode",
"sra"."address", "sra"."zipCode", "sra"."province"
FROM "container" con
LEFT JOIN "surrender_details" sud
ON ("con"."id" = "sud"."Container")
LEFT JOIN "shipper_rendition_address" sra
ON ("sud"."shipper" = "sra"."shipperId" AND "con"."originNode" = "sra"."nodeId")
Basically I want to add this line "AND "con"."originNode" = "sra"."nodeId" to retrieve only the rows that matched with the container node. I try to code the next line but I recived a error code
.leftJoinAndSelect('shipperRenditionAddress.node', 'node', 'node = :nodeId, {'nodeId': 'container.node')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
