Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions test/parent_sort_test.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
defmodule AshPostgres.Test.ParentSortTest do

Check warning on line 1 in test/parent_sort_test.ex

View workflow job for this annotation

GitHub Actions / ash-ci (15) / mix credo --strict

Modules should have a @moduledoc tag.

Check warning on line 1 in test/parent_sort_test.ex

View workflow job for this annotation

GitHub Actions / ash-ci (14) / mix credo --strict

Modules should have a @moduledoc tag.

Check warning on line 1 in test/parent_sort_test.ex

View workflow job for this annotation

GitHub Actions / ash-ci (16) / mix credo --strict

Modules should have a @moduledoc tag.
use AshPostgres.RepoCase, async: false

alias AshPostgres.Test.{Organization, Post, User}

require Ash.Query

test "can reference parent field when declaring default sort in has_many no_attributes? relationship" do
organization =
Organization
|> Ash.Changeset.for_create(:create, %{name: "test_org"})
|> Ash.create!()

user =
User
|> Ash.Changeset.for_create(:create, %{organization_id: organization.id, name: "foo bar"})
|> Ash.create!()

Post
|> Ash.Changeset.for_create(:create, %{organization_id: organization.id})
|> Ash.create!()

Post
|> Ash.Changeset.for_create(:create, %{organization_id: organization.id, title: "test_org"})
|> Ash.create!()

assert {:ok, _} =
Post
|> Ash.Query.load(:recommendations)
|> Ash.read(authorize?: false)
end
end
6 changes: 6 additions & 0 deletions test/support/resources/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,12 @@ defmodule AshPostgres.Test.Post do
filter(expr(fragment("? = ?", title, parent(organization.name))))
end

has_many(:recommendations, __MODULE__) do
public?(true)
no_attributes?(true)
sort([calc(fragment("abs(extract epoch from ?))", parent(datetime) - datetime))])
end

belongs_to :parent_post, __MODULE__ do
public?(true)
end
Expand Down
Loading