I have a query that works in string format, but not in ObjectLiteral format:
const queryBuilder = this.usersRepository.createQueryBuilder('user');
const where = this.findQueryBuilder(options);
const result = queryBuilder
.leftJoinAndSelect('user.roles', 'role')
.andWhere((qb) => {
if (caslQueries.length > 0) {
const [firstQuery, ...otherQueries] = caslQueries;
qb.where(firstQuery);
otherQueries.forEach((query) => qb.orWhere(query));
}
})
.andWhere(where)
.andWhere({ 'role.name': 'guest' })
this causes exception:
- EntityPropertyNotFoundError: Property “role.name” was not found in “UserEntity”. Make sure your query is correct.
but if I write the same code this way:
const queryBuilder = this.usersRepository.createQueryBuilder('user');
const where = this.findQueryBuilder(options);
const result = queryBuilder
.leftJoinAndSelect('user.roles', 'role')
.andWhere((qb) => {
if (caslQueries.length > 0) {
const [firstQuery, ...otherQueries] = caslQueries;
qb.where(firstQuery);
otherQueries.forEach((query) => qb.orWhere(query));
}
})
.andWhere(where)
.andWhere('role.name = :role', { role: 'guest' })
this works without any problem. why?