Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/waffle_ecto/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Waffle.Ecto.Schema do
field :avatar, MyApp.Uploaders.AvatarUploader.Type
end

def changeset(user, params \\ :invalid) do
def changeset(user, params \\ %{}) do
user
|> cast(params, [:name])
|> cast_attachments(params, [:avatar])
Expand Down Expand Up @@ -69,20 +69,20 @@ defmodule Waffle.Ecto.Schema do
end
end)

waffle_params =
case params do
:invalid ->
:invalid

%{} ->
case params do
params when is_map(params) and map_size(params) > 0 ->
waffle_params =
params
|> convert_params_to_binary()
|> Map.take(allowed_param_keys)
|> check_and_apply_scope(scope, options)
|> Enum.into(%{})
end

Ecto.Changeset.cast(changeset_or_data, waffle_params, allowed)
Ecto.Changeset.cast(changeset_or_data, waffle_params, allowed)

_ ->
changeset_or_data
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule WaffleTest.Ecto.Schema do
%{__struct__: Plug.Upload, path: path, filename: Path.basename(path)}
end

test "supports :invalid changeset" do
test "supports invalid empty changeset" do
cs = TestUser.changeset(%TestUser{})
assert cs.valid? == false
assert cs.changes == %{}
Expand Down
Loading