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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<blockquote>
<p>I’m currently involved in yet another domain modeling exercise where all the database tables are being designed upfront. I have a nagging feeling that a classic mistake is being made for the N-millionth time. Does anyone have any goto resources they like for not falling into this trap? I remember watching a talk a few years ago which I’m having trouble finding now. Am I even making sense??</p>
</blockquote>
<p>You can try <a href="https://www.eventstorming.com/" rel="noopener nofollow ugc">Event Storming</a>, it will focus you on the <em>domain</em> not the the <em>data</em>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346217" 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/design-discussion-ecto-is-your-application/67389/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-346217" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346217"
                     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 #11"></div>
  </section>
</div>
    <div class="postbit" id="346229" data-post-id="346229">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Sorc96" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Sorc96/120/28361_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Sorc96
                    <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>Your comment made me realize something interesting. I think we’re encountering the same issue as the object-relational (or graph-relational) mismatch. When designing the database first, we end up conforming not just the application code to it (which can be acceptable to a certain degree), but also the way our software can be used easily.</p>
<p>And the users won’t be happy when using the app the way they want is awkward because of the decisions we made about the storage mechanism. A classic example would be when data can be entered into the system partially, like information about products being sold. But of course, in order for customers to buy the product, all of the information needs to be in the system.</p>
<p>When thinking about the process first, we would most likely realize the need to strictly separate the work-in-progress products from ones that can be sold. But in practice, there’s probably just one table for products with a column which marks that the product can be sold. Inevitably, products with incomplete information end up being sold, creating problems all over the place.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346229" data-batch-url="/posts/batch_likers">
                        0
                      </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/design-discussion-ecto-is-your-application/67389/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-346229" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346229"
                     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 #12"></div>
  </section>
</div>
    <div class="postbit" id="346412" data-post-id="346412">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="krisleech" data-post="12" data-topic="67389">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/krisleech/48/35182_2.png" class="avatar"> krisleech:</div>
<blockquote>
<p>You can try <a href="https://www.eventstorming.com/" rel="noopener nofollow ugc">Event Storming</a>, it will focus you on the <em>domain</em> not the the <em>data</em>.</p>
</blockquote>
</aside>
<p>I’ve actually done example mapping before!  It was on a project with a very small model, though, and the primarily domain modelling had already been done.  It was a very UI-heavy app (a gantt chart) and I think there were a total of maybe 8 business models?  I feel like it was less but this was a few years ago.  Everything had already been modeled and there were far more changes to verbs than nouns in general.</p>
<aside class="quote no-group" data-username="dimitarvp" data-post="10" data-topic="67389">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/48/38664_2.png" class="avatar"> dimitarvp:</div>
<blockquote>
<p>but it also has to be said that usually code follows data i.e. the most important thing you will do is to design the data (well or not).</p>
</blockquote>
</aside>
<p>I’m not arguing that data isn’t the most important thing but that modeling it based on how it’s stored is not ideal.  Using behaviour to inform its design is (likely) better.  This is what I understood <a class="mention" href="/u/sorc96" rel="nofollow">@Sorc96</a>’s premise to be.  I think I agree but I just don’t have the experience of knowledge to back that up which is why I asked if anyone had any really good resources.  I assume it’s limited as I don’t know of a web framework that doesn’t push you to model data based on its storage and it seems like one of those things that most people are going to say “It’s what everyone already knows and is good enough.”</p>
<aside class="quote no-group" data-username="al2o3cr" data-post="4" data-topic="67389">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/48/3457_2.png" class="avatar"> al2o3cr:</div>
<blockquote>
<p>It also sounds like you’re looking for a feature like ActiveRecord’s <a href="https://api.rubyonrails.org/classes/ActiveRecord/Aggregations/ClassMethods.html#method-i-composed_of" rel="noopener nofollow ugc"><code>composed_of</code></a>.</p>
</blockquote>
</aside>
<p>I didn’t respond to this earlier but having <code>composed_of</code> in Ecto would be great!  A friend of mine actually did a really good <a href="https://www.youtube.com/watch?v=j5o-lUF_nJs" rel="noopener nofollow ugc">2018 Rails Conf talk</a> that includes <code>composed_of</code>.  I feel a little dirty slipping a plug in here, but it’s a really good talk!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346412" 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/design-discussion-ecto-is-your-application/67389/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-346412" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346412"
                     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 #13"></div>
  </section>
</div>
    <div class="postbit" id="346413" data-post-id="346413">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="sodapopcan" data-post="14" data-topic="67389">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sodapopcan/48/34668_2.png" class="avatar"> sodapopcan:</div>
<blockquote>
<p>I don’t know of a web framework that doesn’t push you to model data based on its storage</p>
</blockquote>
</aside>
<p>I wonder if this is really true though?</p>
<p>I think there can certainly be certain features of frameworks that make it more or less difficult to design storage agnostic models but at the end of the day there will always be tradeoffs for doing so. ActiveRecord’s philosophy was very clearly to help you forget about the DB and as a novice developer I drank deeply of that particular kool aid (even before <code>NoSQL</code> became a real buzzword) because I found SQL to be a boring, terrible API in comparison to Ruby, and as the runtime env for my application the latter felt much closer to the “life” of my application. But even AR had aspects that clearly were geared to relational dbs (hard to imagine “associations” outside the context of a relational db). And isn’t that because relational dbs have features that, even if they sometimes seem like purely technical, implementation details, are really part of the value you are offering your users? “Persistence” isn’t some weird accidental part of software, it’s a real world need with its own logic that most frameworks want to expose.</p>
<p>So I guess the answer is yes, frameworks do push that, but not in an essentially different way than they push you to validate inputs, etc.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346413" 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/design-discussion-ecto-is-your-application/67389/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-346413" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346413"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="346439" data-post-id="346439">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="tfwright" data-post="15" data-topic="67389">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/48/20299_2.png" class="avatar"> tfwright:</div>
<blockquote>
<p>So I guess the answer is yes, frameworks do push that, but not in an essentially different way than they push you to validate inputs, etc.</p>
</blockquote>
</aside>
<p>I think this is a good thing honestly. I love that you can write your own queries in Ecto and you don’t have to rely on some higher-level abstractions that ORMs from languages like c#/java offer. The problem with those types of ORMs is that they are opinionated in a lot of the decisions, not flexible enough and not extensible.</p>
<p>I always tend to showcase how easily ecto queries can be extended:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  defmacro st_transform(wkt, srid) do
    quote do: fragment("ST_Transform(?, ?)", unquote(wkt), unquote(srid))
  end
</code></pre>
<p>Good luck implementing that with an ORM that tries to abstract everything.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346439" 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/design-discussion-ecto-is-your-application/67389/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-346439" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346439"
                     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 #15"></div>
  </section>
</div>
    <div class="postbit" id="346444" data-post-id="346444">
  <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">
								<p>I think ecto has a hard time to be explained because by being a data mapping tool it is great at two edges of the system – the one where data comes in and the one where data goes out (usually for storage). In a lot of cases, where data is shaped to allow for it, it’s very easy to just not think of those as two edges, but just wire data right through. Therefore that’s a lot of what we see in code shared around elixir. Imo this is however just a lazy mans shortcut, fair to be used where possible, but which needs to be acknowledged as not the way forward where it doesn’t anymore. If there’s a need for richer domain modeling, which deviates from the constraints of storing the data, then that’s imo no longer ectos job, even if ecto might be part of implementing that. That’s one of the places where ecto hard deviates from what ORMs commonly do. Ecto wants to model your data stored in your db by embracing that the data needs to go into a db, instead of finding magic ways to make you do things dbs cannot do well like polymorphic relationships.</p>
<p>If one is fine with the lack of referential integrity of <code>ref_id, ref_type</code> columns then that can be built with ecto. Others might go with <a href="https://hexdocs.pm/ecto/3.12.4/Ecto.Schema.html#belongs_to/3-polymorphic-associations" rel="nofollow">abstract tables</a> polymorphism, which retains referential integrity. Or you might not need to have foreign keys, so you opt for polymorphic data in a json column. One might even use all three options depending on their distinct tradeoffs.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346444" data-batch-url="/posts/batch_likers">
                        7
                      </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/design-discussion-ecto-is-your-application/67389/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-346444" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346444"
                     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 #16"></div>
  </section>
</div>
    <div class="postbit" id="346446" data-post-id="346446">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Sorc96" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Sorc96/120/28361_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Sorc96
                    <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">
								<aside class="quote no-group" data-username="sodapopcan" data-post="14" data-topic="67389">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sodapopcan/48/34668_2.png" class="avatar"> sodapopcan:</div>
<blockquote>
<p>I assume it’s limited as I don’t know of a web framework that doesn’t push you to model data based on its storage and it seems like one of those things that most people are going to say “It’s what everyone already knows and is good enough.”</p>
</blockquote>
</aside>
<p>I have the same experience. It’s probably because of how easy it is to get started wit this approach. Most people, especially less experienced devs, don’t want to start thinking about mapping between UI, domain and persistence layers. Just define one model/schema and have it go from the html form all the way to the database and you’re done.</p>
<p>But as the application becomes more and more complex, this approach starts to take its toll. Suddenly, domain logic is doing way too many checks for underlying details of the persistence layout, database tables are designed suboptimally to avoid even more application level complexity, and custom mapping starts happening all over the place because the UI doesn’t match the database 1:1.</p>
<p>I’m not sure if I will ever be truly happy with any solution, but I’m currently at a point where I think more ORM features (like <code>composed_of</code>) could help a lot.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346446" 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/design-discussion-ecto-is-your-application/67389/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-346446" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346446"
                     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 #17"></div>
  </section>
</div>
    <div class="postbit" id="346448" data-post-id="346448">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Sorc96" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Sorc96/120/28361_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Sorc96
                    <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>I just realized the same thing after writing the initial post. Ecto has amazing capabilities for working with the database and changesets work well for validating the data that comes in from the outside. But having these two concerns (and also domain logic) align is a happy accident that cannot be relied upon.</p>
<p>I think the weakest part is probably Ecto.Schema. It provides enough features that I don’t want to work without it, while also constraining design significantly. In order to make schemas work better without custom mapping to other data structures, they would need to support more mapping features like <code>composed_of</code> mentioned above.</p>
<p>I also think schemas would need more versatility in terms of the underlying representation. Maybe a schema should not be tied to a single table. Why not allow any queryable? That way, schemas could automatically be limited to certain rows by a <code>where</code> clause or combine data from multiple tables using <code>join</code>. This would allow schemas to be used with the full power of Ecto.Query. However, I am aware that this could also make insert/update impossible, but I still think the benefits to read operations would be worth it.</p>
<p>EDIT: To make my point clearer, I think the problem is that we have to either use Ecto.Schema and give up on the powerful features of Ecto.Query, or use the full potential of Ecto.Query in out custom mapping functions, but then we’re giving up the benefits of Ecto.Schema.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346448" 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/design-discussion-ecto-is-your-application/67389/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-346448" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346448"
                     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 #18"></div>
  </section>
</div>
    <div class="postbit" id="346449" data-post-id="346449">
  <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="Sorc96" data-post="19" data-topic="67389">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sorc96/48/28361_2.png" class="avatar"> Sorc96:</div>
<blockquote>
<p>I also think schemas would need more versatility in terms of the underlying representation. Maybe a schema should not be tied to a single table. Why not allow any queryable?</p>
</blockquote>
</aside>
<pre data-code-wrap="elixir"><code class="lang-elixir">def schema_from_two_tables do
  from a in "a", 
    join: b in "b", 
    on: a.id == b.a_id, 
    select: %Schema{id: a.id, from_b: b.data}
end
</code></pre>
<p>Nobody requires you to query based on the table defined on the schema macro. The name provided to the schema table is also never validated to be an actual valid table name. It is only required to be valid if you try to query by it. E.g. <code>{"filtered_people", Person}</code> is a queryable, to query values using a schema from a separately provided table.</p>
<p>So I’d argue you already have all the freedom to query schemas how you like, we’re just having a hard time communicating all of that to people I think. You are correct though that inserts/updates are a lot trickier that way. If you need inserts/updates you can look into updatable views with postgres, but also I’d argue CQS, where you have separate schemas/models for querying and writing is something reasonable to look at.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346449" 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/design-discussion-ecto-is-your-application/67389/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-346449" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346449"
                     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 #19"></div>
  </section>
</div>
    <div class="postbit" id="346457" data-post-id="346457">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Sorc96" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Sorc96/120/28361_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Sorc96
                    <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">
								<aside class="quote no-group" data-username="LostKobrakai" data-post="20" data-topic="67389">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lostkobrakai/48/3072_2.png" class="avatar"> LostKobrakai:</div>
<blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">def schema_from_two_tables do
  from a in "a", 
    join: b in "b", 
    on: a.id == b.a_id, 
    select: %Schema{id: a.id, from_b: b.data}
end
</code></pre>
</blockquote>
</aside>
<p>Is the schema doing anything at this point, though? Would there be any difference with a regular struct?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="346457" data-batch-url="/posts/batch_likers">
                        0
                      </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/design-discussion-ecto-is-your-application/67389/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-346457" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="346457"
                     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 #20"></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/67389/load_more?page=3">Load more posts (18 remaining)</a>
</div></template></turbo-stream>