Skip to content

Commit 8e3f549

Browse files
authored
README (#2)
1 parent aff1cae commit 8e3f549

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ defmodule Post do
2222
data_layer: Ash.DataLayer.Postgres,
2323
extensions: [AshDefaultSort]
2424

25+
relationships do
26+
has_many :comments, Comment
27+
has_many :tags, Tag do
28+
sort [id: :asc]
29+
end
30+
end
31+
2532
actions do
2633
read :read do
2734
primary? true
@@ -36,18 +43,22 @@ defmodule Post do
3643

3744
read :read_every do
3845
end
46+
end
3947

4048
default_sort do
4149
sort [like_count: :desc, created_at: :desc]
50+
has_many_sort [id: :desc]
4251
include_primary_read? false
4352
except [:read_all]
4453
end
4554
end
4655
```
4756

48-
In the example above, [like_count: :desc, created_at: :desc] is applied to `read_every`.
57+
In the example above, `[like_count: :desc, created_at: :desc]` is applied to `read_every`.
58+
59+
This is because `read` is excluded by `include_primary_read? false`, `read_sorted` is not affected because it already includes a `sort`, and `read_all` is excluded by the `except` option.
4960

50-
This is because `read` is excluded by `include_primary_read? false`, `read_sorted` is not affected because it already includes a sort, and `read_all` is excluded by the `except` option.
61+
And the `default_sort` for `comments` is set to `[id: :desc]` because `has_many_sort` is present, and `comments` has no `sort` or `default_sort` options.
5162

5263
## License
5364

lib/ash_default_sort/has_many_sort/transformer.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ defmodule AshDefaultSort.HasManySort.Transformer do
1414
dsl_state
1515
|> Transformer.get_entities([:relationships])
1616
|> Enum.filter(&(&1.type == :has_many))
17+
|> Enum.reject(&(&1.default_sort || &1.sort))
1718
|> Enum.reject(&(&1.name in except))
18-
|> Enum.reject(& &1.default_sort)
1919
|> Enum.map(&%{&1 | default_sort: has_many_sort})
2020
|> Enum.reduce(dsl_state, fn has_many, dsl_state ->
2121
Transformer.replace_entity(

0 commit comments

Comments
 (0)