Assoc.Updater (Assoc v0.2.3) View Source
Usage
Within a Module
defmodule MyApp.CreateUser do
use Assoc.Updater, repo: MyApp.Repo
def call(params) do
%User{}
|> User.changeset(params)
|> Repo.insert
|> update_associations(params)
end
end
Key points:
- Include
use Assoc.Updater
at the top of the module - Add
update_associations
after the record is created / updated- The first argument is the parent struct. It can take the struct on its own, or in a tuple:
%User{}
{:ok, %User{}}
- Any other values are returned without raising an exception
- The second argument is the params.
- The first argument is the parent struct. It can take the struct on its own, or in a tuple:
Direct Function Call
Assoc.Updater.update_associations(MyApp.Repo, user, params)
Key points:
- The first argument is the Repo module to use for database interactions.
- The second argument is the parent struct. It can take the struct on its own, or in a tuple:
- The third argument is the params.
Link to this section Summary
Functions
Create and update associated records.