获取所有数据和仅过滤的关系

Getting all data and only filtered relations

我有 table 个与定价相关的产品 table,理想情况下,我希望获得所有产品的数组,以及那些与用户有定价关系的产品与产品关联。

 return this.repo
        .createQueryBuilder("product")
        .leftJoinAndSelect("product.pricings", "pricings")
        .leftJoinAndSelect("pricings.driver", "driver")
        .where("pricings.driver.id = :id", { id: 1 })
        .getMany()

这 returns 一系列具有上述关系的产品,我想要所有产品,甚至那些与定价没有关系的产品。

         SELECT  product.id, product.price,
            product.name, pricing.driverId, pricing.alteredPrice
            FROM    product   
            LEFT JOIN pricing 
                ON product.id = pricing.productId AND
                    pricing.driverId = '1'
            ORDER   BY product.id

这显然可以解决问题

对于 typeorm 等价于:

          this.repo
                .createQueryBuilder('product')
                .leftJoinAndSelect("product.pricings", "pricing", "pricing.driverId = :driverId", { driverId })
                .select('product.id')
                .addSelect('product.price')
                .addSelect('product.name')
                .addSelect('product.saleType')
                .addSelect('pricing.driverId')
                .addSelect('pricing.alteredPrice')
                .addSelect('pricing.id')
                .orderBy("product.id")
                .getMany()