vapor-community / pagination

Simple Vapor 3 Pagination
MIT License
64 stars 15 forks source link

Order of paginated results #10

Closed danielinoa closed 6 years ago

danielinoa commented 6 years ago

Paginated results seem to be outputted in descending order. I have a collection of 100 posts. Page 1 includes 10 posts going from post #100 to post #91. The function looks like this:

func test(_ req: Request) throws -> Future<Paginated<Post>> {
    return try Post.query(on: req).paginate(for: req)
}

Is this expected behavior?

anthonycastelli commented 6 years ago

By default it's in descending order. https://github.com/vapor-community/pagination/blob/91658b8ff9300a196190faaa300b33c5e975783c/Sources/Pagination/Paginatable.swift#L23-L37

If you want to switch it, just override defaultPageSorts

extension Post: Paginatable {
    static var defaultPageSorts: [Self.Database.QuerySort] {
        return [
            // My sorts
        ]
    }
}

Let me know if that helps.

anthonycastelli commented 6 years ago

Closing this due to inactivity. If this issue still persists, let me know.

danielinoa commented 6 years ago

I ended up overriding defaultPageSorts. Thanks so much for the help! 🙌