From 687723730a2f59b82f67f7bd32e715f3bba66407 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Wed, 17 May 2023 22:36:47 -0400 Subject: [PATCH] fix: errors on casting arrays of unions in newtypes --- lib/ash/error/invalid/unavailable.ex | 1 - lib/ash/resource/schema.ex | 12 ++++++++---- lib/ash/type/new_type.ex | 11 +++-------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/ash/error/invalid/unavailable.ex b/lib/ash/error/invalid/unavailable.ex index 23dac4f4..d81c26d8 100644 --- a/lib/ash/error/invalid/unavailable.ex +++ b/lib/ash/error/invalid/unavailable.ex @@ -14,7 +14,6 @@ defmodule Ash.Error.Invalid.Unavailable do def code(_), do: "unavailable" - @spec message(%Ash.Error.Invalid.Unavailable{}) :: <<_::64, _::_*8>> def message(%{resource: resource, source: source, reason: reason}) when not is_nil(source) do """ #{inspect(resource)} - the resource is not available#{with_reason(reason)}. diff --git a/lib/ash/resource/schema.ex b/lib/ash/resource/schema.ex index deff7ccc..b1f99045 100644 --- a/lib/ash/resource/schema.ex +++ b/lib/ash/resource/schema.ex @@ -175,23 +175,26 @@ defmodule Ash.Schema do :ok %{type: :belongs_to} -> - belongs_to relationship.name, relationship.destination, + belongs_to(relationship.name, relationship.destination, define_field: false, references: relationship.destination_attribute, foreign_key: relationship.source_attribute + ) %{type: :has_many} -> - has_many relationship.name, relationship.destination, + has_many(relationship.name, relationship.destination, foreign_key: relationship.destination_attribute, references: relationship.source_attribute + ) %{type: :has_one} -> - has_one relationship.name, relationship.destination, + has_one(relationship.name, relationship.destination, foreign_key: relationship.destination_attribute, references: relationship.source_attribute + ) %{type: :many_to_many} -> - many_to_many relationship.name, relationship.destination, + many_to_many(relationship.name, relationship.destination, join_through: relationship.through, join_keys: [ {relationship.source_attribute_on_join_resource, @@ -199,6 +202,7 @@ defmodule Ash.Schema do {relationship.destination_attribute_on_join_resource, relationship.destination_attribute} ] + ) end Module.put_attribute( diff --git a/lib/ash/type/new_type.ex b/lib/ash/type/new_type.ex index bcc900bc..b1a882fb 100644 --- a/lib/ash/type/new_type.ex +++ b/lib/ash/type/new_type.ex @@ -178,10 +178,10 @@ defmodule Ash.Type.NewType do end @impl Ash.Type - def equal?(value, constraints) do + def equal?(left, right) do unquote(subtype_of).equal?( - value, - type_constraints(constraints, unquote(subtype_constraints)) + left, + right ) end @@ -248,11 +248,6 @@ defmodule Ash.Type.NewType do unquote(subtype_of).storage_type() end - @impl Ash.Type - def ecto_type do - unquote(subtype_of).ecto_type() - end - @impl Ash.Type def constraints do unquote(subtype_of).constraints()