【发布时间】:2021-05-05 22:27:29
【问题描述】:
我想通过表关系订购这个查找功能。
const [people, total] = await typePersonServiceInstance.find(
{
take,
skip,
where: (qb: any) => {
qb.where('person.type IN (:...type)', { type });
qb.andWhere('person.status IN (:...status)', { status });
if (query.search) {
qb.andWhere(new Brackets((subQb) => {
subQb.where('name like :name', { name: `%${query.search}%` });
subQb.orWhere('fantasyName like :fantasyName', { fantasyName: `%${query.search}%` });
subQb.orWhere('person.city like :city', { city: `%${query.search}%` });
subQb.orWhere('person.state like :state', { state: `%${query.search}%` });
subQb.orWhere('person.id = :id', { id: query.search });
}));
}
},
order: {
person: {
status: 'ASC'
}
}
},
);
我面临的问题是尝试通过person 表中的某些属性进行排序时,如果我这样做的话
order: {
anyColumnFromTypePersonHere: 'ASC' | 'DESC'
}
它工作得很好,但如果我想按状态排序(这是一个人的属性)它不会工作
【问题讨论】:
标签: node.js sorting entity relationship typeorm