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
56 changes: 56 additions & 0 deletions priv/resource_snapshots/test_repo/tags/20260105194602.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"attributes": [
{
"allow_nil?": false,
"default": "fragment(\"gen_random_uuid()\")",
"generated?": false,
"precision": null,
"primary_key?": true,
"references": null,
"scale": null,
"size": null,
"source": "id",
"type": "uuid"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"precision": null,
"primary_key?": false,
"references": null,
"scale": null,
"size": null,
"source": "title",
"type": "text"
},
{
"allow_nil?": false,
"default": "0",
"generated?": false,
"precision": null,
"primary_key?": false,
"references": null,
"scale": null,
"size": null,
"source": "importance",
"type": "bigint"
}
],
"base_filter": null,
"check_constraints": [],
"create_table_options": null,
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "8357381E60B641F3A2F66AF2B3830CCFADFB6EFC281D65A0AA4BCD714A611B0E",
"identities": [],
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"repo": "Elixir.AshPostgres.TestRepo",
"schema": null,
"table": "tags"
}
21 changes: 21 additions & 0 deletions priv/test_repo/migrations/20260105194602_add_title_to_tags.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule AshPostgres.TestRepo.Migrations.AddTitleToTags do
@moduledoc """
Updates resources based on their most recent snapshots.

This file was autogenerated with `mix ash_postgres.generate_migrations`
"""

use Ecto.Migration

def up do
alter table(:tags) do
add(:title, :text)
end
end

def down do
alter table(:tags) do
remove(:title)
end
end
end
25 changes: 25 additions & 0 deletions test/aggregate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,31 @@

assert Enum.sort(user.years_visited) == ["1955", "1985", "1985", "2015"]
end

test "reproduction of a bug where joins involving an aggregate use the wrong id on a join condition" do

Check failure on line 742 in test/aggregate_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (16) / mix test

test list reproduction of a bug where joins involving an aggregate use the wrong id on a join condition (AshSql.AggregateTest)

Check failure on line 742 in test/aggregate_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (14) / mix test

test list reproduction of a bug where joins involving an aggregate use the wrong id on a join condition (AshSql.AggregateTest)

Check failure on line 742 in test/aggregate_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (15) / mix test

test list reproduction of a bug where joins involving an aggregate use the wrong id on a join condition (AshSql.AggregateTest)
tag =
AshPostgres.Test.Tag
|> Ash.Changeset.for_create(:create, %{title: "Hello There"})
|> Ash.create!()

post =
AshPostgres.Test.Post
|> Ash.Changeset.for_create(:create, %{title: "A Post"})
|> Ash.create!()

comment =
AshPostgres.Test.Comment
|> Ash.Changeset.for_create(:create, %{title: "Hello There"})
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
|> Ash.create!()

_post_tag =
AshPostgres.Test.PostTag
|> Ash.Changeset.for_create(:create, %{post_id: post.id, tag_id: tag.id})
|> Ash.create!()

assert Ash.calculate!(tag, :has_post_with_comment_with_same_title) == true
end
end

describe "first" do
Expand Down
9 changes: 9 additions & 0 deletions test/support/resources/tag.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule AshPostgres.Test.Tag do

attributes do
uuid_primary_key(:id)
attribute(:title, :string, allow_nil?: true, public?: true)
attribute(:importance, :integer, allow_nil?: false, default: 0, public?: true)
end

Expand All @@ -48,4 +49,12 @@ defmodule AshPostgres.Test.Tag do
sort(score_after_winning: :desc)
end
end

calculations do
calculate(
:has_post_with_comment_with_same_title,
:boolean,
expr(title in posts.uniq_comment_titles)
)
end
end
Loading