- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
现在一直在搜索这个,不确定这在 SQL 世界中是否是非正统的东西,但我正在尝试做一个左连接,该连接不为空“deletedAt”列,但我似乎无法找到一种方法来做一个左连接,其中包括删除。
这只是一个虚拟示例,说明了我要做什么,在这种情况下,我想检索此人的信息以及工作的信息,但工作已被软删除。
this.createQueryBuilder('person')
.leftJoinAndSelect('person.job', 'job')
由此产生的 SQL 查询在
上隐式地添加了“IS NOT NULL”左加入 但我有这种情况,我需要来自确实已删除的记录的信息。
.withDeleted();
任何人有任何提示?
最佳答案
在我的测试中,TypeOrm 根据 .withDeleted()
是否生成不同的查询。是之前还是之后 .leftJoinAndSelect()
// Normal case: Exclude both soft-deleted 'Person' and 'Job':
this.createQueryBuilder("Person")
.leftJoinAndSelect('Person.job', 'Job');
// 'withDeleted() after the join: Include soft-deleted 'Person' BUT EXCLUDE soft-deleted 'Job':
this.createQueryBuilder("Person")
.leftJoinAndSelect('Person.job', 'Job')
.withDeleted();
// 'withDeleted() before the join: Include both soft-deleted 'Person' and 'Job':
this.createQueryBuilder("Person")
.withDeleted()
.leftJoinAndSelect('Person.job', 'Job');
因此,如果您想排除软删除的“人”但包括软删除的“工作”(我所期望的),则可以在加入之前使用 withDeleted(将包括所有内容)并添加您自己的条件然后排除软删除的“人”(即添加条件
"Person.deletedAt IS NULL"
)。这样你就不需要做一个完整的 RAW 查询:
// 'withDeleted() before the join with extra condition: Exclude soft-deleted 'Person' BUT INCLUDE soft-deleted 'Job':
this.createQueryBuilder("Person")
.withDeleted()
.andWhere("Person.deletedAt Is Null")
.leftJoinAndSelect('Person.job', 'Job');
(我用 TypeORM 0.2.30 和 0.2.31 进行了测试并看到了相同的行为)。
关于nestjs - TypeORM - 左加入没有 "deletedAt IS NULL",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66117005/
我知道 typeorm 可以创建整个 db 模式,甚至可以将数据库模式与实体定义同步(请参阅 synchronize 中的 Connection Options ) 但在生产中,我想要求 typeor
我有一个 Role Entity 和一个 Route Entity,它们是树形结构,它们是 ManyToMany 关系。 现在我想通过 RoleRepository.find({relations:
我已经设置了 logging: true当createConnection()来自 TypeORM ,在大多数情况下都可以正常工作。 但是有一种情况,我的数据字段之一来自特定的 query/mutat
在 Rails 上,每个测试用例都会创建一个 ActiveRecord 事务,它允许测试所有内容,然后将数据库恢复到原始状态,而不必删除所有表或任何可能影响播种机等的内容。 可以在 Typeorm 上
Note 与 Subject 具有多对多关系 查询它的最佳方式是什么?我喜欢编写以下内容来获取给定注释上的所有主题: const subjectRepo = connection.getRepos
我使用 UUID 作为我的实体的主键,它工作得很好。但我想删除那些破折号。 现在 ID 被保存为 8e5365f4-3d42-4274-bafc-93b97bd6e3f2 36 个字符 我想要的是 8
我一整天都在尝试将实体保存到 MySQL 数据库中,遇到了巨大的困难。我正在使用 NestJS 和 TypeORM。 teacher.entity.ts import { BeforeInsert,
我也想在前端使用我用 TypeORM 创建的实体。有没有一种干净的方法可以做到这一点?或者我应该继续这样做。 此时,我的文件结构如下所示(前端的 Angular 8): /server /enti
我想得到一个 basic setup使用 TypeORM 工作,并在设置后收到此错误。 这是一个 REPL(只需执行 yarn install && yarn db:dev 后跟 yarn db:mi
我正在尝试通过 Nest/TypeORM 构建 SAAS 产品,我需要按子域配置/更改数据库连接。 customer1.domain.com => connect to customer1 datab
如何将 TypeORM 与 Better-sqlite3 一起使用? 上官方documentation ,有一个section形式更好-sqlite3。 我已经通过 typeorm@latest 安装
操作系统:macOS Sierra v 10.12.6 我正在尝试使用 typeorm 在 Typescript 中构建一个应用程序,这是我第一次使用其中任何一个。 我使用了以下两种方法来安装 typ
有没有一种简单的方法可以使用 DataSource 在 typeORM v.0.3.6 中播种数据? typeorm-seeding 似乎使用已弃用的 Connection。 最佳答案 找到这个包裹
我正在做一门类(class),我们使用 express-node postgres 和 react(使用 typescript)和 typeORM。到目前为止一切都运行良好,但我面临 typeORM
尽管进行了大量研究和反复试验,但不幸的是,我还没有针对以下用例的完美解决方案:一个用户有多个帖子,这被正确地实现为一对多关系。我想为用户加载他的所有帖子,但不是帖子的所有属性,只有某些属性。 方法 1
我用 NestJS 和 ORM TypeORM 做一个 API 我有实体: 用户 关系类型 UserRelationshipType(带有用户和关系类型 ForeignKey) 和关系(与 userR
我有两个实体 Tag 和 Photo: // tag.entity.ts import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm
我有以下要保存的实体: @Entity('approvals') export class Approval { @PrimaryGeneratedColumn() id: string;
我有命令: .leftJoinAndSelect("permission.user", "user") .where("permissi
我是使用 typeorm 的新手,这是我第二次与 typeorm 混淆,我有以下查询: SELECT t1.a,t1.b,t2.a (SELECT TOP 1 t1.a FROM table1
我是一名优秀的程序员,十分优秀!