April 2016
Beginner to intermediate
300 pages
6h 58m
English
Ecto has a DSL that specifies the fields in a struct and the mapping between those fields and the database tables. Let’s use that now. To define our schema, replace the contents in web/models/user.ex with the following:
| | defmodule Rumbl.User do |
| | use Rumbl.Web, :model |
| | |
| | schema "users" do |
| | field :name, :string |
| | field :username, :string |
| | field :password, :string, virtual: true |
| | field :password_hash, :string |
| | |
| | timestamps |
| | end |
| | end |
This DSL is built with Elixir macros. The schema and field macros let us specify both the underlying database table and the Elixir struct. Each field corresponds to both a field in the database and ...