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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="woylie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/woylie/120/38856_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  woylie
                    <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>You can pass the prefix as part of the <code>query_opts</code>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Flop.validate_and_run(query, params, query_opts: [prefix: "some_prefix"])
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="324733" 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/flop-filtering-sorting-and-pagination-for-ecto/51750/33">Post #32</a>
	                </div>
	            </div>
              <div id="likers-container-324733" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="324733"
                     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="324765" data-post-id="324765">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Perfect! Got to love Flop! Such a quality of life improvement! Thanks for this library!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="324765" 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/flop-filtering-sorting-and-pagination-for-ecto/51750/34">Post #33</a>
	                </div>
	            </div>
              <div id="likers-container-324765" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="324765"
                     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="331399" data-post-id="331399">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>A bit of a late reply, but, to improve your life even more, you could store the prefix in the process once you determine the tenant, and use the prefix in the repo’s default option. This would abstract providing the schema prefix from almost all of your app (I say almost cuz sometimes you’d need to explicitly set the prefix, eg: tests).</p>
<p>Here’s how we do it in our app:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Postgres

  .
  .
  .

  @impl true
  def default_options(_) do
    [prefix: get_tenant()]
  end

  @doc """
  Hold :prefix in option in the current process space
  """
  def set_tenant(tenant) do
    Process.put({__MODULE__, :prefix}, tenant)
    tenant
  end

  def get_tenant do
    Process.get({__MODULE__, :prefix}) || "public"
  end
end

</code></pre>
<p>The only piece left in the puzzle is setting the prefix once you determine the current tenant, eg: access to domain &lt;tenant-subdomain&gt;.example.com → prefix = &lt;tenant-subdomain&gt;</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">MyApp.Repo.set_tenant("&lt;tenant-subdomain&gt;")
</code></pre>
<p>Hope this helps!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="331399" 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/flop-filtering-sorting-and-pagination-for-ecto/51750/35">Post #34</a>
	                </div>
	            </div>
              <div id="likers-container-331399" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="331399"
                     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="342300" data-post-id="342300">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><s>Is there a convenient way to have an final order applied <em>after</em> all requested orders have been applied? The goal is to have a stable list, even when sorting by a condition that has many large buckets of the same value. Adding a sort order by id (or inserted_at for example) as the last order by clause can make the final list stable.</s></p>
<p><s>The default order doesn’t help here, because I want to add the order clause in any case. Ecto only allows <a href="https://hexdocs.pm/ecto/Ecto.Query.html#prepend_order_by/3" rel="noopener nofollow ugc">Ecto.Query.prepend_order_by/3</a>. I don’t think there is any way to intercept the final query, and append a sort order after Flop has augmented the passed-in query. Unless I’m missing something here… <img src="https://forum.elixirforum.com/images/emoji/apple/thinking.png?v=15" title=":thinking:" class="emoji" alt=":thinking:" loading="lazy" width="20" height="20"></s></p>
<p>Oh, I’ve asked about this before <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"> (<a href="https://github.com/woylie/flop/discussions/349" class="inline-onebox" rel="noopener nofollow ugc">A different way of manipulating ordering fields and directions, and combining with the configured default ordering. · woylie/flop · Discussion #349 · GitHub</a>) I didn’t remember. Sorry for the noise.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="342300" 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/flop-filtering-sorting-and-pagination-for-ecto/51750/36">Post #35</a>
	                </div>
	            </div>
              <div id="likers-container-342300" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342300"
                     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="353364" data-post-id="353364">
  <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">
								<p>Seems this is the place to ask Flop questions.  Not sure if it’s ideal over starting a new thread but here I am!</p>
<p>Is there a less verbose way to, on the fly, build a path with filters than this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">build_path(~p"/admin/catalog",
  %Flop{
    filters: [
      %Flop.Filter{
        field: :collection_id,
        value: collection.id
      }
    ]
  }
)
</code></pre>
<p>I may be having a brain blip as I feel as if I’ve done this before but I can’t remember or find it <img src="https://forum.elixirforum.com/images/emoji/apple/face_with_spiral_eyes.png?v=15" title=":face_with_spiral_eyes:" class="emoji" alt=":face_with_spiral_eyes:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="353364" 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/flop-filtering-sorting-and-pagination-for-ecto/51750/37">Post #36</a>
	                </div>
	            </div>
              <div id="likers-container-353364" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="353364"
                     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="353380" data-post-id="353380">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="woylie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/woylie/120/38856_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  woylie
                    <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 don’t think there’s a less verbose way to do that short of writing out the query parameters directly.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="353380" 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/flop-filtering-sorting-and-pagination-for-ecto/51750/38">Post #37</a>
	                </div>
	            </div>
              <div id="likers-container-353380" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="353380"
                     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 #37"></div>
  </section>
</div>
    <div class="postbit" id="353406" data-post-id="353406">
  <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">
								<p>Thanks, <a class="mention" href="/u/woylie" rel="nofollow">@woylie</a>!  I realized that I have never actually used it (obviously), I just <em>thought</em> about it.  I have an app for a client that is (if you can believe this) a glorified spreadsheet.  There are several pages where I link to the main table view with pre-filled filters.  I remembered that I ended using dropdowns out of <s>laziness</s> the convenience of <code>Flop.Phoenix.filter_fields/1</code> even though links would be better.  This is the first app I ever used Flop with and I don’t work on it very often so there are some odd decisions lurking that I made while learning.</p>
<p>It’s not like status quo is bad but a shorthand might be nice.  Would you be open to that?  Something like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">build_path(path, filters: [field: value])
build_path(path, filters: [field: {:&gt;=, value}])
build_path(path, page: 2)
</code></pre>
<p>Thinking out loud here and not sure if it’s a problem many people face or what can of worms this might open.  I’m happy to do the work if you’re open to it, though.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="353406" 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/flop-filtering-sorting-and-pagination-for-ecto/51750/39">Post #38</a>
	                </div>
	            </div>
              <div id="likers-container-353406" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="353406"
                     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="353450" data-post-id="353450">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="woylie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/woylie/120/38856_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  woylie
                    <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’m not sure I’d want to officially support this at the moment. I thought I opened an issue before about a simplified filter syntax, but I can’t find it. I feel like there are more pressing issues right now, and this would just add unnecessary complexity. If you find it useful, you can add a wrapper around <code>build_path</code> to your application (and maybe share it). Might think about this again in the future.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="353450" 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/flop-filtering-sorting-and-pagination-for-ecto/51750/40">Post #39</a>
	                </div>
	            </div>
              <div id="likers-container-353450" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="353450"
                     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="361482" data-post-id="361482">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Is there a way to return errors in the same format as Ecto changeset errors?</p>
<p>I’m making a request like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">/api/posts?filters[0][field]=invalid_field&amp;filters[0][value]=value
</code></pre>
<p>It returns meta struct with errors like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">%Flop.Meta{
  backend: nil,
  current_offset: nil,
  current_page: nil,
  end_cursor: nil,
  next_offset: nil,
  next_page: nil,
  page_size: nil,
  previous_offset: nil,
  previous_page: nil,
  schema: MyApp.Posts.Post,
  start_cursor: nil,
  total_count: nil,
  total_pages: nil,
  errors: [
    filters: [
      [field: [{"is invalid", [validation: :inclusion, enum: [:is_public]]}]]
    ]
  ],
  flop: %Flop{
    after: nil,
    before: nil,
    first: nil,
    last: nil,
    limit: nil,
    offset: nil,
    order_by: nil,
    order_directions: nil,
    page: nil,
    page_size: nil,
    decoded_cursor: nil,
    filters: []
  },
  has_next_page?: false,
  has_previous_page?: false,
  opts: [for: MyApp.Posts.Post],
  params: %{"filters" =&gt; [%{"field" =&gt; "invalid_field", "value" =&gt; "value"}]}
}
</code></pre>
<p>What is the best way to convert meta.errors into a human-readable format before returning a JSON response in Phoenix?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="361482" 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/flop-filtering-sorting-and-pagination-for-ecto/51750/41">Post #40</a>
	                </div>
	            </div>
              <div id="likers-container-361482" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="361482"
                     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>
    <div class="postbit" id="361485" data-post-id="361485">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="woylie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/woylie/120/38856_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  woylie
                    <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><code>meta.errors</code> contains the errors in the same format as Ecto.Changset. You should be able to transform them with Phoenix’s <code>translate_error</code> function:</p>
<p><a href="https://github.com/phoenixframework/phoenix/blob/d8c6e8bf7a42f2f9668dd619aab71acd67b91e90/installer/templates/phx_web/components/core_components.ex#L434-L474" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/phoenixframework/phoenix/blob/d8c6e8bf7a42f2f9668dd619aab71acd67b91e90/installer/templates/phx_web/components/core_components.ex#L434-L474</a></p>
<p>Except in your case, you probably want to transform the errors of all fields recursively, instead of only a single field.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="361485" 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/flop-filtering-sorting-and-pagination-for-ecto/51750/42">Post #41</a>
	                </div>
	            </div>
              <div id="likers-container-361485" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="361485"
                     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 #41"></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/51750/load_more?page=5">Load more posts (5 remaining)</a>
</div></template></turbo-stream>