Skip to content

Instantly share code, notes, and snippets.

View romseguy's full-sized avatar

Romain Séguy romseguy

View GitHub Profile
# it also takes care of translating error messages with Gettext
defmodule ApiWeb.Middleware.ChangesetErrorFormatter do
import ApiWeb.ErrorHelpers
def call(%{errors: []} = res, _), do: res
def call(%{errors: errors} = res, _) do
formatted_errors = format_changeset_error(errors)
%{res | errors: formatted_errors}
end
@romseguy
romseguy / many.ex
Last active July 12, 2017 22:34
ecto question
# User can have many Place
# Place can have many User
# User has a role for a Place he belongs to
# 1) ecto schemas
schema "accounts_users" do
# fields
many_to_many :map_places, Place, join_through: UserPlace
end