I have a model with field of type array defined:
defmodule QsiSearchService.Features.FeatureProperties do
use Ecto.Schema
import Ecto.Changeset
alias QsiSearchService.Features.{FeatureProperties, FeatureType}
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "feature_properties" do
field :fields, {:array, :map}
belongs_to :feature_type, FeatureType
timestamps()
end
@doc false
def changeset(%FeatureProperties{} = feature_properties, attrs) do
feature_properties
|> cast(attrs, [:fields, :feature_type_id])
|> validate_required([:fields, :feature_type_id])
end
end
When I try creating a record:
@feature_properties_attrs %{fields: [
%{"name" => "PROGRESS_STATUS", "type" => "string"},
%{"name" => "VOLTAGE", "type" => "number"}
]}
{:ok, feature_properties} =
@feature_properties_attrs
|> Map.put(:feature_type_id, created_feature_type.id)
|> Features.create_feature_properties()
I get the following error:
** (ArgumentError) Postgrex expected a binary, got %{"name" => "PROGRESS_STATUS", "type" => "string"}. Please make sure the value you are passing matches the definition in
your table or in your query or convert the value accordingly.
Is this kind of operation possible, or do I have to create this schema using embeds?
Thanks