Skip to content

Commit

Permalink
Fix documentation examples for casting empty values (#4550)
Browse files Browse the repository at this point in the history
  • Loading branch information
fly49 authored Nov 15, 2024
1 parent f489c96 commit 892dc85
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/ecto/changeset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -664,21 +664,21 @@ defmodule Ecto.Changeset do
# Using default
iex> params = %{title: "", topics: []}
iex> changeset = cast(post, params, [:title, :topics])
iex> changeset.params
iex> changeset = cast(%Post{}, params, [:title, :topics])
iex> changeset.changes
%{topics: []}
# Changing default
iex> params = %{title: "", topics: []}
iex> changeset = cast(post, params, [:topics], empty_values: [[], nil])
iex> changeset.params
iex> changeset = cast(%Post{}, params, [:title, :topics], empty_values: [[], nil])
iex> changeset.changes
%{title: ""}
# Augmenting default
iex> params = %{title: "", topics: []}
iex> changeset =
...> cast(post, params, [:topics], empty_values: [[], nil] ++ Ecto.Changeset.empty_values())
iex> changeset.params
...> cast(%Post{}, params, [:title, :topics], empty_values: [[], nil] ++ Ecto.Changeset.empty_values())
iex> changeset.changes
%{}
You can define a custom error message function.
Expand Down

0 comments on commit 892dc85

Please sign in to comment.