Comments (6)
Thanks for looking into this @glebm , and let me know if I can assist.
from order_query.
After adding a test for multiple nulls, I can see that the query it generates without wrap_top_level_or
has an incorrect OR
clause:
SELECT "posts".* FROM "posts"
WHERE ("posts"."published_at" IS NULL OR -- <- *this is wrong*
"posts"."published_at" IS NULL AND "posts"."id" < 47)
ORDER BY "posts"."published_at" IS NULL ASC,
"posts"."published_at" ASC,
"posts"."id" DESC LIMIT 1
from order_query.
If it works for you, I'll release a new version.
You can try it out with:
gem 'order_query', git: 'https://github.com/glebm/order_query', branch: 'null-wtlo'
There should be no need to set wrap_top_level_or = false
in that branch (it wasn't a sufficient workaround anyway).
from order_query.
Hi @glebm , things seem to work with the updated code.
I did not use wrap_top_level_or = false
for this test (I omitted the setting altogether).
For posterity, here its the resulting query:
seek_args: [[:title, :desc, {:nulls=|:first}]]
Entry Load (1.0ms) SELECT `entries`.* FROM `entries` ORDER BY `entries`.`title` IS NULL DESC, `entries`.`title` DESC, `entries`.`id` ASC LIMIT 20
Entry Load (0.7ms) SELECT `entries`.* FROM `entries` WHERE `entries`.`id` = 1 LIMIT 1
Entry Load (0.7ms) SELECT `entries`.* FROM `entries` WHERE (`entries`.`title` IS NULL AND `entries`.`id` | 1) ORDER BY `entries`.`title` IS NULL ASC, `entries`.`title` ASC, `entries`.`id` DESC LIMIT 1
Thanks for your help with this!
from order_query.
BTW, please feel free to close the other issue, it's obviously less pressing given this is working. Thanks again.
from order_query.
Fix released in v0.4.1
from order_query.
Related Issues (20)
- Ordering by NULLS FIRST / LAST HOT 10
- documentation on how to "paginate" results HOT 6
- new version release HOT 1
- Test on multiple databases
- is sorting by an associated column supported? HOT 10
- pass table and column to custom sql function HOT 11
- TODO: Better tests for nils in enums
- Change base scope? HOT 2
- Get point for reverse scope HOT 2
- Rails 6 support HOT 2
- Wrong order? HOT 1
- Top-level disjunctive causes sub-optimal query plan HOT 6
- Calling prev and next when the ordering model attribute is enumerable creates an invalid SQL where clause HOT 2
- Redundant condition elimination
- #seek or #at with previously specified order HOT 5
- Can this sort on nested attributes? HOT 3
- Feature Request: HOT 1
- .previous always showing first record when limiting scope HOT 2
- Not compatible with rails 5 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from order_query.