1
1
defmodule Ecto.Changeset do
2
2
@ moduledoc ~S"""
3
3
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.
12
15
13
16
The remaining functions in this module, such as validations,
14
17
constraints, association handling, are about manipulating
@@ -18,14 +21,14 @@ defmodule Ecto.Changeset do
18
21
19
22
Changesets allow working with two kinds of data:
20
23
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
26
25
a form that needs to be type-converted and properly validated. This
27
26
use case is primarily covered by the `cast/4` function.
28
27
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
+
29
32
When working with external data, the data is typically provided
30
33
as maps with string keys (also known as parameters). On the other hand,
31
34
when working with internal data, you typically have maps of atom keys
@@ -147,8 +150,8 @@ defmodule Ecto.Changeset do
147
150
148
151
## Associations, embeds, and on replace
149
152
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:
152
155
153
156
* `cast_assoc/3` and `cast_embed/3` - those functions are used when
154
157
working with external data. In particular, they allow you to change
0 commit comments