Skip to content

Commit

Permalink
Revert "Allow apply_changes/1 to use nested schemaless changesets f…
Browse files Browse the repository at this point in the history
…or `:map` type (#4516)"

This reverts commit a180048.

Closes #4520.
  • Loading branch information
josevalim committed Oct 6, 2024
1 parent a180048 commit 407912c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 23 deletions.
6 changes: 0 additions & 6 deletions lib/ecto/changeset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2190,9 +2190,6 @@ defmodule Ecto.Changeset do
regardless if the changeset is valid or not. See `apply_action/2`
for a similar function that ensures the changeset is valid.
If a field of type `:map` contains a schemaless changeset,
its changes too will be applied and returned as a map with atom keys.
## Examples
iex> changeset = change(%Post{author: "bar"}, %{title: "foo"})
Expand All @@ -2211,9 +2208,6 @@ defmodule Ecto.Changeset do
{:ok, {tag, relation}} when tag in @relations ->
apply_relation_changes(acc, key, relation, value)

{:ok, :map} when is_struct(value, Changeset) ->
Map.put(acc, key, apply_changes(value))

{:ok, _} ->
Map.put(acc, key, value)

Expand Down
17 changes: 0 additions & 17 deletions test/ecto/changeset_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,23 +1073,6 @@ defmodule Ecto.ChangesetTest do
assert changed_post.category == nil
end

test "apply_changes/1 with nested schemaless validation" do
params = %{"seo_metadata" => %{"keywords" => ["foo", "bar"], "slug" => "my-post-1"}}

changeset =
%Post{}
|> changeset(params)
|> update_change(:seo_metadata, fn seo_metadata ->
{%{}, %{keywords: {:array, :string}, slug: :string}}
|> cast(seo_metadata || %{}, [:keywords, :slug])
|> validate_required([:keywords, :slug])
end)

changed_post = apply_changes(changeset)

assert changed_post.seo_metadata == %{keywords: ["foo", "bar"], slug: "my-post-1"}
end

describe "apply_action/2" do
test "valid changeset" do
post = %Post{}
Expand Down

0 comments on commit 407912c

Please sign in to comment.