View Source Bonfire.Ecto.Acts.Delete (Bonfire v0.9.10-classic-beta.169)
Summary
Functions
Attempts to delete the given objects or struct from the repository.
Runs the delete act, marking the specified changeset or struct for deletion.
Functions
Attempts to delete the given objects or struct from the repository.
This function handles the deletion of objects, whether they are a list, a Needle.Pointer
, or a regular struct. It returns the number of objects deleted.
Parameters
objects
- The object(s) to be deleted, can be a list or a single struct.repo
- The repository module to use for deletion.
Examples
iex> objects = [%SomeStruct{id: 1}, %SomeStruct{id: 2}]
iex> repo = MyApp.Repo
iex> Bonfire.Ecto.Acts.Delete.maybe_delete(objects, repo)
{:ok, 2}
iex> object = %SomeStruct{id: 1}
iex> repo = MyApp.Repo
iex> Bonfire.Ecto.Acts.Delete.maybe_delete(object, repo)
{:ok, 1}
Runs the delete act, marking the specified changeset or struct for deletion.
This function marks an object for deletion based on the :on
key in the act options.
If associations are specified for deletion, they will be processed as well.
Parameters
epic
- The epic struct that contains the list of acts to be executed.act
- The current act being processed.
Examples
iex> epic = %Epic{assigns: %{some_key: %SomeStruct{}}, errors: []}
iex> act = %{options: %{on: :some_key}}
iex> Bonfire.Ecto.Acts.Delete.run(epic, act)
%Epic{assigns: %{some_key: %SomeStruct{}}, errors: []}
iex> epic = %Epic{assigns: %{some_key: %SomeStruct{}}, errors: ["error"]}
iex> act = %{options: %{on: :some_key}}
iex> Bonfire.Ecto.Acts.Delete.run(epic, act)
%Epic{assigns: %{some_key: %SomeStruct{}}, errors: ["error"]}