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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>True, but I wouldn’t be too concerned about SQL becoming opinionated, as the main goal is foreign language integration, which lend itself to prioritize building tooling that can be used in a provided mix task or other libraries hooking into said API.</p>
<p>Which means that we would have to look at migrations from a new angle, that is further away from what Ecto does today, but closer to Ash. Before we can do this we need to address the fundamental questions, why do we have database migrations, what do they solve, and what would they look like if they where native to the application language, or in the SQL specification itself.</p>
<p>I’m looking forward to this exercise.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="388147" 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-do-you-model-different-types-with-totally-different-fields-in-ecto/74944/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-388147" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="388147"
                     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 #21"></div>
  </section>
</div>
    <div class="postbit" id="388155" data-post-id="388155">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Your data model looks like a regular tagged union to me. Is there some reason you can’t use a separate table for each item type? If the relations are 1;1, then there’s not really any difference between the items;item_one schema and just an item_one schema with all the fields from both items and item_one on it. This also avoids a join, which can help if you need to sort across multiple columns since Postgres at least can’t use ordered indexes across joins.</p>
<p>Since you’ve got a tag field for the tagged union (the <code>type</code> field), you can pattern match on the value of that field passing structs or Ecto Schemas around in application code, and if each item type is a separate table, you could use Ecto Schemas and Ecto would take care of querying the correct table for you. If you don’t want to use ecto schemas it would be easy enough to pattern match on the type field to get the <code>from</code> clause. Something like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def from_items(:item_one), do: from(i in "item_one", as: :item_one)
def from_items(:item_two), do: from(i in "item_two", as: :item_two)
</code></pre>
<p>Cheers!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="388155" 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/how-do-you-model-different-types-with-totally-different-fields-in-ecto/74944/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-388155" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="388155"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>