Skip to content

Commit 8dd97c3

Browse files
authored
Documentation tweaks for changesets and embedded schemas (#4582)
1 parent c2d5868 commit 8dd97c3

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

lib/ecto/changeset.ex

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
defmodule Ecto.Changeset do
22
@moduledoc ~S"""
33
Changesets allow filtering, casting, validation and
4-
definition of constraints when manipulating structs.
5-
6-
There is an example of working with changesets in the introductory
7-
documentation in the `Ecto` module. The functions `cast/4` and
8-
`change/2` are the usual entry points for creating changesets.
9-
The first one is used to cast and validate external parameters,
10-
such as parameters sent through a form, API, command line, etc.
11-
The second one is used to change data directly from your application.
4+
definition of constraints when manipulating structs, usually in
5+
preparation for inserting and updating entries into a database.
6+
7+
There is an example of
8+
[working with changesets](`Ecto#module-changesets`) in the
9+
introductory documentation in the `Ecto` module. In a nutshell, there
10+
are two main functions for creating a changeset. The `cast/4` function
11+
is used to receive external parameters from a form, API or command
12+
line, and convert them to the types defined in your `Ecto.Schema`.
13+
`change/2` is used to modify data directly from your application,
14+
assuming the data given is valid and matches the existing types.
1215
1316
The remaining functions in this module, such as validations,
1417
constraints, association handling, are about manipulating
@@ -18,14 +21,14 @@ defmodule Ecto.Changeset do
1821
1922
Changesets allow working with two kinds of data:
2023
21-
* internal to the application - for example programmatically generated,
22-
or coming from other subsystems. This use case is primarily covered
23-
by the `change/2` and `put_change/3` functions.
24-
25-
* external to the application - for example data provided by the user in
24+
* external to the application - for example user input from
2625
a form that needs to be type-converted and properly validated. This
2726
use case is primarily covered by the `cast/4` function.
2827
28+
* internal to the application - for example programmatically generated,
29+
or coming from other subsystems. This use case is primarily covered
30+
by the `change/2` and `put_change/3` functions.
31+
2932
When working with external data, the data is typically provided
3033
as maps with string keys (also known as parameters). On the other hand,
3134
when working with internal data, you typically have maps of atom keys
@@ -147,8 +150,8 @@ defmodule Ecto.Changeset do
147150
148151
## Associations, embeds, and on replace
149152
150-
Using changesets you can work with associations as well as with embedded
151-
structs. There are two primary APIs:
153+
Using changesets you can work with associations as well as with
154+
[embedded](embedded-schemas.html) structs. There are two primary APIs:
152155
153156
* `cast_assoc/3` and `cast_embed/3` - those functions are used when
154157
working with external data. In particular, they allow you to change

0 commit comments

Comments
 (0)