我有一个实体:
@Entity()
export class Training {
@PrimaryGeneratedColumn()
id: number;
@Column('jsonb')
workoutExercises: Exercise[];
}
运动实体:
@Entity()
export class Exercise {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
}
数据示例:
[
{
"workoutName": "Monday",
"workoutExercises": [
{
"id": 1,
"sets": 4,
"weight": 100,
"repetitions": 10
}
],
},
{
"workoutName": "Sunday",
"workoutExercises": [
{
"id": 2,
"sets": 4,
"weight": 100,
"repetitions": 10
}
],
}
]
我想找到id为运动id为1的实体。
abdul Samad回答后,我试了这个:
this.createQueryBuilder('training')
.where(`:exerciseId IN ("training"."workoutExercises"->>id)`, {
exerciseId,
})
.getMany();
返回一个空数组。应该还点东西的
this.createQueryBuilder('training')
.where('workoutExercises->>id IN (:exerciseId)', { exerciseId })
.getMany();
希望这能奏效:).