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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.