• 内联和左联

    内联和左联

    如果你想使用INNER JOIN而不是LEFT JOIN,只需使用innerJoinAndSelect

    1. const user = await createQueryBuilder("user")
    2. .innerJoinAndSelect("user.photos", "photo", "photo.isRemoved = :isRemoved", { isRemoved: false })
    3. .where("user.name = :name", { name: "Timber" })
    4. .getOne();

    This will generate:

    1. SELECT user.*, photo.* FROM users user
    2. INNER JOIN photos photo ON photo.user = user.id AND photo.isRemoved = FALSE
    3. WHERE user.name = 'Timber'

    LEFT JOININNER JOIN之间的区别在于,如果没有任何 photos,INNER JOIN将不会返回 user。即使没有 photos,LEFT JOIN也会返回 user。要了解有关不同连接类型的更多信息,请参阅 SQL 文档.