Skip to content

Instantly share code, notes, and snippets.

@dougo
Created May 4, 2013 04:21
Show Gist options
  • Save dougo/5516162 to your computer and use it in GitHub Desktop.
Save dougo/5516162 to your computer and use it in GitHub Desktop.
Surprising behavior of ActiveRecord's order method. Can't decide if I should file this as a bug on rails/rails, or post to stackoverflow, or just suck it up and write a separate method that does the right thing.
Loading development environment (Rails 4.0.0.rc1)
2.0.0p0 :001 > p = Post.new
=> #<Post id: nil, title: nil, text: nil, created_at: nil, updated_at: nil>
2.0.0p0 :002 > p.comments.build
=> #<Comment id: nil, commenter: nil, body: nil, post_id: nil, created_at: nil, updated_at: nil>
2.0.0p0 :003 > p.comments.size
=> 1
2.0.0p0 :004 > p.comments.order(:created_at).size
=> 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment