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â|
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.