Persisting Annotations

Now that we have in-memory annotations going across all connected clients through an authenticated user, let’s extend our multimedia context to attach those annotations to videos and users in the database. You’ve seen how we manage schemas and relationships with Ecto so the process will be straightforward. 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 phx.gen.schema generator, like this:

 $ ​​mix​​ ​​phx.gen.schema​​ ​​Multimedia.Annotation​​ ​​annotations​​ ​​body:text​​ ​​\
 at:integer​​ ​​user_id:references:users​​ ​​video_id:references:videos
 
 * creating lib/rumbl/multimedia/annotation.ex
 * creating priv/repo/migrations/20180726203443_create_annotations.exs ...

Get Programming Phoenix 1.4 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.