-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is it possible to add a custom sorting function to the tool ? #4
Comments
You can sort your query results using typeorm itself. |
@mr-cool is right, use query builder to sort the results as usual then pass it to the paginator. |
thanks for your answers @mr-cool @benjamin658 |
@HippolyteJacque have you fixed your issue ? My query builder looks like that: const queryBuilder = this.productsRepository
.createQueryBuilder('product')
.addSelect('substring("metadataProduct"."countryOfOriginCode" from 1 for 2) AS "metadataProduct_country_code"')
.innerJoinAndMapOne('product.metadataProducts', metadataProductEntity, 'metadataProduct', 'product.id = metadataProduct.product_id')
.leftJoin(
ProductToOrganisationEntity,
'product_to_organisation',
'product_to_organisation.product_id = product.id AND product_to_organisation.organisation_id = :organisationId',
{ organisationId },
)
.leftJoin(
ProductEntity,
'metadataProduct2',
'metadataProduct2.product_id = product.id AND metadataProduct.createdAt < metadataProduct2.createdAt',
)
.where('metadataProduct2.id IS NULL')
.andWhere(filtersSubQuery.length ? filtersSubQuery : 'metadataProduct.id IS NOT NULL', filterValues)
.andWhere('product_to_organisation.organisation_id = :organisationId', { organisationId });
.orderBy('substring("metadataProduct"."countryOfOriginCode" from 1 for 2)', 'DESC'); and my paginator const paginator = buildPaginator({
entity: ProductEntity,
alias: 'product',
paginationKeys: ['customId'],
query: {
limit: queryOptions.first,
order: 'ASC',
afterCursor: queryOptions.afterCursor,
beforeCursor: queryOptions.beforeCursor,
},
});
return paginator.paginate(queryBuilder); I tried to use the sort function ( Nothing works :/ Maybe because I try to sort on inner tables ? @benjamin658 |
@HippolyteJacque @remithomas thanks for the reporting. Could you do me a little favor? Thanks. |
@benjamin658 |
@benjamin658 I think the problem with the sorting is being affected by |
Hello @remithomas I have actually switch to our own paginator tool, page based not cursor base tho, took 1 day to build it with typeorm, pretty simple, sorry I could not help more @benjamin658 have not get the time to try with |
Hi @jimuelpalaca and @HippolyteJacque , Thanks for your feedback. However, I'm not sure whether the custom order has any side effects, I have to add more test cases to verify it. Hope I could add this feature in few days. |
@benjamin658 |
Hi @cjlynch12 , Sorry for the late reply. I'm still working on it, but I found that the TypeORM seems to have a bug on the
(actually, there are a lot of related opened issues) If the TypeORM could not solve the issue, the custom order feature will only allow ordering on the same entity. Any suggestions are welcome. |
just wondering, thanks
The text was updated successfully, but these errors were encountered: