Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Force consistent ordering of dates containing NULLs

Because database servers differ on how they sort NULL values, the sort
order for articles was changed, via COALESCE, so that a NULL date will
be treated as being less than (i.e., older than) any non-NULL date.
This fixes test_should_search_article_by_section so that it passes with
MySQL, SQLite, and PostgreSQL.

[I'm merging this patch because I'm quite fond of PostgreSQL, and
because it has been tested with most of the other databases we support.
If this breaks your database, please let me know. -Eric]
  • Loading branch information...
commit bb6c3a33fdbab9b4a65e157d54f7f6c52e413ee9 1 parent dd86ad9
@davec davec authored emk committed
Showing with 4 additions and 1 deletion.
  1. +4 −1 app/controllers/admin/articles_controller.rb
5 app/controllers/admin/articles_controller.rb
@@ -14,7 +14,10 @@ class Admin::ArticlesController < Admin::BaseController
before_filter :load_sections, :only => [:new, :edit]
def index
- @articles = site.articles.paginate(article_options(:order => 'contents.published_at DESC', :select => 'contents.*',
+ # Force NULL published_at values to be considered earlier than any non-NULL
+ # published_at value. (Database servers differ on how NULLs are sorted, so
+ # we need to force a consistent order.)
+ @articles = site.articles.paginate(article_options(:order => "COALESCE(contents.published_at, '1900-01-01') DESC", :select => 'contents.*',
:page => params[:page], :per_page => params[:per_page]))
@comments = @site.unapproved_comments.count :all, :group => :article, :order => '1 desc'
Please sign in to comment.
Something went wrong with that request. Please try again.