- 内联和左联
内联和左联
如果你想使用INNER JOIN而不是LEFT JOIN,只需使用innerJoinAndSelect:
const user = await createQueryBuilder("user").innerJoinAndSelect("user.photos", "photo", "photo.isRemoved = :isRemoved", { isRemoved: false }).where("user.name = :name", { name: "Timber" }).getOne();
This will generate:
SELECT user.*, photo.* FROM users userINNER JOIN photos photo ON photo.user = user.id AND photo.isRemoved = FALSEWHERE user.name = 'Timber'
LEFT JOIN和INNER JOIN之间的区别在于,如果没有任何 photos,INNER JOIN将不会返回 user。即使没有 photos,LEFT JOIN也会返回 user。要了解有关不同连接类型的更多信息,请参阅 SQL 文档.
