-
Notifications
You must be signed in to change notification settings - Fork 513
Description
I’m using TypeORM with NestJS and have encountered an issue when trying to use VirtualColumn with createQueryBuilder and paginate. The VirtualColumn fields are not recognized or included in the query results when using createQueryBuilder. Here is an example of my setup and the issue I’m facing:
Entity Definitions
@Entity('MonthlyBill')
@UseDto(MonthlyBillDto)
export class MonthlyBillEntity extends AbstractEntity<MonthlyBillDto> {
@Entity('Users')
@UseDto(UsersDto)
export class Users extends AbstractEntity<UsersDto> {
@PrimaryGeneratedColumn()
id: number;
@Column()
group: string;
@VirtualColumn({
query: (alias) => `(SELECT COUNT(id) FROM Users WHERE group = ${alias}.group)`,
})
userCount: number;
}Query Builder and Pagination
const pageOptionsDto = { q: 'GROUP_A' };
const query = this.usersRepository.createQueryBuilder('users');
const [items, pageMetaDto] = await query.paginate(pageOptionsDto);Issue
When using the above setup, the VirtualColumn fields userCount are not included in the query results. This issue occurs because createQueryBuilder does not recognize or include VirtualColumn fields in the results.
Request
Is there a recommended approach to use VirtualColumn with createQueryBuilder and paginate in TypeORM? If not, could support for this feature be added? It would be very helpful to be able to use VirtualColumn seamlessly with createQueryBuilder and pagination.
Thank you for your assistance.