Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add Finder API changes to upgrading guide #12015

Merged
merged 1 commit into from

5 participants

guides/source/upgrading_ruby_on_rails.md
@@ -172,6 +172,16 @@ this gem such as `whitelist_attributes` or `mass_assignment_sanitizer` options.
* Rails 4.0 has deprecated `ActiveRecord::Fixtures` in favor of `ActiveRecord::FixtureSet`.
* Rails 4.0 has deprecated `ActiveRecord::TestCase` in favor of `ActiveSupport::TestCase`.
+* Rails 4.0 has deprecated the old-style hash based finder API. This means that methods which previously accepted "finder options" no longer do.
+
+* All dynamic methods except for `find_by_...` and `find_by_...!` are deprecated. Here's how you can handle the changes:
@robin850 Collaborator

Could you please wrap these additions around 80 chars?

I did so, since all other lines aren't.

@senny Owner
senny added a note

We are gradually moving to an 80 char limit on the guides. No reason to convert all at once but new stuff and changed stuff should be wrapped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@steveklabnik steveklabnik merged commit c9f834b into rails:master
@garysweaver

where(...) is not an equivalent to the old finders because it returns a relation, so there probably should be a statement below this section with something to the effect of, "Note that where(...) returns a relation, not an array like the old finders. In some cases, the resulting relation can be treated similarly to an array, but if you require an array, use where(...).to_a."

If being really picky, you might also want to include a statement that the SQL executed may not be exactly the same, depending on how it is used.

Feel free to disregard if you'd rather not make changes since it's committed.

@steveklabnik
Collaborator

Sure, if you think this can be further improved, please submit a pull :)

@garysweaver

Ok, cool. Just wanted to make sure it would be a good idea to clarify further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 26, 2013
  1. @vipulnsward
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 0 deletions.
  1. +12 −0 guides/source/upgrading_ruby_on_rails.md
View
12 guides/source/upgrading_ruby_on_rails.md
@@ -172,6 +172,18 @@ this gem such as `whitelist_attributes` or `mass_assignment_sanitizer` options.
* Rails 4.0 has deprecated `ActiveRecord::Fixtures` in favor of `ActiveRecord::FixtureSet`.
* Rails 4.0 has deprecated `ActiveRecord::TestCase` in favor of `ActiveSupport::TestCase`.
+* Rails 4.0 has deprecated the old-style hash based finder API. This means that
+ methods which previously accepted "finder options" no longer do.
+
+* All dynamic methods except for `find_by_...` and `find_by_...!` are deprecated.
+ Here's how you can handle the changes:
+
+ * `find_all_by_...` becomes `where(...)`.
+ * `find_last_by_...` becomes `where(...).last`.
+ * `scoped_by_...` becomes `where(...)`.
+ * `find_or_initialize_by_...` becomes `find_or_initialize_by(...)`.
+ * `find_or_create_by_...` becomes `find_or_create_by(...)`.
+
### Active Resource
Rails 4.0 extracted Active Resource to its own gem. If you still need the feature you can add the [Active Resource gem](https://github.com/rails/activeresource) in your Gemfile.
Something went wrong with that request. Please try again.