Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing null values from sort_link in Ransack #647

Closed
bnussey opened this issue Feb 22, 2016 · 2 comments
Closed

Removing null values from sort_link in Ransack #647

bnussey opened this issue Feb 22, 2016 · 2 comments

Comments

@bnussey
Copy link

bnussey commented Feb 22, 2016

I have a Ransack sort_link on a column called Revenue with a default sort: default_order: :desc

The problem I've got at the moment is the items with a null value in Revenue are put to the top. Is there anyway to avoid this?

Here is the full code:

sort_link(@q, :revenue, default_order: :desc)

@avit
Copy link
Contributor

avit commented Feb 26, 2016

Please post general questions to StackOverflow.

To answer briefly here: this is just how the database sorts NULL values. To sort it you'll need to select a real value in place of NULL: format the sort so instead of sort: "revenue" using raw value it uses "COALESCE(revenue, 0)" to replace with 0.

@jonatack
Copy link
Contributor

Thanks @avit.

@bnussey this question has been answered before (#443, etc.) In addition to posting on Stack Overflow where a wider community can help you, please search the repository before posting. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants