Hello geeks, I’m still a newbie so my code could be not that good and my question could seem trivial, so I really appreciate your help.
I have a question. I have and embedded schema for playerErrors
inside the main schema log
using embeds_many :playerErrors, PlayerError
in log.ex and in the migration file I wrote this add :playerErrors, {:array, :jsonb}, default: []
.
And in the log changeset I wrote this
|> cast_embed(:playerErrors)
|> put_embed(:playerErrors, attrs[:playerErros])
This how the playerErrors looks like:
[
%{_id: "5dfed5631d12bf790c61465f", errorCount: 0, errorType: "DET_NOUN"},
%{_id: "5dfed5631d12bf790c61465e", errorCount: 0, errorType: "FIRST"},
%{_id: "5dfed5631d12bf790c61465d", errorCount: 0, errorType: "ADP_NOUN"},
%{_id: "5dfed5631d12bf790c61465c", errorCount: 0, errorType: "ADJ_NOUN"},
%{_id: "5dfed5631d12bf790c61465b", errorCount: 0, errorType: "ADV_VERB_NOUN"}
]
But whenever I attempt to create a log I get this changeset error:
{:error,
#Ecto.Changeset<
action: :insert,
changes: %{
playerErrors: [
#Ecto.Changeset<
action: :insert,
changes: %{errorCount: 0, errorType: "DET_NOUN"},
errors: [],
data: #Lean.GameLogs.PlayerError<>,
valid?: true
>,
#Ecto.Changeset<
action: :insert,
changes: %{errorCount: 0, errorType: "FIRST"},
errors: [],
data: #Lean.GameLogs.PlayerError<>,
valid?: true
>,
#Ecto.Changeset<
action: :insert,
changes: %{errorCount: 0, errorType: "ADP_NOUN"},
changes: %{errorCount: 0, errorType: "ADJ_NOUN"},
errors: [],
data: #Lean.GameLogs.PlayerError<>,
valid?: true
>,
#Ecto.Changeset<
action: :insert,
changes: %{errorCount: 0, errorType: "ADV_VERB_NOUN"},
errors: [],
data: #Lean.GameLogs.PlayerError<>,
valid?: true
>
],
},
errors: [
playerErrors: {"is invalid", [type: {:array, :map}]}
],
data: #Lean.GameLogs.Log<>,
valid?: false
>}
Can someone please help me?
Thanks in advance.