You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/topics/advanced/pagination.livemd
+28-2Lines changed: 28 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,10 @@ Ash has built-in support for two kinds of pagination: `offset` and `keyset`. You
13
13
14
14
Pagination support is configured on a per-action basis. A single action can support both kinds of pagination if desired, but typically you would use one or the other. Read actions generated with `defaults [:read]` support both offset and keyset pagination, for other `read` actions you have to configure the [`pagination` section](https://hexdocs.pm/ash/dsl-ash-resource.html#actions-read-pagination).
15
15
16
+
> ### Default Pagination Type
17
+
>
18
+
> When an action supports both pagination types, the behavior depends on your application configuration. See the ["Default Pagination Behavior"](#default-pagination-behavior-when-both-types-are-supported) section below for details on how Ash determines which type to use.
19
+
16
20
> ### Check the updated query return type!
17
21
>
18
22
> Pagination will modify the return type of calling the query action.
@@ -895,9 +899,31 @@ last_page.more?
895
899
false
896
900
```
897
901
898
-
### Actions supporting both offset and keyset pagination
902
+
### Default Pagination Behavior When Both Types Are Supported
903
+
904
+
When an action supports both `offset` and `keyset` pagination (such as default read actions), Ash uses the following logic to determine which pagination type to use:
905
+
906
+
**1. Explicit pagination parameters take precedence:**
907
+
- If `after` or `before` is provided → keyset pagination
908
+
- If `offset` is provided → offset pagination
909
+
910
+
**2. Configuration-based default for ambiguous cases:**
911
+
Ash is configured to use keyset-pagination by default when installed with `mix igniter.install ash`, or the homepage installer.
912
+
913
+
#### Practical Examples
899
914
900
-
If an action supports both offset and keyset pagination (e.g. default read actions), offset pagination is used by default when page options only contain `limit`. However, the records will have the keyset in the metadata, so keyset pagination can be performed on next pages.
915
+
Regardless of configuration, the records will have keyset metadata, so you can always transition between pagination types:
When an action supports `offset` and `keyset` pagination, and a page is requested
70
-
with only `limit` set, i.e `page: [limit: 10]`, you would get back an `%Ash.Page.Offset{}`.
69
+
When an action supports both `offset` and `keyset` pagination, and a page is requested
70
+
with only `limit` set (i.e., `page: [limit: 10]`), Ash defaulted to offset pagination
71
+
and returned an `%Ash.Page.Offset{}`.
71
72
72
73
### New Behavior
73
74
74
-
Now we will return a `%Ash.Page.Keyset{}` choosing it whenever it is ambiguous.
75
-
You can always force returning an `%Ash.Page.Offset{}` by providing the offset option,
76
-
i.e `page: [offset: 0]`
75
+
With the current default configuration, Ash will now return an `%Ash.Page.Keyset{}` when the pagination
76
+
type is ambiguous (only `limit` is provided).
77
+
78
+
For detailed pagination behavior documentation, see the [pagination guide](/documentation/topics/advanced/pagination.livemd#default-pagination-behavior-when-both-types-are-supported).
77
79
78
80
## policies.no_filter_static_forbidden_reads?
79
81
@@ -172,15 +174,15 @@ reverse order. This was missed for `Ash.Query`. Meaning if you had something lik
0 commit comments