Skip to content

Instantly share code, notes, and snippets.

@terakilobyte
Created January 8, 2016 23:31
Show Gist options
  • Save terakilobyte/cc170d6a489ad9d816a5 to your computer and use it in GitHub Desktop.
Save terakilobyte/cc170d6a489ad9d816a5 to your computer and use it in GitHub Desktop.
def validate_categories(%{model: %{categories: nil}} = changeset), do: add_error(changeset, :categories, "must have at least two categories")
def validate_categories(%{model: %{categories: categories}} = changeset) when map_size(categories) < 2 do
add_error(changeset, :categories, "must have at least two categories")
end
def validate_categories(changeset), do: changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment