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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><code>type/2</code> in select is great.</p>
<p>One use case came up that is still a bit awkward: converting a <code>sum(x)</code> into a <code>Money.Ecto.Type</code>:<br>
The workaround I found was to wrap it in a subquery:</p>
<pre><code>from account_balance in subquery(
  from t in Transaction,
  group_by: [t.account_id],
  select: %{account_id: t.account_id, balance: sum(t.amount)})
select %{account_id: account_balance.account_id, balance: type(account_balance.balance, Money.Ecto.Type)}
</code></pre>
<p>If the subquery layer could be removed it would be amazing!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45402" 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/ecto-2-2-0-rc-0-released/7634/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-45402" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45402"
                     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="45428" data-post-id="45428">
  <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
                    <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 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/mbuhot" rel="nofollow">@mbuhot</a> please open up an issue, we can easily support aggregates inside <code>type/2</code> as well.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45428" 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/ecto-2-2-0-rc-0-released/7634/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-45428" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45428"
                     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="45440" data-post-id="45440">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="ijunaidfarooq" data-post="12" data-topic="7634" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ijunaidfarooq/48/1532_2.png" class="avatar"> ijunaidfarooq:</div>
<blockquote>
<p>while you are rewriting already will you please mention here? one of use case as well? that how and where it helped you?</p>
</blockquote>
</aside>
<p>I build some utterly massive queries to get information from an old Oracle database.  If I were to return everything then it would be beyond huge (it has hundreds of columns in some cases), so I return data massaged into a better format (getting some information like ethnicity involves querying <em>5</em> tables, or 6 depending on the detail wanted), however some information is only available depending on what was passed in, and the sheer combination of options that can be passed in would be thousands large if I were to make a custom query for each combination of input and return information, so instead I’ve been building information to generate a select as it ramps down the whole line of things, changing it from thousands of total combinations to the 9 or so from the inputs and just branch based on their combinations for specific shared outputs.  This means that I can reduce it to a linear set of code instead of my prior N*M combinations, thus making it substantially easier to read and follow.</p>
<p>I’ve not rewritten any of the older ones yet, they are a bit of a many-many-screen horrors each, but sometime…  &gt;.&gt;<br>
(I don’t want to break them, they are brittle, this will reduce a lot of the brittleness though once I do it.)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45440" 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/ecto-2-2-0-rc-0-released/7634/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-45440" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45440"
                     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="45487" data-post-id="45487">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks <a class="mention" href="/u/josevalim" rel="nofollow">@josevalim</a>, <a href="https://github.com/elixir-ecto/ecto/issues/2163" rel="noopener nofollow ugc">#2163</a> opened.</p>
<p>Related, but slightly different is when a schema declares a virtual field that is populated in a query:</p>
<pre><code>  schema "accounts" do
    field :name, :string
    field :balance, Money.Ecto.Type, virtual: true
    has_many :transactions, Transaction
    timestamps()
  end

accounts_with_balance = Repo.all(from a in Account, select: %{a | balance: 123})
</code></pre>
<p>The current behaviour doesn’t load the value through the declared custom type.<br>
Would you be open to automatically casting the virtual field to the type declared in the 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="45487" 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/ecto-2-2-0-rc-0-released/7634/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-45487" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45487"
                     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="45538" data-post-id="45538">
  <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
                    <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 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="mbuhot" data-post="16" data-topic="7634">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mbuhot/48/33444_2.png" class="avatar"> mbuhot:</div>
<blockquote>
<p>Would you be open to automatically casting the virtual field to the type declared in the schema?</p>
</blockquote>
</aside>
<p>Please open up an issue as well.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="45538" 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/ecto-2-2-0-rc-0-released/7634/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-45538" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="45538"
                     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>