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:

Get Programming Phoenix now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.