ash_postgres/test/distinct_test.exs
Zach Daniel 4d2d29d976 feat: support configuring references
feat: support configuring polymorphic references
feat: support `distinct` Ash queries
2021-04-01 02:19:30 -04:00

33 lines
700 B
Elixir

defmodule AshPostgres.DistinctTest do
@moduledoc false
use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.{Api, Post}
require Ash.Query
test "records returned are distinct on the provided field" do
Post
|> Ash.Changeset.new(%{title: "title"})
|> Api.create!()
Post
|> Ash.Changeset.new(%{title: "title"})
|> Api.create!()
Post
|> Ash.Changeset.new(%{title: "foo"})
|> Api.create!()
Post
|> Ash.Changeset.new(%{title: "foo"})
|> Api.create!()
results =
Post
|> Ash.Query.distinct(:title)
|> Ash.Query.sort(:title)
|> Api.read!()
assert [%{title: "foo"}, %{title: "title"}] = results
end
end