Skip to content

Instantly share code, notes, and snippets.

@pikender
Last active April 11, 2016 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pikender/f58b2208ae8951c7b13214bf320e8ec1 to your computer and use it in GitHub Desktop.
Save pikender/f58b2208ae8951c7b13214bf320e8ec1 to your computer and use it in GitHub Desktop.
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