Trash.Repo.discard-exclamation-mark
You're seeing just the function
discard-exclamation-mark
, go back to Trash.Repo module for more information.
Link to this function
discard!(changeset, repo)
Specs
discard!( changeset_or_schema :: Ecto.Changeset.t() | Ecto.Schema.t(), repo :: atom() ) :: Ecto.Schema.t()
Updates a record as discarded.
This takes either an Ecto.Changeset
or an Ecto.Schema
struct. If a struct
is given a bare changeset is generated first.
A change is added to the changeset to set discarded_at
to
DateTime.utc_now/1
. It calls repo.update/2
to finalize the changes.
Raises Ecto.InvalidChangesetError
if the changeset is invalid.
Note: since an Ecto.Schema
struct can be passed which generates a bare
changeset, this will never raise when given a struct.
Examples
iex> Post.changeset(post, %{title: "[Archived] Hello, world"})
|> Trash.Repo.discard!(MyApp.Repo)
%Post{title: "[Archived] Hello, world", discarded_at: %DateTime{}}
iex> Post.changeset(post, %{}) |> Trash.Repo.discard!(MyApp.Repo)
** (Ecto.InvalidChangesetError)