Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Created December 19, 2008 13:46
Show Gist options
  • Save bkeepers/38005 to your computer and use it in GitHub Desktop.
Save bkeepers/38005 to your computer and use it in GitHub Desktop.
class Section < ActiveRecord::Base
has_many :articles, :order => 'position'
end
class Article
default_scope :order => 'published_at DESC'
named_scope :by_author, :order => 'author'
named_scope :by_position, :order => 'position'
end
Article.by_author
# Expected:
# …ORDER BY author, published_at DESC
# Actual:
# …ORDER BY author
Article.by_position.by_author
# Expected:
# …ORDER BY author, position, published_at DESC
# Actual:
# …ORDER BY author
Section.first.articles.by_author
# Expected:
# …ORDER BY author, position
# Actual:
# …ORDER BY position, author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment