O'Reilly logo

Programming Phoenix by Jose Valim, Bruce Tate, Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required