Skip to Main Content
Mastering Elixir
book

Mastering Elixir

by André Albuquerque, Daniel Caixinha
July 2018
Intermediate to advanced content levelIntermediate to advanced
574 pages
14h 7m
English
Packt Publishing
Content preview from Mastering Elixir

Media ownership

In the previous Media section, we simply inserted a new Media entry when we saved the media file for our users with the Storage.store/3 function. However, this was only a partial solution, since we have a many-to-many relationship between the Media and Owner schemas.

Our goal here is to create a new MediaOwners schema entry when we store a file for the first time with the Storage.store/3 function, effectively associating the user with the uploaded media:

$ cat apps/elixir_drip/lib/elixir_drip/storage/storage.exdefmodule ElixirDrip.Storage do  # ...  def store(user_id, file_name, full_path, content) do    file_size = byte_size(content)    with %Owner{} = owner <- get_owner(user_id), %Changeset{} = changeset <- Media.create_initial_changeset ...
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

Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781788472678Supplemental Content