1
I am using typeorm and graphql in my api and want to make a findAndCount in a table called corresponding_users that has a one to one relation with the table users, but the query only works if Where is in the primary key of the other table, follows the code:
@Query((returns) => GetAllCorrespondingsResponse)
async getAllCorrespondingsBySearchTerm(
@Arg('page', { defaultValue: 1 }) page: number,
@Arg('searchTerm') searchTerm: string
) {
const [result, total] = await CorrespondingUser.findAndCount({
relations: [
'user',
'user.address',
'user.userBankData',
'correspondingDistrict',
'correspondingDistrict.district',
'mainDistrict',
],
where: {
user: {
name: Raw((alias) => `${alias} ILIKE '%${searchTerm}%'`),
},
},
order: {
corresponding_user_id: 'DESC',
},
take: 2,
skip: (page - 1) * 2,
});
return {
correspondings: result,
total: total,
};
}