Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a nested form with an embedded schema
- Loading branch information
1 parent
bb47213
commit 2f50ad0
Showing
5 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Tutorial.Shop.Data do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
@primary_key false | ||
embedded_schema do | ||
field :size, :string | ||
field :color, :string | ||
end | ||
|
||
@doc false | ||
def changeset(option, attrs) do | ||
option | ||
|> cast(attrs, [:size, :color]) | ||
|> validate_required([]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
priv/repo/migrations/20210601082650_add_data_column_to_products.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule Tutorial.Repo.Migrations.AddDataColumnToProducts do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:shop_products) do | ||
add :data, :map, default: %{}, null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters