huntz20
Hello there im working on pagination on my query
first lets see my query
query
|> join(:left, [o], op in OrderProduct, as: :order_product, on: o.id == op.order_id)
|> join(:left, [o, op], p in Product, as: :product, on: op.product_id == p.id)
|> preload(
[order_product: op, product: p],
[
:order_type,
:merchant,
:customer,
:payment_method,
order_product: {
op,
product: p
},
]
)
is valid query and its working, after giving it limit the result mess up
what i mean by mess up is i set the limit 5 but it return 3
i thought it was my query but after hour debugging i realize if i remove nested preload to be this
query
|> join(:left, [o], op in OrderProduct, as: :order_product, on: o.id == op.order_id)
|> join(:left, [o, op], p in Product, as: :product, on: op.product_id == p.id)
|> preload(
[order_product: op, product: p],
[
:order_type,
:merchant,
:customer,
:payment_method,
# order_product: {
# op,
# product: p
# },
]
it working and find any idea what is going here ??
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
al2o3cr
Take a look at the query that this is generating -
Ecto.Adapters.SQL.to_sql/3will give you the actual SQL that gets sent.The usual culprit in cases like this is that
LIMITapplies to the total number of rows returned, but when preloading in a single query there will be one row in the result perOrderProduct; if there are orders with more than one product, fewer than 5 orders will be returned.huntz20
Is there any options for me to make pagination but still doing preload ?
LostKobrakai
Preload in separate queries instead of joining them inline.
huntz20
sorry i dont realy get want you mean
so basicly i need get the data first then i iterate trrough all data to get all associate data ?
is that best practice for this case ?? or i miss intepret you sugesstion ??
dorgan
I’m using this to preload n items per row: Ecto preload n items per entity in a list · GitHub
Would love to know if folks find issues with that approach, but so far it worked well for me
LostKobrakai
Essentially yes, but you don’t need to iterate the data manually. If you don’t join associations in your quieries then preloads in ecto will happen in a separate query already. Even though there can be merit in doing less queries to the db there’s also the downside of data duplication within the resultset. Joining assocs just for preloading is imo nothing to blindly default to.