Is there a way to figure out if struct is persisted or not? I started digging source for Ecto's insert_or_update
but with no luck as it hits some private method. I want to accoplish something like this:
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:whatever]
|> do_a_thing_on_unsaved_struct
end
defp do_a_thing_on_unsaved_struct(struct) do
case ARE_YOU_PERSISTED?(struct) do
:yes -> struct
:no -> do_things(struct)
end
end
Is it possible, or I'm doing something dumb?
Ecto.get_meta(struct, :state)
. My tests are getting tripped up on something, but it's probably my factories. – Claque