April 2019
Beginner to intermediate
244 pages
6h 34m
English
Now let’s tackle a more complex case: creating a form with associations. To make it even more interesting, we’ll use an embedded schema representing the user’s address. If you need to refresh your memory on schemas, associations or embeds, you might want to flip back to Chapter 3, Connecting Your Tables to Elixir Structs with Schemas before proceeding.
First, create an embedded schema for the user’s address, along with a changeset function:
| | defmodule MyApp.Address do |
| | import Ecto.Changeset |
| | use Ecto.Schema |
| | |
| | embedded_schema do |
| | field :street, :string |
| | field :city, :string |
| | end |
| | |
| | def changeset(address, ... |
Read now
Unlock full access