typeorm inner join 和 where 问题 - BaseEntity 模型
typeorm inner join and where problem - BaseEntity model
我使用 typeorm (^0.2.41) 并定义了两个从我的自定义 BaseModel 扩展的模型:
基础模型:
import { BaseEntity } from 'typeorm';
export class BaseModel extends BaseEntity {
}
类别:
@Entity('Category', { schema: 'public' })
export class Category extends BaseModel {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
id: number;
@OneToMany(() => AbilityCategory, (abilityCategory) => abilityCategory.category, { onDelete: 'CASCADE' })
abilityCategories: AbilityCategory[];
}
能力类别:
@Entity('_ability_category', { schema: 'public' })
export class AbilityCategory extends BaseModel {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
id: number;
@ManyToOne(() => Category, (category) => category.abilityCategories)
@JoinColumn([{ name: 'categoryId', referencedColumnName: 'id' }])
category: Category;
}
(我删除了不必要的字段,在此之前提及)
我写了这个查询:
await Category.find({
where: {
type: 'JobCategory',
'abilityCategories.id': 13
},
join: {
alias: 'category',
innerJoinAndSelect: { abilityCategories: 'category.abilityCategories' }
},
take: 5
}
);
但在原始 sql 查询中,它将 null 传递给 abilityCategories.id:
SELECT DISTINCT "distinctAlias"."category_id" as "ids_category_id"
FROM (SELECT "category"."id" AS "category_id"
FROM "public"."Category" "category"
INNER JOIN "public"."_ability_category" "abilityCategories"
ON "abilityCategories"."categoryId" = "category"."id"
WHERE ("category"."type" = AND "abilityCategories"."id" = )) "distinctAlias"
ORDER BY "category_id" ASC
LIMIT 5 -- PARAMETERS: ["JobCategory",null]
有没有人帮我看看第二个参数为空值的原因?
它与 GitHub
上的这个问题有关
我使用 typeorm (^0.2.41) 并定义了两个从我的自定义 BaseModel 扩展的模型:
基础模型:
import { BaseEntity } from 'typeorm';
export class BaseModel extends BaseEntity {
}
类别:
@Entity('Category', { schema: 'public' })
export class Category extends BaseModel {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
id: number;
@OneToMany(() => AbilityCategory, (abilityCategory) => abilityCategory.category, { onDelete: 'CASCADE' })
abilityCategories: AbilityCategory[];
}
能力类别:
@Entity('_ability_category', { schema: 'public' })
export class AbilityCategory extends BaseModel {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
id: number;
@ManyToOne(() => Category, (category) => category.abilityCategories)
@JoinColumn([{ name: 'categoryId', referencedColumnName: 'id' }])
category: Category;
}
(我删除了不必要的字段,在此之前提及)
我写了这个查询:
await Category.find({
where: {
type: 'JobCategory',
'abilityCategories.id': 13
},
join: {
alias: 'category',
innerJoinAndSelect: { abilityCategories: 'category.abilityCategories' }
},
take: 5
}
);
但在原始 sql 查询中,它将 null 传递给 abilityCategories.id:
SELECT DISTINCT "distinctAlias"."category_id" as "ids_category_id"
FROM (SELECT "category"."id" AS "category_id"
FROM "public"."Category" "category"
INNER JOIN "public"."_ability_category" "abilityCategories"
ON "abilityCategories"."categoryId" = "category"."id"
WHERE ("category"."type" = AND "abilityCategories"."id" = )) "distinctAlias"
ORDER BY "category_id" ASC
LIMIT 5 -- PARAMETERS: ["JobCategory",null]
有没有人帮我看看第二个参数为空值的原因?
它与 GitHub
上的这个问题有关