语境
我有两个实体:
@Entity({ tableName: 'students' })
export class StudentEntity {
@Property()
firstName: string;
@Property()
lastName: string;
@ManyToMany({
entity: () => TeacherEntity,
pivotTable: 'students_to_teachers',
joinColumn: 'student_id',
inverseJoinColumn: ;teacher_id'
})
teachers = new Collection<TeacherEntity>(this);
}
和 ...
@Entity({ tableName: 'teachers' })
export class TeacherEntity {
@OneToOne(() => UserEntity, {
owner: true,
fieldName: 'user_id',
})
user: UserEntity;
@ManyToMany({
entity: () => StudentEntity,
pivotTable: 'students_to_teachers',
joinColumn: 'teacher_id',
mappedBy: (s: StudentEntity) => s.teachers
})
students = new Collection<StudentEntity>(this);
}
任务
给定 auserId
的UserEntity
a TeacherEntity
,我可以通过以下方式获取与这位老师有联系的所有学生
const students = await this.studentsRepo.find(
{
teachers: {
user: {
id: userId
}
}
}
);
问题
现在我想要相反的做法。我想选出所有与这位老师没有关系的学生。出于本能,我做了类似的事情
const students = await this.studentsRepo.find(
{
teachers: {
user: {
$ne: {
id: userId
}
}
}
}
);
但它没有作用。
请指教!