Skip to content

Commit 28d53c3

Browse files
committed
Merge branch 'main' into feat-codegen-dev-mode
2 parents af4f4b6 + 9a047a2 commit 28d53c3

File tree

5 files changed

+67
-6
lines changed

5 files changed

+67
-6
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ See [Conventional Commits](https://www.conventionalcommits.org) for commit guide
55

66
<!-- changelog -->
77

8+
## [v2.5.7](https://github.com/ash-project/ash_postgres/compare/v2.5.6...v2.5.7) (2025-03-04)
9+
10+
11+
12+
13+
### Bug Fixes:
14+
15+
* handle errors from identities in polymorphic resources properly (#497)
16+
17+
* Use exclusion_constraint instead of check_constraint in add_exclusion_constraints (#495)
18+
19+
* check for stale record errors on destroy
20+
21+
* don't rely on private function from `Ecto.Repo` (#492)
22+
823
## [v2.5.6](https://github.com/ash-project/ash_postgres/compare/v2.5.5...v2.5.6) (2025-02-25)
924

1025

lib/data_layer.ex

+15-5
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,17 @@ defmodule AshPostgres.DataLayer do
19641964
end
19651965
rescue
19661966
e ->
1967-
changeset = Ash.Changeset.new(resource)
1967+
changeset =
1968+
case source do
1969+
{table, resource} ->
1970+
resource
1971+
|> Ash.Changeset.new()
1972+
|> Ash.Changeset.put_context(:data_layer, %{table: table})
1973+
1974+
resource ->
1975+
resource
1976+
|> Ash.Changeset.new()
1977+
end
19681978

19691979
handle_raised_error(
19701980
e,
@@ -2555,13 +2565,13 @@ defmodule AshPostgres.DataLayer do
25552565
{key, name} ->
25562566
case repo.default_constraint_match_type(:check, name) do
25572567
{:regex, regex} ->
2558-
Ecto.Changeset.check_constraint(changeset, key,
2568+
Ecto.Changeset.exclusion_constraint(changeset, key,
25592569
name: regex,
25602570
match: :exact
25612571
)
25622572

25632573
match ->
2564-
Ecto.Changeset.check_constraint(changeset, key,
2574+
Ecto.Changeset.exclusion_constraint(changeset, key,
25652575
name: name,
25662576
match: match
25672577
)
@@ -2570,14 +2580,14 @@ defmodule AshPostgres.DataLayer do
25702580
{key, name, message} ->
25712581
case repo.default_constraint_match_type(:check, name) do
25722582
{:regex, regex} ->
2573-
Ecto.Changeset.check_constraint(changeset, key,
2583+
Ecto.Changeset.exclusion_constraint(changeset, key,
25742584
name: regex,
25752585
message: message,
25762586
match: :exact
25772587
)
25782588

25792589
match ->
2580-
Ecto.Changeset.check_constraint(changeset, key,
2590+
Ecto.Changeset.exclusion_constraint(changeset, key,
25812591
name: name,
25822592
message: message,
25832593
match: match

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule AshPostgres.MixProject do
55
The PostgreSQL data layer for Ash Framework
66
"""
77

8-
@version "2.5.6"
8+
@version "2.5.7"
99

1010
def project do
1111
[

test/aggregate_test.exs

+29
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,35 @@ defmodule AshSql.AggregateTest do
6565
assert read_post.count_of_comments == 1
6666
end
6767

68+
test "nested filters on aggregates works" do
69+
org =
70+
Organization
71+
|> Ash.Changeset.for_create(:create, %{name: "match"})
72+
|> Ash.create!()
73+
74+
post =
75+
Post
76+
|> Ash.Changeset.for_create(:create, %{title: "match"})
77+
|> Ash.Changeset.manage_relationship(:organization, org, type: :append_and_remove)
78+
|> Ash.create!()
79+
80+
post2 =
81+
Post
82+
|> Ash.Changeset.for_create(:create, %{title: "match"})
83+
|> Ash.create!()
84+
85+
Comment
86+
|> Ash.Changeset.for_create(:create, %{title: "match"})
87+
|> Ash.Changeset.manage_relationship(:post, post2, type: :append_and_remove)
88+
|> Ash.create!()
89+
90+
assert [%{count_of_comments_matching_org_name: 1}] =
91+
Post
92+
|> Ash.Query.load(:count_of_comments_matching_org_name)
93+
|> Ash.Query.filter(id == ^post.id)
94+
|> Ash.read!()
95+
end
96+
6897
describe "Context Multitenancy" do
6998
alias AshPostgres.MultitenancyTest.{Org, Post, User}
7099

test/support/resources/post.ex

+7
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,13 @@ defmodule AshPostgres.Test.Post do
850850
filter(title: "match")
851851
end
852852

853+
count :count_of_comments_matching_org_name, [
854+
:posts_with_matching_title,
855+
:comments
856+
] do
857+
filter(expr(parent(organization.name) == title))
858+
end
859+
853860
count(:count_of_comments_containing_title, :comments_containing_title)
854861

855862
first :first_comment, :comments, :title do

0 commit comments

Comments
 (0)