Reputation: 65
I'm working on a NestJS project where I'm using nestjs-paginate with TypeORM. I have a Customer entity that has PhoneNumber and Dealer as related entities, and I’m trying to paginate Customer records along with these relations.
Here's my Customer entity:
@Entity()
export class Customer extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
@OneToOne(() => PhoneNumber, { cascade: true, nullable: true, onDelete: 'SET NULL' })
@JoinColumn()
phoneNumber?: PhoneNumber;
@ManyToOne(() => Dealer, { cascade: true, nullable: true, onDelete: 'SET NULL' })
@JoinColumn()
dealer?: Dealer;
}
In the CustomerService, I have the following findAll function for pagination:
async findAll(query: PaginateQuery): Promise<Paginated<Customer>> {
return paginate(query, this.customerRepository, {
sortableColumns: ['id', 'name', 'tc_no', 'email'],
relations: ['dealer', 'phoneNumber'],
nullSort: 'last',
defaultSortBy: [['id', 'DESC']],
searchableColumns: ['name', 'tc_no', 'email', 'address'],
select: [
'id', 'name', 'tc_no', 'phoneNumber', 'address', 'email', 'dealer', 'created', 'updated', 'deleted'
],
filterableColumns: {
name: [FilterOperator.EQ, FilterSuffix.NOT],
email: [FilterOperator.EQ],
tc_no: [FilterOperator.EQ],
deleted: [FilterOperator.EQ],
},
});
}
When running this code, I'm encountering the following error:
[Nest] ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'databaseName') TypeError: Cannot read properties of undefined (reading 'databaseName') at /typeorm/query-builder/SelectQueryBuilder.ts:3685:41
Upvotes: 1
Views: 88