Open jadhavmanoj opened 2 years ago
Sounds tempting. Order normalization can't be removed (or at least it would be a very breaking change), because Sequelize's order
value has many supported formats. I wonder how createCursor and recursivelyGetPaginationQuery would work in this case.
Would it be possible for you to open a pull request of your implementation with a few test cases?
@Kaltsoon you are right! 😥. the above mentioned functions does not support ordering on associated model.
I am working on the solution. I will create PR once it is ready.
As of now, this lib does not support ordering on associated models. But this can be achieved quickly imo.
Proposed solution:
We should just look for the
omitPrimaryKeyFromOrder
argument, and then addprimaryKeyField
to the 'orderOption' variable and give that object to the model.paginate function.We should not parse anything else. paginate parses the order argument and constructs the query.
Below code block is from
normalizedOrder
function - https://github.com/Kaltsoon/sequelize-cursor-pagination/blob/6d5f8ba5a241a17774bc05ad15533e854ed177de/src/utils.js#L39We should remove this. ordering parameter for associated model can be nested many level. ex. ordering =
[[{model:user, as: "users"}, "name", "ASC" ]]
Let me know if you have better approach to implement this feature.
I tried implementing this approach, worked for me.