Comments (10)
All done! Released in v0.4.0!
from order_query.
What database are you using? NULL LAST is the default for DESC in MySQL.
This gem doesn't deal with nulls well yet, I'll need to see what it does currently and how it can be improved.
from order_query.
As a quick hack for now while we figure out a proper solution, you could do this:
order_query :my_order,
[:posted_at_or_zero, :desc, sql: "COALESCE(posted_at, '0000-00-00 00:00:00')"]
def posted_at_or_zero
posted_at || DateTime.new(0)
end
from order_query.
Looks good! That's postgresql so I had to change order_query
to COALESCE(posted_at, '#{Time.utc(1900).to_s(:db)}')
and posted_at_or_zero
to posted_at || Time.utc(1900)
since postgresql does not allow zeros as date.
That's good enough for my application. Nevertheless it would be nice if you could do something like: order_query :my_order, ['posted_at %order% NULLS LAST', :desc]
and order_query would replace %order%
by DESC
or ASC
. This way all future problems, where the name of a field to order by is not enough, would be solved.
Thank you for your time and your hints how to solve this problem!
from order_query.
@glebm I see that you did some work on this but it's well over a year old. I'm just curious what the status is and what your plans are for this feature.
from order_query.
This feature seems to work in the nulls-order
branch, but:
- Tests are needed.
- Branch needs rebasing.
- Documentation needs to be updated.
I don't plan to do that myself, but if someone does all of the above and sends a PR I'll review it.
from order_query.
Thanks for the reply. I looked at it and rebased from master with no issues. All the tests ran afterwards but the nulls feature still needs a some work and is not currently working.
Nulls can be especially tricky since many times you want to keep them in the result set but still have them sorted.
As I looked more into it I realized I would be better off implementing keyset queries in my own app. I think this will be the case for most people who need queries that this gem doesn't handle.
from order_query.
Status update: Added more tests to the branch and got some of them to pass.
from order_query.
Status update: The nulls-order branch now passes all the tests. Still needs testing with all the databases to be safe to merge (#15)
from order_query.
Status update: PR merged, tests failing on Postgres, still not 100% coverage.
from order_query.
Related Issues (20)
- 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
- Nulls ordering skips records if there is more than one NULL HOT 6
- 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.