<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="28496" data-post-id="28496">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="gmile" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gmile/120/33982_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  gmile
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Contexts had me confused as well, I still don’t understand them fully. I’ve settled on something simple that works for our application and is good enough.</p>
<p>When starting new application, I needed a simple CRUD for users. To jump-start, I used:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">mix phx.gen.json UserAPI User users email:string password:string scopes:array:string
</code></pre>
<p>Among other things, I got this folder with two files:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">lib/my_app/user_api/user_api.ex
lib/my_app/user_api/user.ex
</code></pre>
<p>I found that having context with a name <code>UserAPI</code> is an absolutely amazing starting point, because:</p>
<ol>
<li>File <code>user_api.ex</code> is now <strong>my dump pipe</strong> for all <code>user</code>-related code,</li>
<li>schema file <code>user.ex</code> remains clean and un-touched,</li>
<li>I use the <code>user_api.ex</code> dump pipe until I figure out some of the code is good to go into a module of it’s own,</li>
<li>As soon as I figure out something needs to be extracted, I created a file nested under <code>user_api</code>; recently I added a file called <code>user_api/search.ex</code> that incorporates validating search params &amp; building complex search queries for my users,</li>
<li>My <code>user_api.ex</code> is now a glue between repo &amp; user_schema and the rest of the app: by our convention no module should be calling functions from <code>MyApp.Repo</code>/<code>user_schema</code> directly.</li>
</ol>
<p>This maybe be very dumb and simple, but it works perfectly for us.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="28496" data-batch-url="/posts/batch_likers">
                        6
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-determine-contexts-with-phoenix-1-3/4367/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-28496" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="28496"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #31"></div>
  </section>
</div>
    <div class="postbit" id="28499" data-post-id="28499">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="karmajunkie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/karmajunkie/120/1076_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  karmajunkie
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="aeons" data-post="31" data-topic="4367">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/aeons/48/3734_2.png" class="avatar"> aeons:</div>
<blockquote>
<p>How do you specifically handle other data that references the user?</p>
</blockquote>
</aside>
<p>The answer anytime you start talking about how to design software in general (and with DDD in particular) is always <em>it depends</em>, which is terrifically unsatisfying but also true.  Its really going to depend on your features and domain, but there’s background to that question worth considering. We often talk about software that exhibits loose coupling—different parts that are only loosely related can change relative to each other with effort that is roughly proportional to the degree of coupling between those two parts.  Its pretty easy to see that if you embed a lot of references to something like a user schema in all parts of your data schema, if you need to make radical changes in something like authorization (say, you start supporting an OAuth signup flow that does not collect email) then all the parts of your software that depended on a User schema looking a certain way are suddenly going to have to adapt.</p>
<p>Something we hear about less often is the idea of <em>cohesion</em>, that all the parts that touch each other belong together, and conversely, that parts that <em>don’t</em> have overlapping or complementary responsibilities are not bound together.  Imagine that you’re building an application for a warehouse, working on an inventory tracking system that is intended to keep track of stock levels and reorder new stock when it gets low. Is it relevant to that system that a pallet was delivered by UPS instead of FedEx or a custom shipping company? (Again, the answer is <em>it depends</em>, but lets say for our purposes its not.)  The UI in the final application should be able to show, for any given stock item, the details of its arrival in stock.  Now, should the stock on that pallet be noted with an association to a particular delivery service?</p>
<p>If you’re building a monolith, majestic or otherwise, you may well be inclined to say yes. In doing so, however, you’re stepping outside the lines of your module with concerns that are not relevant, and in doing so reducing cohesion and creating tight coupling between that module and another (in this case, we’ll say its the shipping module’s responsibility to know that information).  Shipping may need to know the skus and how many of each kind of item are on an incoming pallet, but it doesn’t need to know where its stored in the warehouse.  So in each case, it may be worth decorating the item with metadata (for example, a user id, or a pallet source id) but if you’re aiming for really high cohesion, you almost certainly don’t want to extend the metadata beyond that and encourage consumption of data from outside your boundary.</p>
<p>And as has been noted before, what’s really being discussed here are a set of conventions that the Phoenix team is encouraging through the use of generated code. <em>You can do all of this without the generators.</em> <em><strong>You can also skip all of this by not using generators.</strong></em>  Elixir doesn’t care what you call your modules. It doesn’t care where you put them as long as they’re compiled. Wherever you are in your app cycle, just put a stake in the ground and start moving from there. You can develop new features using the pattern the Phoenix team encourages. Move your old one over time. Or jump in with both feet, or not at all. One of the great things about convention over configuration in Phoenix as opposed to Rails and its ilk is that where Rails makes it very painful to fight conventions a lot of the time, Elixir and Phoenix reduce that friction a great deal.</p>
<p>/end_soapbox</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="28499" data-batch-url="/posts/batch_likers">
                        8
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-determine-contexts-with-phoenix-1-3/4367/33">Post #32</a>
	                </div>
	            </div>
              <div id="likers-container-28499" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="28499"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #32"></div>
  </section>
</div>
    <div class="postbit" id="28508" data-post-id="28508">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sync08" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sync08
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I really appreciate you joining in this thread, Chris. I feel as though my earlier reply comes across as way more negative than I hoped and I actually feel terrible for the way I worded it.</p>
<p>I do still think the whole context idea is causing some issues in the community though. Not because it’s a bad idea (the intentions are very admirable) but because there is still no agreement on best practices. We all know we should structure our code better and need to do so using proven best practices. Well named modules and functions is something we can all agree on.</p>
<p>I think the DDD terminology is hurting more than helping. I’ve been reading a lot about it over the last few months but I don’t buy into the idea as it’s not a solution to any of my problems. It just doesn’t feel like it’s suitable at all for web apps.There is also literally zero consensus on the subject. This is a personal thing so feel free to ignore this.</p>
<p>Thinking of contexts as a place to store modules and functions helps understand them but I don’t think adding artificial boundaries between them makes sense. I’m not going to create two tables for “blog_user” and “shop_user” and try to keep them in sync. I’m going to have a single user that is fully aware that they have both blog posts and shop items. That means a user schema (in an account context) will have relationships to other contexts’ schemas. I’m hoping Jose can chime in with his reasoning why this is a bad idea.</p>
<p>I’ve been using <a href="http://asp.net" rel="noopener nofollow ugc">asp.net</a> core for the last year and have actually come to really like the structure. I have a main models directory (I’m not even going to get started with the aversion to models <img src="https://forum.elixirforum.com/images/emoji/apple/stuck_out_tongue_closed_eyes.png?v=15" title=":stuck_out_tongue_closed_eyes:" class="emoji" alt=":stuck_out_tongue_closed_eyes:" loading="lazy" width="20" height="20">) with all of my core domain models in one place. So things like “user”, “blog”, “post”, “comments”, “department” and “business”. I then structure everything into areas so the “blog” area will have it’s own controllers, views, view models and services so it is its own mini app. The key to this is the view models which are representations of the actual domain models which can have their own validations, fields e.t.c. but are cast to domain model before going to the database. So like Ecto schema and changesets.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="28508" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-determine-contexts-with-phoenix-1-3/4367/34">Post #33</a>
	                </div>
	            </div>
              <div id="likers-container-28508" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="28508"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #33"></div>
  </section>
</div>
    <div class="postbit" id="28532" data-post-id="28532">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="sync08" data-post="34" data-topic="4367">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/ed655f/48.png" class="avatar"> sync08:</div>
<blockquote>
<p>I’ve been reading a lot about it over the last few months but I don’t buy into the idea as it’s not a solution to any of my problems. It just doesn’t feel like it’s suitable at all for web apps.</p>
</blockquote>
</aside>
<p>If it doesn’t solve any of your problems then so be it. Nobody is keeping you from putting all your domain logic in  a single place. If your domain is small enough it might work out without problems. I think the bigger “improvement” for phoenix 1.2 → 1.3 is pushing people to not have domain logic in the web controllers, which is the far worse thing to do. Contexts are (at least to me) rather a hint to people, where the journey can go as soon as things start to grow and one is feeling the issues with having to handle all sorts of different concerns in a single place.</p>
<p>Probably the real hard thing here is just that it’s difficult to cater to people of all sorts of skill levels / all sorts of project scopes with just a single kind of generators. The 1.2 generators were the quick&amp;dirty jump-starters, the 1.3 are the opposite direction, where you’re supposed to think a bit about your application before you do run into the problems of outgrowing quick&amp;dirty.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="28532" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-determine-contexts-with-phoenix-1-3/4367/35">Post #34</a>
	                </div>
	            </div>
              <div id="likers-container-28532" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="28532"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #34"></div>
  </section>
</div>
    <div class="postbit" id="28543" data-post-id="28543">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="aeons" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/aeons/120/3734_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  aeons
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks for the thorough answer.</p>
<p>I guess my conclusion will be that my app currently is small and simple enough that everything can live in the same context.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="28543" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-determine-contexts-with-phoenix-1-3/4367/36">Post #35</a>
	                </div>
	            </div>
              <div id="likers-container-28543" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="28543"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #35"></div>
  </section>
</div>
    <div class="postbit" id="28562" data-post-id="28562">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="sync08" data-post="34" data-topic="4367">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/ed655f/48.png" class="avatar"> sync08:</div>
<blockquote>
<p>I think the DDD terminology is hurting more than helping.</p>
</blockquote>
</aside>
<p><strong>It is not a DDD terminology</strong>. Chris mentioned it during one slide, in one talk, to provide some <em>reference</em> for folks familiar with DDD. A context is a module and functions, that’s it. Don’t bring more to it than it is.</p>
<aside class="quote no-group" data-username="sync08" data-post="34" data-topic="4367">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/ed655f/48.png" class="avatar"> sync08:</div>
<blockquote>
<p>Thinking of contexts as a place to store modules and functions helps understand them but I don’t think adding artificial boundaries between them makes sense. I’m not going to create two tables for “blog_user” and “shop_user” and try to keep them in sync. I’m going to have a single user that is fully aware that they have both blog posts and shop items. That means a user schema (in an account context) will have relationships to other contexts’ schemas. I’m hoping Jose can chime in with his reasoning why this is a bad idea.</p>
</blockquote>
</aside>
<p>As I mentioned on another thread, if people take whatever pattern or restriction and follow it blindly, <strong>this change is for nothing</strong>, because it will likely end-up on another dead end. If you want to have cross-context relationships, think about pros and cons carefully and move forward. Different teams will balance trade-offs differently.</p>
<p>At the same time you say there is no agreement on best practices, you took a “best practice” comment and disagreed with it. <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"> That’s the point. Best practices are guidelines. They are very important for new teams and we will provide more of them to those teams as we go but experienced teams should re-evaluate them when necessary.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="28562" data-batch-url="/posts/batch_likers">
                        5
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-determine-contexts-with-phoenix-1-3/4367/37">Post #36</a>
	                </div>
	            </div>
              <div id="likers-container-28562" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="28562"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #36"></div>
  </section>
</div>
    <div class="postbit" id="28564" data-post-id="28564">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="sync08" data-post="15" data-topic="4367">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/ed655f/48.png" class="avatar"> sync08:</div>
<blockquote>
<p>The more I read about contexts the more I think it’s a bad idea.There seems to be a big push for “Phoenix is not your application” which, as far as I can tell, is nonsense. It’s a very big anti-rails movement.</p>
<p>Phoenix is your application. It’s a framework that serves as the foundation which you build on top of.</p>
</blockquote>
</aside>
<p>One more comment on this.</p>
<p>First of all, Elixir is not Ruby and Phoenix is not Rails. Ruby, opposite to Elixir, does not provide any mechanism for structuring your projects. Most of the standards you see today in Ruby came from the community.</p>
<p>In Elixir, we do have such structure. Elixir itself has the concept of applications and how code is structured. Those are pushed as part of the language and its tooling.</p>
<p>When we say Phoenix is not your application, it is not some anti-Rails instance. So don’t make it so. It is literally how writing projects work in Elixir (and Erlang/OTP). We had technical reasons for generating the “web” directory in previous versions but those have been solved, so Phoenix projects should follow the standards in the community instead of fragmenting it.</p>
<p>The way we are advocating Phoenix applications to be structured is exactly how community projects such as Elixir itself, Phoenix and Ecto are structured. In Ecto, we have “contexts”, such as <code>Ecto.Repo</code>, with private modules inside, such as <code>Ecto.Repo.Supervisor</code>. Only <code>Ecto.Repo</code> is allowed to talk to <code>Ecto.Repo.Supervisor</code>. Sometimes we do violate this rule by making an inner module public but that’s exactly the point: building a project with Phoenix should be no different from building any other Elixir app.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="28564" data-batch-url="/posts/batch_likers">
                        11
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-determine-contexts-with-phoenix-1-3/4367/38">Post #37</a>
	                </div>
	            </div>
              <div id="likers-container-28564" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="28564"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="28572" data-post-id="28572">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="pra" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  pra
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="37" data-topic="4367">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>If you want to have cross-context relationships, think about pros and cons carefully and move forward</p>
</blockquote>
</aside>
<p>But there would always some cross-context relationships. Like say we have auth, registration, orders context. Registration would create a User, which would be used by Auth and Orders would be associated with Users. Do we create User schema in each of the context, have a main schema say in Auth and associate it with others? I assume it would need to be a single table. I am trying to understand these kind of relationships wrt contexts. Some simple examples would be very useful.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="28572" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-determine-contexts-with-phoenix-1-3/4367/39">Post #38</a>
	                </div>
	            </div>
              <div id="likers-container-28572" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="28572"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #38"></div>
  </section>
</div>
    <div class="postbit" id="28575" data-post-id="28575">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/pra" rel="nofollow">@pra</a> just to clarify, if they are in the same database, then you definitely want to have foreign keys at the database level. At the application level, you will have to associate them too. The question is only if you have are going to have has_many/belongs_to going across schemas contexts.</p>
<p>The major downside of doing so is that you can easily end-up with really large schemas that associate with many schemas in different contexts. If you decide to not have has_many/belongs_to across contexts, then some parts of Ecto will become slightly more verbose. It means that instead of:</p>
<pre><code>Repo.all user.posts
</code></pre>
<p>You need to write:</p>
<pre><code>Repo.all from Post, where: [user_id: ^user.id]
</code></pre>
<p>Is it worth it? I would say so. But you can be the judge in your application. Relationships across contexts will certainly exist, it is a question of how you will reflect it on the application side.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="28575" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-determine-contexts-with-phoenix-1-3/4367/40">Post #39</a>
	                </div>
	            </div>
              <div id="likers-container-28575" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="28575"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #39"></div>
  </section>
</div>
    <div class="postbit" id="28613" data-post-id="28613">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ssbb" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ssbb/120/4414_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ssbb
                      <span class="op-star" title="Thread Starter">
                        <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                      </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Downside of this is because a lot of tools requires belongs_to/has_many to do some things automatically. For example ExAdmin.</p>
<p>btw how to preload things then to avoid N+1? For example if I have list of posts and there is <code>field :user_id, :integer</code> and I want to add user name at list of posts.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="28613" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-determine-contexts-with-phoenix-1-3/4367/41">Post #40</a>
	                </div>
	            </div>
              <div id="likers-container-28613" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="28613"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #40"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/4367/load_more?page=5">Load more posts (36 remaining)</a>
</div></template></turbo-stream>