File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ defmodule AshPostgres.Test.ParentSortTest do
2+ use AshPostgres.RepoCase , async: false
3+
4+ alias AshPostgres.Test . { Organization , Post , User }
5+
6+ require Ash.Query
7+
8+ test "can reference parent field when declaring default sort in has_many no_attributes? relationship" do
9+ organization =
10+ Organization
11+ |> Ash.Changeset . for_create ( :create , % { name: "test_org" } )
12+ |> Ash . create! ( )
13+
14+ user =
15+ User
16+ |> Ash.Changeset . for_create ( :create , % { organization_id: organization . id , name: "foo bar" } )
17+ |> Ash . create! ( )
18+
19+ Post
20+ |> Ash.Changeset . for_create ( :create , % { organization_id: organization . id } )
21+ |> Ash . create! ( )
22+
23+ Post
24+ |> Ash.Changeset . for_create ( :create , % { organization_id: organization . id , title: "test_org" } )
25+ |> Ash . create! ( )
26+
27+ assert { :ok , _ } =
28+ Post
29+ |> Ash.Query . load ( :recommendations )
30+ |> Ash . read ( authorize?: false )
31+ end
32+ end
Original file line number Diff line number Diff line change @@ -614,6 +614,12 @@ defmodule AshPostgres.Test.Post do
614614 filter ( expr ( fragment ( "? = ?" , title , parent ( organization . name ) ) ) )
615615 end
616616
617+ has_many ( :recommendations , __MODULE__ ) do
618+ public? ( true )
619+ no_attributes? ( true )
620+ sort ( [ calc ( fragment ( "abs(extract epoch from ?))" , parent ( datetime ) - datetime ) ) ] )
621+ end
622+
617623 belongs_to :parent_post , __MODULE__ do
618624 public? ( true )
619625 end
You can’t perform that action at this time.
0 commit comments