ecto_soft_delete icon indicating copy to clipboard operation
ecto_soft_delete copied to clipboard

[Feature] Restore function

Open Matsa59 opened this issue 4 years ago • 4 comments

It could be nice to have a function to restore a soft deleted entity.

something like the following code sample in the file https://github.com/revelrylabs/ecto_soft_delete/blob/master/lib/ecto/soft_delete_query.ex

  def restore(query) do
    update(query, [t], set: [deleted_at: nil])
  end

Matsa59 avatar Feb 05 '21 21:02 Matsa59

this wont work due to ecto casting nil to utc_datetime_usec raw query is required, fixed in pr #143

mithereal avatar Nov 19 '23 18:11 mithereal

We have a functino restore/1 that works nicely

  def restore(struct) do
    struct
    |> Ecto.Changeset.change(%{deleted_at: nil})
    |> Repo.update()
  end

Matsa59 avatar Nov 21 '23 17:11 Matsa59

hmmm i dont see it in the repo nor in the hex.docs, however when i try to nil a datestamp by running restore() as specified above in postgres ecto casts it to now(), i believe this is the default behaviour of ecto for date/time types as i see many discussions about it.

mithereal avatar Nov 21 '23 19:11 mithereal

No I mean, we have added this function into our code ^^

I will continue this discussion your PR

Matsa59 avatar Nov 22 '23 02:11 Matsa59