Every changeset is nested. So there is the changeset of the Product; you should access that nested changeset and call put_change I guess? (or directly update the :changes map)
Every changeset is nested into :changes of the parent changeset.
I don’t have strong skills with Ecto, just an idea:)
I’m curious. You mention " to be able to change the inserted_at of the product item?". If there are many accounts for users and many products for accounts, how to know which product is “the” product?
Hmm that seems like a different error I tried this and it worked:
defmodule Product do
use Ecto.Schema
schema "products" do
field(:inserted_at, :date)
end
end
defmodule Account do
use Ecto.Schema
schema "accounts" do
has_many(:products, Product)
end
end
defmodule User do
use Ecto.Schema
schema "user" do
has_many(:accounts, Account)
end
end
changes = %{
accounts: [
%{
products: [
%{inserted_at: ~D[2020-03-03]}
]
}
]
}
Ecto.Changeset.change(%User{id: "123"}, changes)
|> Ecto.Changeset.cast_assoc(:accounts,
with: fn account, changes ->
Ecto.Changeset.change(account, changes)
|> Ecto.Changeset.cast_assoc(:products,
with: fn product, changes ->
Ecto.Changeset.change(product, changes)
end
)
end
)