I have this code:
defmodule Project.Role do
use Ash.Resource,
data_layer: AshPostgres.DataLayer
attributes do
uuid_primary_key(:id)
create_timestamp(:inserted_at)
update_timestamp(:updated_at)
attribute(:name, :string, allow_nil?: false)
attribute(:roles, {:array, :map})
end
code_interface do
define_for(Project.Resource)
define(:create, action: :create)
define(:update, action: :update)
define(:destroy, action: :destroy)
end
actions do
defaults([:create, :read, :update, :destroy])
end
end
iex> roles = [%{section: :client, actions[:create, :update]}, %{section: :product, actions[:create, :update]}]
iex> role = Project.Role.create! %{name: "test", roles: roles}
iex> Project.Role.update! role, %{name: "test 2", roles: roles}
No problem for create, but, when if update, show an error.
** (EXIT from #PID<0.536.0>) an exception was raised:
** (Ash.Error.Unknown) Unknown Error
* ** (Postgrex.Error) ERROR 42804 (datatype_mismatch) column "roles" is of type jsonb[] but expression is of type text[]