mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
improvement: add sort + select test
This commit is contained in:
parent
9e4fce974f
commit
34a8b5cc5b
1 changed files with 30 additions and 1 deletions
|
@ -63,7 +63,11 @@ defmodule AshPostgres.SortTest do
|
|||
Post
|
||||
|> Ash.Query.load([
|
||||
:count_of_comments,
|
||||
comments: Comment |> Ash.Query.sort([:title, :likes]) |> Ash.Query.limit(1)
|
||||
comments:
|
||||
Comment
|
||||
|> Ash.Query.sort([:title, :likes])
|
||||
|> Ash.Query.select([:title, :likes])
|
||||
|> Ash.Query.limit(1)
|
||||
])
|
||||
|> Ash.Query.sort([:title, :score])
|
||||
|> Api.read!()
|
||||
|
@ -74,4 +78,29 @@ defmodule AshPostgres.SortTest do
|
|||
%{title: "bbb"}
|
||||
] = posts
|
||||
end
|
||||
|
||||
test "multicolumn sort works with a select statement" do
|
||||
Post
|
||||
|> Ash.Changeset.new(%{title: "aaa", score: 0})
|
||||
|> Api.create!()
|
||||
|
||||
Post
|
||||
|> Ash.Changeset.new(%{title: "aaa", score: 1})
|
||||
|> Api.create!()
|
||||
|
||||
Post
|
||||
|> Ash.Changeset.new(%{title: "bbb", score: 0})
|
||||
|> Api.create!()
|
||||
|
||||
assert [
|
||||
%{title: "aaa", score: 0},
|
||||
%{title: "aaa", score: 1},
|
||||
%{title: "bbb"}
|
||||
] =
|
||||
Api.read!(
|
||||
Post
|
||||
|> Ash.Query.sort(title: :asc, score: :asc)
|
||||
|> Ash.Query.select([:title, :score])
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue