April 2016
Beginner to intermediate
300 pages
6h 58m
English
In this section, we’re going to add some categories. We’ll use many of the same techniques we discovered in our user-to-video relationship to manage the relationships between videos and categories. A video optionally belongs to a category, one chosen by the end user. First, let’s generate the model and migration, using phoenix.gen.model, like this:
| | $ mix phoenix.gen.model Category categories name:string |
| | |
| | * creating priv/repo/migrations/20150829145417_create_category.exs |
| | * creating web/models/category.ex |
| | * creating test/models/category_test.exs |
This generator will build the model with a schema and migration for us.
Next let’s edit our migration to mark the name field as ...