mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-21 05:53:18 +12:00
37cc01957d
* WIP * chore: fix mix.lock merge issues * improvement: upgrade to 3.0 * chore: remove `repo.to_tenant` * chore: continue removal of unnecessary helper * chore: use `Ash.ToTenant`
108 lines
2.6 KiB
Elixir
108 lines
2.6 KiB
Elixir
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,
|
|
domain: nil,
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
attributes do
|
|
uuid_primary_key(:id, writable?: true)
|
|
attribute(:name, :string, public?: true)
|
|
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,
|
|
domain: nil,
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
attributes do
|
|
uuid_primary_key(:id, writable?: true)
|
|
attribute(:secondary_id, :uuid, public?: true)
|
|
attribute(:foo_id, :uuid, public?: true)
|
|
attribute(:name, :string, public?: true)
|
|
attribute(:org_id, :uuid, public?: true)
|
|
end
|
|
|
|
multitenancy do
|
|
strategy(:attribute)
|
|
attribute(:org_id)
|
|
end
|
|
|
|
relationships do
|
|
belongs_to(:org, Org) do
|
|
public?(true)
|
|
end
|
|
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,
|
|
domain: nil,
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
attributes do
|
|
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)
|
|
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
|