mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-19 13:03:14 +12:00
fix: update ash & fix subquery sort references
This commit is contained in:
parent
56f3a5eb2f
commit
77b824e23d
4 changed files with 25 additions and 12 deletions
|
@ -21,6 +21,8 @@ if Mix.env() == :test do
|
|||
config :ash, :validate_domain_resource_inclusion?, false
|
||||
config :ash, :validate_domain_config_inclusion?, false
|
||||
|
||||
config :ash, :policies, show_policy_breakdowns?: true
|
||||
|
||||
config :ash_postgres, :ash_domains, [AshPostgres.Test.Domain]
|
||||
|
||||
config :ash_postgres, AshPostgres.TestRepo,
|
||||
|
|
|
@ -1348,7 +1348,7 @@ defmodule AshPostgres.DataLayer do
|
|||
|
||||
if needs_to_join? do
|
||||
root_query =
|
||||
from(row in query.from.source, [])
|
||||
from(row in query.from.source, as: ^0)
|
||||
|> Map.put(:__ash_bindings__, query.__ash_bindings__)
|
||||
|> Ecto.Query.exclude(:select)
|
||||
|> Map.put(:limit, query.limit)
|
||||
|
@ -1356,7 +1356,7 @@ defmodule AshPostgres.DataLayer do
|
|||
|
||||
root_query =
|
||||
if query.limit || query.offset do
|
||||
root_query
|
||||
Map.put(root_query, :order_bys, query.order_bys)
|
||||
else
|
||||
Ecto.Query.exclude(root_query, :order_by)
|
||||
end
|
||||
|
@ -1374,11 +1374,12 @@ defmodule AshPostgres.DataLayer do
|
|||
end)
|
||||
|
||||
faked_query =
|
||||
from(row in root_query,
|
||||
from(row in query.from.source,
|
||||
inner_join: limiter in ^subquery(root_query),
|
||||
as: ^0,
|
||||
on: ^dynamic
|
||||
)
|
||||
|> Map.put(:__ash_bindings__, query.__ash_bindings__)
|
||||
|
||||
joins_to_add =
|
||||
for {%{on: on} = join, ix} <- Enum.with_index(query.joins) do
|
||||
|
|
|
@ -21,11 +21,17 @@ defmodule AshPostgres.BulkUpdateTest do
|
|||
end
|
||||
|
||||
test "bulk updates can set datetimes" do
|
||||
Ash.bulk_create!([%{title: "fred"}, %{title: "george"}], Post, :create)
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create, %{title: "fred"})
|
||||
|> Ash.create!()
|
||||
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create, %{title: "george"})
|
||||
|> Ash.create!()
|
||||
|
||||
now = DateTime.utc_now()
|
||||
|
||||
Ash.bulk_update!(Post, :update, %{datetime: now})
|
||||
Ash.bulk_update!(Post, :update, %{datetime: now}, strategy: :atomic)
|
||||
|
||||
posts = Ash.read!(Post)
|
||||
|
||||
|
@ -81,7 +87,10 @@ defmodule AshPostgres.BulkUpdateTest do
|
|||
Post
|
||||
|> Ash.Query.limit(1)
|
||||
|> Ash.Query.sort(:title)
|
||||
|> Ash.bulk_update!(:update, %{}, atomic_update: %{title: Ash.Expr.expr(title <> "_stuff")})
|
||||
|> Ash.bulk_update!(:update, %{},
|
||||
atomic_update: %{title: Ash.Expr.expr(title <> "_stuff")},
|
||||
strategy: :atomic
|
||||
)
|
||||
|
||||
titles =
|
||||
Post
|
||||
|
|
|
@ -38,12 +38,13 @@ defmodule AshPostgres.Test.MultitenancyTest do
|
|||
end
|
||||
|
||||
test "context multitenancy works with policies", %{org1: org1} do
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create, %{name: "foo"})
|
||||
|> Ash.Changeset.set_tenant(tenant(org1))
|
||||
|> Ash.create!()
|
||||
|> Ash.Changeset.for_update(:update_with_policy, %{}, authorize?: true)
|
||||
|> Ash.Changeset.set_tenant(tenant(org1))
|
||||
post =
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:create, %{name: "foo"}, tenant: tenant(org1))
|
||||
|> Ash.create!()
|
||||
|
||||
post
|
||||
|> Ash.Changeset.for_update(:update_with_policy, %{}, authorize?: true, tenant: tenant(org1))
|
||||
|> Ash.update!()
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue