Waffle.Ecto.Schema (waffle_ecto v0.0.12)

Defines helpers to work with changeset.

Add a using statement use Waffle.Ecto.Schema to the top of your ecto schema, and specify the type of the column in your schema as MyApp.Avatar.Type.

Attachments can subsequently be passed to Waffle's storage though a Changeset cast_attachments/3 function, following the syntax of cast/3.

example

Example

defmodule MyApp.User do
  use MyApp.Web, :model
  use Waffle.Ecto.Schema

  schema "users" do
    field :name,   :string
    field :avatar, MyApp.Uploaders.AvatarUploader.Type
  end

  def changeset(user, params \\ :invalid) do
    user
    |> cast(params, [:name])
    |> cast_attachments(params, [:avatar])
    |> validate_required([:name, :avatar])
  end
end

Link to this section Summary

Link to this section Functions

Link to this macro

cast_attachments(changeset_or_data, params, allowed, options \\ [])

(macro)

Extracts attachments from params and converts it to the accepted format.

options

Options

  • :allow_urls — fetches remote file if the string matches ~r/^https?:\/\//
  • :allow_paths — accepts any local path as file destination

examples

Examples

cast_attachments(changeset, params, [:fetched_remote_file], allow_urls: true)
Link to this function

check_and_apply_scope(params, scope, options)

Link to this function

convert_params_to_binary(params)

Link to this function

do_apply_changes(changeset)