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

Persisting Annotations

Now that we have in-memory annotations going across all connected clients through an authenticated user, let’s create an Annotation model. You’ve seen how we manage models and relationships with Ecto. In this case, we’re creating annotations on videos. Each new annotation will belong to both a user and a video.

You can use the phoenix.gen.model generator, like this:

 $ ​​mix​​ ​​phoenix.gen.model​​ ​​Annotation​​ ​​annotations​​ ​​body:text​​ ​​at:integer​​ ​​\
 user_id:references:users​​ ​​video_id:references:videos
 
 * creating priv/repo/migrations/20150921162814_create_annotation.exs
 * creating web/models/annotation.ex
 * creating test/models/annotation_test.exs
 
 $

And now you can migrate our database:

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