Created
February 11, 2016 22:19
-
-
Save paulcsmith/e87f1c17e8f73f411d3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Changeset do | |
def cast(model_or_changeset, :empty, required, optional) do | |
Ecto.Changeset.cast(model_or_changeset, :empty, required, optional) | |
end | |
def cast(model_or_changeset, params, required, optional) do | |
param_keys = params |> Map.keys |> Enum.map(&to_string/1) | |
allowed_params = (required ++ optional) |> Enum.map(&to_string/1) | |
disallowed_params = param_keys -- allowed_params | |
if length(disallowed_params) > 0 do | |
Logger.debug """ | |
Some params were removed from the changeset. | |
Given params: #{inspect param_keys} | |
Allowed params: #{inspect allowed_params} | |
Disallowed params: #{inspect disallowed_params} | |
""" | |
end | |
Ecto.Changeset.cast(model_or_changeset, params, required, optional) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment