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...
davec authored and emk committed Feb 27, 2009
1 parent dd86ad9 commit bb6c3a33fdbab9b4a65e157d54f7f6c52e413ee9
Showing with 4 additions and 1 deletion.
  1. +4 −1 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'

0 comments on commit bb6c3a3

Please sign in to comment.