Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Restore function #121

Open
Matsa59 opened this issue Feb 5, 2021 · 4 comments
Open

[Feature] Restore function #121

Matsa59 opened this issue Feb 5, 2021 · 4 comments

Comments

@Matsa59
Copy link

Matsa59 commented Feb 5, 2021

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
@mithereal
Copy link

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

@Matsa59
Copy link
Author

Matsa59 commented Nov 21, 2023

We have a functino restore/1 that works nicely

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

@mithereal
Copy link

mithereal commented Nov 21, 2023

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.

@Matsa59
Copy link
Author

Matsa59 commented Nov 22, 2023

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

I will continue this discussion your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants