Updated source's friendly_name to default to the collection_name (#29)
This commit is contained in:
1 parent
1ec1a48235
commit
01042ebd1b
9 files changed
+101
-3
No files matched your search
@@ -0,0 +1,19 @@
|
||||
defmodule Pinchflat.Utils.ChangesetUtils do
|
||||
@moduledoc """
|
||||
Utility methods for working with changesets
|
||||
"""
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
@doc """
|
||||
Sets the default value of a field if it is nil by applying the given function.
|
||||
|
||||
Returns %Ecto.Changeset{}.
|
||||
"""
|
||||
def dynamic_default(changeset, key, value_fn) do
|
||||
case get_field(changeset, key) do
|
||||
nil -> put_change(changeset, key, value_fn.(changeset))
|
||||
_ -> changeset
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user