embeds_many :items, Item, on_replace: :delete do
@derive Jason.Encoder
field :name, :string
field :image, :string
field :variant_id, :string
field :quantity, :integer
field :price, :decimal
end
Unfortunately, the hidden field generated by inputs_for is the following, which includes “_persistent_id” and not “id”:
The schema for the parent and child items is the following (both are not persisted to the db)
defmodule Pdex.DraftOrderCreationForm do
import Ecto.Changeset
use Ecto.Schema
@primary_key false
embedded_schema do
field :order_id, :string
field :customer_id, :string
embeds_many :items, Item, on_replace: :delete do
@derive Jason.Encoder
field :name, :string
field :image, :string
field :variant_id, :string
field :quantity, :integer
field :price, :decimal
end
end
Shouldn’t the fact that an id is present be enough to render it in the markup ? Or should the id be both present AND the resource a persisted one ?
is there a way to have inputs_for use a different unique field from the schema rather than the primary key? In addition to the default primary key, I have a uuid in my schema, which is also a unique index for that table. I would like to use this uuid field rather than the id to avoid leaking information about the number of rows in the database.