I’m wondering if I understand the Ecto.insert :returning option. Here’s how I think it works when inserting a changeset (and possibly a schema struct - I haven’t checked):
- Regardless of
:returning, the input:datais returned, including virtual fields. - Regardless of
:returning, the primary key is always added to that result.
Is that right?
Here’s some code:
Enum.at(@changesets, 0)
|> Crit.Repo.insert(prefix: "demo", returning: false)
|> IO.inspect
The return value is this:
{:ok,
%Crit.Usables.ServiceGap{
__meta__: #Ecto.Schema.Metadata<:loaded, "demo", "service_gaps">,
end_date: nil,
gap: %Ecto.Datespan{
first: :unbound,
last: ~D[2012-12-12],
lower_inclusive: false,
upper_inclusive: false
},
id: 1236,
reason: "before animal was put in service",
start_date: ~D[2012-12-12],
timezone: nil
}}
This is the same result as happens with returning: true or returning: [:id].
(I picked a schema without timestamps, because it was the most convenient. I’m betting I could affect whether timestamps were returned with :returning. I’m nearly out of power. I’ll check if my understanding above is wrong.)






















