Assoc v0.1.1 Assoc.Updater 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 / updatedThe 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.
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
Link to this section Functions
Link to this function
update_associations(repo, parent, params) View Source
Create and update associated records.