sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

CursorTrait implementation for SelectTwo

Open lasantosr opened this issue 3 years ago • 3 comments

Motivation

Cursor-based pagination is implemented for single tables, but we can't use it when querying with related table, even it's the same concept and most of the work done still apply.

Proposed Solutions

I don't know the best implementation but I guess Cursor struct should be edited to support two tables and the API should support some way of indicating which table columns on before and after belongs to. Then CursorTrait can be implemented for SelectTwo and SelectTwoMany.

lasantosr avatar Sep 29 '22 07:09 lasantosr

Hey @lasantosr, welcome! I think we could implement cursor pagination for SelectTwo. However, I don't think it's trivial to implement cursor pagination for SelectTwoMany. Because in SelectTwoMany, we query N parent rows and its M child rows in a single query then fold it into Vec<N, Vec<M>>. So, we cannot precisely paginate the result, for example a parent row with 101 child rows but the page size is just 100, we will leave one child behind.

billy1624 avatar Sep 30 '22 08:09 billy1624

You're right @billy1624, I missed that point, I think its enough for SelectTwo.

In the case of SelectTwoMany I guess we will have to paginate the main entity and then, if needed, paginate the related children.

Thanks!

lasantosr avatar Sep 30 '22 08:09 lasantosr

Just an additional idea on Cursor: it's likely we can add a cursor method (in addition to cursor_by) which automatically uses the Entity's primary key as the cursor key. It won't work for SelectTwo though

tyt2y3 avatar Feb 22 '23 05:02 tyt2y3