Ecto Changesets: Difference between revisions
From ElixirBlocks
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 5: | Line 5: | ||
Ecto.Repo.insert/2, update/2 and delete/2 require a changeset as their first parameter. | Ecto.Repo.insert/2, update/2 and delete/2 require a changeset as their first parameter. | ||
The creating, updating or deleting of table data always requires a changeset. | The creating, updating or deleting of table data always requires a changeset. | ||
Changesets can be created using the data from a table schema. | |||
==Using Ecto.Changeset.cast == | |||
Ecto.Changeset.cast(%Friends.Person{name: "Bob"}, %{"name" => "Jack"}, [:name, :age]) | |||
The previous code takes three arguments. | |||
* The Schema | |||
* the change you want to make to the data | |||
* The names of the fields that you are allowed to change (as a list of atoms) | |||
* | |||
==Using Ecto.Changeset.change == |
Latest revision as of 20:38, 8 October 2023
This page is in progress
Ecto.Repo.insert/2, update/2 and delete/2 require a changeset as their first parameter. The creating, updating or deleting of table data always requires a changeset.
Changesets can be created using the data from a table schema.
Using Ecto.Changeset.cast
Ecto.Changeset.cast(%Friends.Person{name: "Bob"}, %{"name" => "Jack"}, [:name, :age])
The previous code takes three arguments.
- The Schema
- the change you want to make to the data
- The names of the fields that you are allowed to change (as a list of atoms)