Defining the User Schema and Migration
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 ...
Get Programming Phoenix now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.