API Reference Assoc v0.2.2

Modules

Usage

defmodule MyApp.User do
  use MyApp.Schema
  use Assoc.Schema, repo: MyApp.Repo

  schema "users" do
    field :email, :string
    field :name, :string
    has_many :user_roles, MyApp.UserRole, on_delete: :delete_all, on_replace: :delete
    timestamps()
  end

  def updatable_associations, do: [
    user_roles: MyApp.UserRole
  ]

  def changeset(struct, params \ %{}) do
    struct
    |> cast(params, [:email, :name])
    |> validate_required([:email])
  end
end

Key points

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

Collection of utility functions