Wierd ordering with multiple alias #15903
Unanswered
marisancans
asked this question in
Help & Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I get wierd ordering when using multiple alias to the same model together with limit:
This is how SsEstate is defined
This is how SsEstatePrice is defined as:
And this is the query I am calling:
Basically what Im trying to achieve is sort SsEstates by LatestPrice which is an hasOne relation to SsEstatePrice
I also need PriceHistory objects to be sorted
What I get is strange ordering,
on page 1 prices look like = 25, 35, 40, 33, 35 (Ascending, but wrong)
on page 2 = 30, 30, 30, 35 (Why starting from 30 again?)
My pagination is working Im sure of that.
What I noticed is that if I remove PriceHistory include then everything works as I want, somehow PriceHistory ruins the ordering and im going crazy trying to figure it out.
Here is the SQL without PriceHistory:
And here is the SQL without PriceHistory:
I notice that without PriceHistory the ORDER BY is called at the end, but when PriceHistory is added it is somewhere else
I also tried to order by latestSsEstatePriceId using literal but was unsuccessful or with lack of knownledge
"sequelize-cli": "^6.6.0"
"sequelize": "6.21.3"
PostgreSQL version: 14.0 (Debian 14.0-1.pgdg110+1)
Edit: Adding subQuery: false is even weirder, returns me 3-7 results on each page (has to be 15)
Edit 2: Ok after a sleep and clear head I managed to do this with a literal SQL which is not ideal in my opinion, I would like to use ORM as much as possible.
Also, I think I found an explanation on what is happening here
What I now dont understand is how can I filter 'latestprice' with where
Beta Was this translation helpful? Give feedback.
All reactions