Skip to Main Content
Programming Phoenix
book

Programming Phoenix

by Chris McCord, Bruce Tate, Jose Valim
April 2016
Beginner to intermediate content levelBeginner to intermediate
300 pages
6h 58m
English
Pragmatic Bookshelf
Content preview from Programming Phoenix

Adding Categories

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.

Generating Category Migrations

Next let’s edit our migration to mark the name field as ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Elm

Programming Elm

Jeremy Fairbank
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781680501926Errata Page