File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -1683,4 +1683,51 @@ defmodule AshSql.AggregateTest do
16831683 |> Ash . read_one! ( )
16841684 end
16851685 end
1686+
1687+ @ tag :regression
1688+ test "count is accurate" do
1689+ org =
1690+ AshPostgres.Test.Organization
1691+ |> Ash.Changeset . for_create ( :create , % { name: "Test Org" } )
1692+ |> Ash . create! ( )
1693+
1694+ user =
1695+ AshPostgres.Test.User
1696+ |> Ash.Changeset . for_create ( :create , % { name: "test_user" , organization_id: org . id } )
1697+ |> Ash . create! ( )
1698+
1699+ AshPostgres.Test.User
1700+ |> Ash.Changeset . for_create ( :create , % { name: "another_user" , organization_id: org . id } )
1701+ |> Ash . create! ( )
1702+
1703+ author =
1704+ AshPostgres.Test.Author
1705+ |> Ash.Changeset . for_create ( :create , % { first_name: "Test" , last_name: "Author" } )
1706+ |> Ash . create! ( )
1707+
1708+ post =
1709+ AshPostgres.Test.Post
1710+ |> Ash.Changeset . for_create ( :create , % {
1711+ title: "Test Post" ,
1712+ organization_id: org . id ,
1713+ author_id: author . id
1714+ } )
1715+ |> Ash . create! ( )
1716+
1717+ AshPostgres.Test.Comment
1718+ |> Ash.Changeset . for_create ( :create , % {
1719+ title: "First comment" ,
1720+ post_id: post . id ,
1721+ author_id: author . id
1722+ } )
1723+ |> Ash . create! ( )
1724+
1725+ loaded_post =
1726+ AshPostgres.Test.Post
1727+ |> Ash.Query . filter ( id == ^ post . id )
1728+ |> Ash.Query . load ( :count_of_comments )
1729+ |> Ash . read_one! ( actor: user )
1730+
1731+ assert loaded_post . count_of_comments == 1
1732+ end
16861733end
You can’t perform that action at this time.
0 commit comments