Skip to content
Merged
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
47 changes: 47 additions & 0 deletions test/aggregate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,4 +1683,51 @@ defmodule AshSql.AggregateTest do
|> Ash.read_one!()
end
end

@tag :regression
test "count is accurate" do
org =
AshPostgres.Test.Organization
|> Ash.Changeset.for_create(:create, %{name: "Test Org"})
|> Ash.create!()

user =
AshPostgres.Test.User
|> Ash.Changeset.for_create(:create, %{name: "test_user", organization_id: org.id})
|> Ash.create!()

AshPostgres.Test.User
|> Ash.Changeset.for_create(:create, %{name: "another_user", organization_id: org.id})
|> Ash.create!()

author =
AshPostgres.Test.Author
|> Ash.Changeset.for_create(:create, %{first_name: "Test", last_name: "Author"})
|> Ash.create!()

post =
AshPostgres.Test.Post
|> Ash.Changeset.for_create(:create, %{
title: "Test Post",
organization_id: org.id,
author_id: author.id
})
|> Ash.create!()

AshPostgres.Test.Comment
|> Ash.Changeset.for_create(:create, %{
title: "First comment",
post_id: post.id,
author_id: author.id
})
|> Ash.create!()

loaded_post =
AshPostgres.Test.Post
|> Ash.Query.filter(id == ^post.id)
|> Ash.Query.load(:count_of_comments)
|> Ash.read_one!(actor: user)

assert loaded_post.count_of_comments == 1
end
end