Executes bulk actions on selected records.
This module is used internally by Cinder.LiveComponent to execute bulk actions
defined in bulk_action slots. It handles both Ash action atoms and function
captures.
Atom Actions
When given an atom, introspects the resource to determine if it's an update or
destroy action, then calls Ash.bulk_update/4 or Ash.bulk_destroy/4:
BulkActionExecutor.execute(:archive,
resource: MyApp.User,
ids: ["1", "2"],
actor: current_user
)Function Actions
When given a function, calls it with (query, opts) matching the signature of
Ash code interface functions. The query is pre-filtered to the selected IDs:
BulkActionExecutor.execute(&MyApp.Users.archive/2,
resource: MyApp.User,
ids: ["1", "2"],
actor: current_user
)Options Handling
- Atom actions:
action_optsare merged directly into Ash options - Function actions:
action_optsare wrapped inbulk_options: [...]for code interface compatibility
Summary
Functions
Builds an Ash.Query filtered to the given IDs.
Executes a bulk action on the given IDs.
Normalizes a bulk action result to {:ok, result} or {:error, reason}.
Types
@type action() :: atom() | (Ash.Query.t(), keyword() -> any())
Functions
@spec build_query(Ash.Resource.t(), [String.t()], atom()) :: Ash.Query.t()
Builds an Ash.Query filtered to the given IDs.
Executes a bulk action on the given IDs.
Options
:resource- The Ash resource (required):ids- List of record IDs to act on (required):id_field- The field to filter on (default::id):actor- Actor for authorization:tenant- Tenant for multi-tenancy:action_opts- Additional options for the action (e.g.,[return_records?: true])
Action Types
- Atom: Introspects the resource to determine the action type. Calls
Ash.bulk_update/4for update actions orAsh.bulk_destroy/4for destroy actions. Action opts are merged directly into the Ash options. - Function/2: Calls the function with
(query, opts)where query is filtered to the selected IDs. Action opts are wrapped inbulk_options: [...]for code interface compatibility.
Examples
# Atom action - uses Ash.bulk_update
execute(:archive, resource: MyApp.User, ids: ["1", "2"], actor: current_user)
# With action options
execute(:archive, resource: MyApp.User, ids: ["1", "2"], action_opts: [return_records?: true])
# Function - receives filtered query
execute(&MyApp.Users.archive/2, resource: MyApp.User, ids: ["1", "2"])
# Destroy action
execute(:destroy, resource: MyApp.User, ids: ["1", "2"])
Normalizes a bulk action result to {:ok, result} or {:error, reason}.