Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You referring to the removal of deprecated methods from the 2.x branch?


I think the parent is referring to the changes to ActiveRecord::Base#find and its convenience helpers, #first, #last, and #all. I'm not sure what else it could be. It's definitely true that the semantics of the finders have changed and they're huge gotchas to newbies to Rails. Here's a brief review:

In rails 2.x:

    Post.find(:first) # => First record, determined by db engine
    Post.find(:all)   # => All records
    Post.find(1)      # => Find record with id 1
    Post.first        # => Same as find(:first)
    Post.all          # => Same as find(:all)
Rails 3.x

    Post.find(:first) # Deprecated, use #first/#all
    Post.find(1)      # Same as 2.x
    Post.first        # First record, determined by db engine
    Post.all          # All records or force execution of a Relation
Rails 4:

    Post.find(:first) # RecordNotFound, could not find record with id :first
    Post.find(1)      # Same as 2.x
    Post.first        # Ordering is enforced, use #take to simulate old #first
    Post.all          # Always returns ActiveRecord::Relation
    Post.all.to_a     # Force query to execute, avoid this!
I'm not particularly unhappy about any of the changes as they definitely make it more consistent. With the move to ARel in the 3.x releases, they definitely discouraged the use of #all to force query execution (build up a query, iterate over it, don't worry about executing it).

I'm actually quite glad they fixed the db ordering gotcha present when using #first and #last. It drove me nuts when I first ran into it and it has affected almost every Rails developer I've talked to.


Yes, but I've been using Rails long enough to remember when they removed `Post.find_first`, and there was even a time when `Post.find(:first)` was the only version - `Post.first` was added late in the 2.x series.


Wow I didn't actually know that. I started using Rails seriously around 2.3 so I always wondered why everyone was always using find(:first) instead of just first. I never even knew about #find_first!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: