nestjs-paginate
nestjs-paginate copied to clipboard
Cannot read properties of undefined (reading 'databaseName')
package.json
{
"@nestjs/common": "^9.0.0",
"typeorm": "^0.3.17",
"nestjs-paginate": "^9.0.0",
}
customer.entity.ts
@Entity()
export class Customer {
...
@Column({ type: 'json', default: {} })
customFields: any;
...
}
service:
async findPaginated(company: Company, paginateQuery: PaginateQuery, entityType: string, relations: string[]) {
...
return paginate(
paginateQuery,
repo,
{
// @ts-ignore
sortableColumns: ['id'],
// @ts-ignore
defaultSortBy: [['id', 'ASC'], ['customFields.scoring', 'DESC']], // Issue with this line
where: {
company: { id: company.id }
}
}
)
}
When calling the service, it's giving me this error:
TypeError: Cannot read properties of undefined (reading 'databaseName')
Hi! :) Could you put this in a little repository by any chance so that I can clone it and debug it from there? :)
Hello, I am facing the same issue, it happens when I add relations to the PaginatteConfig.
This stack overflow queitons outlines the same issue
[Nest] 15768 - 01/24/2025, 11:52:29 AM ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'databaseName') TypeError: Cannot read properties of undefined (reading 'databaseName') at <anonymous> (C:\work\server\node_modules\typeorm\query-builder\src\query-builder\SelectQueryBuilder.ts:3685:41) at Array.map (<anonymous>) at SelectQueryBuilder.createOrderByCombinedWithSelectExpression (C:\work\server\node_modules\typeorm\query-builder\src\query-builder\SelectQueryBuilder.ts:3669:14) at SelectQueryBuilder.executeEntitiesAndRawResults (C:\work\server\node_modules\typeorm\query-builder\src\query-builder\SelectQueryBuilder.ts:3429:22) at SelectQueryBuilder.getManyAndCount (C:\work\server\node_modules\typeorm\query-builder\src\query-builder\SelectQueryBuilder.ts:1873:47) at paginate (C:\work\server\node_modules\nestjs-paginate\src\paginate.ts:438:51) at ATMService.findAndPaginate (C:\work\server\src\atms\atm.service.ts:45:20) at ATMResolver.getATMs (C:\work\server\src\atms\atm.resolver.ts:24:28) at C:\work\server\node_modules\@nestjs\core\helpers\external-context-creator.js:67:33 at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
you can not sort like this by an inner json field value, it requires much more transformations to do it, and it's not provided by the library or typeorm itself, and quite hard to implement. this specific error means that there is not such column in a table (that's thrown by typeorm).
please reopen an issue if you still think it's possible to fix