Phoenix 1.3 contexts & relationships

I had a quick question about the new contextual/boundary approach being suggested. I’m starting a new project and I’m going to approach it using this approach. I do have one question regarding relationships between boundaries.

Here is a quick abstract of my app boundaries:

  • Accounts

    • Customers
    • Users
  • Media

    • Images
    • Videos

A media image and media video is created by a user, so it belongs to a user through the user_id foreign key. To help separate boundaries is the suggested method to obtain the “owner” of a video to do something like the following, instead of using Ecto belongs_to?

# Just simple example code.
defmodule MyApp.Media do
  def owner_of_media(media_item) do
    Accounts.get_user!(media_item.user_id)
  end
end

I would appreciate any feedback.

I was able to consult with @chrismccord on slack, and I’m on the right path.

For posterity, this is what I suggested on slack:

Maybe ContentTracker?:

ContentTracker.add_comment(user, post, body)

ContentTracker.add_vote(user, post)

ContentTracker.inc_views(post)

ContentTracker.most_viewed(Post, :today)
2 Likes