2023-11-21 10:52:50 +13:00
|
|
|
defmodule AshPostgres.ReferencesTest do
|
|
|
|
use ExUnit.Case
|
|
|
|
|
|
|
|
test "can't use match_type != :full when referencing an non-primary key index" do
|
|
|
|
Code.compiler_options(ignore_module_conflict: true)
|
|
|
|
on_exit(fn -> Code.compiler_options(ignore_module_conflict: false) end)
|
|
|
|
|
|
|
|
defmodule Org do
|
|
|
|
@moduledoc false
|
|
|
|
use Ash.Resource,
|
2024-03-28 09:52:28 +13:00
|
|
|
domain: nil,
|
2023-11-21 10:52:50 +13:00
|
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key(:id, writable?: true)
|
2024-03-28 09:52:28 +13:00
|
|
|
attribute(:name, :string, public?: true)
|
2023-11-21 10:52:50 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
multitenancy do
|
|
|
|
strategy(:attribute)
|
|
|
|
attribute(:id)
|
|
|
|
end
|
|
|
|
|
|
|
|
postgres do
|
|
|
|
table("orgs")
|
|
|
|
repo(AshPostgres.TestRepo)
|
|
|
|
end
|
|
|
|
|
|
|
|
actions do
|
|
|
|
defaults([:create, :read, :update, :destroy])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defmodule User do
|
|
|
|
@moduledoc false
|
|
|
|
use Ash.Resource,
|
2024-03-28 09:52:28 +13:00
|
|
|
domain: nil,
|
2023-11-21 10:52:50 +13:00
|
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key(:id, writable?: true)
|
2024-03-28 09:52:28 +13:00
|
|
|
attribute(:secondary_id, :uuid, public?: true)
|
|
|
|
attribute(:foo_id, :uuid, public?: true)
|
|
|
|
attribute(:name, :string, public?: true)
|
|
|
|
attribute(:org_id, :uuid, public?: true)
|
2023-11-21 10:52:50 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
multitenancy do
|
|
|
|
strategy(:attribute)
|
|
|
|
attribute(:org_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
relationships do
|
2024-03-28 09:52:28 +13:00
|
|
|
belongs_to(:org, Org) do
|
|
|
|
public?(true)
|
|
|
|
end
|
2023-11-21 10:52:50 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
postgres do
|
|
|
|
table("users")
|
|
|
|
repo(AshPostgres.TestRepo)
|
|
|
|
end
|
|
|
|
|
|
|
|
actions do
|
|
|
|
defaults([:create, :read, :update, :destroy])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise Spark.Error.DslError, ~r/Unsupported match_type./, fn ->
|
|
|
|
defmodule UserThing do
|
|
|
|
@moduledoc false
|
|
|
|
use Ash.Resource,
|
2024-03-28 09:52:28 +13:00
|
|
|
domain: nil,
|
2023-11-21 10:52:50 +13:00
|
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
|
|
|
|
attributes do
|
2024-03-28 09:52:28 +13:00
|
|
|
attribute(:id, :string, primary_key?: true, allow_nil?: false, public?: true)
|
|
|
|
attribute(:name, :string, public?: true)
|
|
|
|
attribute(:org_id, :uuid, public?: true)
|
|
|
|
attribute(:foo_id, :uuid, public?: true)
|
2023-11-21 10:52:50 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
multitenancy do
|
|
|
|
strategy(:attribute)
|
|
|
|
attribute(:org_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
relationships do
|
|
|
|
belongs_to(:org, Org)
|
|
|
|
belongs_to(:user, User, destination_attribute: :secondary_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
postgres do
|
|
|
|
table("user_things")
|
|
|
|
repo(AshPostgres.TestRepo)
|
|
|
|
|
|
|
|
references do
|
|
|
|
reference :user, match_with: [foo_id: :foo_id], match_type: :simple
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
actions do
|
|
|
|
defaults([:create, :read, :update, :destroy])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|