TypeOrm – OneToOne连接更新尝试删除相关logging
我有一个使用TypeORM的项目,我有以下两个实体
@Entity("Email") export class EmailEntity extends BaseEntity implements IEmail { @Column({length: 100}) to: string; @Column({length: 100}) from: string; @Column({length: 255}) subject: string; @Column({nullable: true}) html: string; @Column({nullable: true}) text: string; }
和
@Entity("QueuedEmail") export class QueuedEmailEntity extends BaseEntity implements IQueuedEmail { @OneToOne(email => EmailEntity, {nullable: false, cascadeAll: true}) @JoinColumn() email: EmailEntity; @Column() retryCount: number; @Column() status: QueuedEmailStatus; constructor() { super(); this.retryCount = 0; this.status = QueuedEmailStatus.QueuedForDispatch; } }
BaseEntity
是一个具有@PrimaryGeneratedColumn
的id
列的抽象类
我有以下代码更新QueuedEmail
上的QueuedEmail
const queuedEmailEntityArray: QueuedEmailEntity[] = await this.queuedEmailRepository.createQueryBuilder("queuedEmail") .where("queuedEmail.status = :queuedEmailStatus", {queuedEmailStatus: QueuedEmailStatus.QueuedForDispatch}) .innerJoinAndSelect("queuedEmail.email", "email") .orderBy("queuedEmail.id", "DESC") .getMany(); queuedEmailEntityArray.forEach(async (value, index) => { let queuedEmailEntity: QueuedEmailEntity = queuedEmailEntityArray.pop(); queuedEmailEntity.status = QueuedEmailStatus.AttemptingToDispatch; await this.queuedEmailRepository.persist(queuedEmailEntity); });
现在,select正确加载数组或QueuedEmailEntity
对象, foreach
运行但引发以下exception
query failed: DELETE FROM "Email" WHERE "id"=$1 -- PARAMETERS: [1] error during executing query:error: update or delete on table "Email" violates foreign key constraint "fk_d438362cf2adecbcc5b17f45606" on table "QueuedEmail"
debugging查询输出显示TypeORM正在更新status
字段,但也更新emailId' and then attempting to delete the
EmailEntitylogging
UPDATE "QueuedEmail" SET "status"=$1, "emailId"=$2 WHERE "id"=$3 -- PARAMETERS: [1,1,1] DELETE FROM "Email" WHERE "id"=$1 -- PARAMETERS: [1]
我不明白为什么TypeORM需要在没有更改引用时更新emailId
字段,更不用说为什么它会尝试删除仍然引用的logging。 任何人都可以看到上面的代码有什么问题吗?
- Node.js SyntaxError:ANTLR4 JavaScript Lexer中的意外标识符“boolean”
- 是否有必要在Node.js中设置一个Content-Type?
- Javascript node.js ORM,遵循数据映射器模式
- 如何使用node.js amqp模块将AQMP消息缓冲区转换为JSON对象?
- 将string转换为数字node.js
- 为request.post设置内容types的标题为json
- 在全新的快递项目doctype 5`上出现错误,您现在必须使用`doctype html`
- 500错误:对于使用ResourceJS的Mongoose模型,对于path\“_ id \”中的值转换为ObjectId失败
- JS – 如何将所有键转换为其值(从对象)