Skip to content

Instantly share code, notes, and snippets.

@nicolasblanco
Created August 12, 2009 16:20
Show Gist options
  • Save nicolasblanco/166596 to your computer and use it in GitHub Desktop.
Save nicolasblanco/166596 to your computer and use it in GitHub Desktop.
# Problem with :order, all and will_paginate ?
#
# This one should NOT work, but will_paginate seems not to use the :order option...
#
>> User.all.paginate(:page => 1, :order => "superpipolol")
=> [#<User id: 1, last_name: "Team", first_name: "The-Sphere", email: "admin@the-sphere.com", ...]
# This fails as expected.
#
>> User.paginate(:all, :page => 1, :order => "superpipolol")
=> ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'superpipolol' in 'order clause': SELECT * FROM `users` ORDER BY superpipolol LIMIT 0, 30
# This fails as expected with a custom named_scope too.
#
>> User.latest(5).paginate(:page => 1, :order => "superpipolol")
=> ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'superpipolol' in 'order clause': SELECT * FROM `users` ORDER BY superpipolol, created_at DESC LIMIT 0, 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment