我在Find语句中设置了WHERE条件,但条件查询WHERE的结果不匹配。
查找查询:
async getRegister() {
const result = await this.registerModel.findOne({
where: {
session: 1,
user: 2,
},
select: ['id', 'created_time'],
});
return result;
}
注册实体:
@Entity('register')
export class Register {
@PrimaryGeneratedColumn()
id: number;
@Column({
type: 'text',
nullable: true,
unique: true,
})
no: string;
……
@ManyToOne(type => User, user => user.registers)
user: User;
@OneToOne(type => Session)
@JoinColumn()
session: Session;
}
格式化的SQL语句:
query: SELECT DISTINCT "distinctAlias"."Register_id" AS "ids_Register_id" FROM (SELECT "Register"."id" AS "Register_id", "Register"."created_time" AS "Register_created_time" FROM "register" "Register" INNER JOIN "session" "Register__Register_session" ON "Register__Register_session"."id"="Register"."sessionId" AND ("Register__Register_session"."deleted_time" IS NULL) INNER JOIN "user" "Register__Register_user" ON "Register__Register_user"."id"="Register"."userId" AND ("Register__Register_user"."deleted_time" IS NULL) WHERE "Register"."deleted_time" IS NULL) "distinctAlias" ORDER BY "Register_id" ASC LIMIT 1
query: SELECT "Register"."id" AS "Register_id", "Register"."created_time" AS "Register_created_time" FROM "register" "Register" INNER JOIN "session" "Register__Register_session" ON "Register__Register_session"."id"="Register"."sessionId" AND ("Register__Register_session"."deleted_time" IS NULL) INNER JOIN "user" "Register__Register_user" ON "Register__Register_user"."id"="Register"."userId" AND ("Register__Register_user"."deleted_time" IS NULL) WHERE ( "Register"."deleted_time" IS NULL ) AND ( "Register"."id" IN (7) )
我找不到参数集
where: {
session: 1,
user: 2,
},
2条答案
按热度按时间x0fgdtte1#
当我使用SQL时,我会得到正确的结果。
i7uq4tfw2#
我已经解决了这个问题。首先修改了注册实体
上次修改查找查询的时间: