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 ...