Skip to content

Instantly share code, notes, and snippets.

@pikender
Last active Apr 11, 2016
Embed
What would you like to do?
Ecto Model Schema Extension
defmodule Nectar.ExtendProduct do
defmacro extensions do
quote do
field :special, :boolean, virtual: true
end
end
end
defmodule Nectar.Product do
import Nectar.ExtendProduct
schema do
extensions
end
## Add #special boolean to get casted
def changeset(model, params \\ :empty) do
model
|> cast(params, @required_fields, ~w(special))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment