Ash.Api.create

You're seeing just the callback create, go back to Ash.Api module for more information.

Specs

create(Ash.Changeset.t(), params :: Keyword.t()) ::
  {:ok, Ash.Resource.record()} | {:error, term()}

Create a record.

  • :upsert? - If a conflict is found based on the primary key, the record is updated in the database (requires upsert support) The default value is false.

  • :upsert_identity - The identity to use when detecting conflicts for upsert?. By default, the primary key is used. Has no effect if upsert?: true is not provided

  • :verbose? - Log engine operations (very verbose!) The default value is false.

  • :action - The action to use, either an Action struct or the name of the action

  • :authorize? - If an actor option is provided (even if it is nil), authorization happens automatically. If not, this flag can be used to authorize with no user.

  • :stacktraces? - For Ash errors, wether or not each error has a stacktrace. See the error_handling guide for more. The default value is true.

  • :tenant - A tenant to set on the query or changeset

  • :actor - If an actor is provided, it will be used in conjunction with the authorizers of a resource to authorize access

  • :after_action - A hook to be run just before the action returns, but before fields are selected (still inside the same transaction, if your data layer supports transactions). This is mostly important if you want to load calculations after the action, which depend on having fields selected, but you want to authorize with the minimal set of fields that are actually being selected. Runs only if the action is successful, and is passed the changeset and result of the action. Should return {:ok, result} or {:error, error}.
    For example, if you had a full_name calculation, but were only selecting, first_name and full_name, you might do something like this:

    MyApp.User
    |> Ash.Changeset.for_create(:create, %{first_name: "first_name", last_name: "last_name"}
    |> Ash.Changeset.select(:first_name))
    |> Api.create(after_action: fn _changeset, user -> Api.load(user, :full_name))

    If you tried to load that :full_name calculation after receiving the data, the last_name would not be selected and as such would not be usable in the calculation, regardless of wether or not the calculation includes that field in its select list.

  • :return_notifications? - Use this if you're running ash actions in your own transaction and you want notifications to happen still.
    If a transaction is ongoing, and this is false, notifications will be discarded, otherwise the return value is {:ok, result, notifications} (or {:ok, notifications})
    To send notifications later, use Ash.Notifier.notify(notifications). It sends any notifications that can be sent, and returns the rest. The default value is false.