Open kenvals opened 2 months ago
Please add a support to sort by relation count
I'm trying to use pagination to display product cards.
However I have a connection Typeorm as: Products <-> accounting
ProductsEntity:
@OneToMany(() => AccountingEntity, (accounting) => accounting.product, {}) accounting: AccountingEntity[]; AccountingEntity: @ManyToOne(() => ProductEntity, (product) => product.accounting, { onDelete: 'CASCADE', }) @JoinColumn({ name: 'product_id' }) product: ProductEntity;
I display my product cards, but I can’t do it to show only those records in which there is NO accounting! or vice versa there is only ACCOUNTING
How can I do this correctly?
My code:
const result: any = await paginate(query, this.productRepository, { sortableColumns: ['uuid', 'name', 'inventory', 'series', 'count', 'accounting', 'author.last_name',], relations: ['accounting', 'author', 'user'], nullSort: 'last', defaultSortBy: [['uuid', 'DESC']], searchableColumns: ['uuid', 'name', 'count', 'author.last_name', 'author.first_name', 'author.surname', 'user.last_name', 'user.first_name', 'user.surname', 'series', 'inventory',], filterableColumns: { count: [FilterOperator.EQ, FilterOperator.BTW], accounting: true, author: true, user: true }, });
You can achieve this using where
in pagination config
@ppetzold What about ordering with the count of relation?
I'm trying to use pagination to display product cards.
However I have a connection Typeorm as: Products <-> accounting
ProductsEntity:
I display my product cards, but I can’t do it to show only those records in which there is NO accounting! or vice versa there is only ACCOUNTING
How can I do this correctly?
My code: