Skip to content
This repository
Browse code

add changelogs about deprecated stuff [ci skip]

  • Loading branch information...
commit 103ce300ec7507d235ca31efe61033f0b7a601c0 1 parent 62c6ac2
Jon Leighton authored May 18, 2012

Showing 1 changed file with 55 additions and 1 deletion. Show diff stats Hide diff stats

  1. 56  activerecord/CHANGELOG.md
56  activerecord/CHANGELOG.md
Source Rendered
... ...
@@ -1,10 +1,64 @@
1 1
 ## Rails 4.0.0 (unreleased) ##
2 2
 
  3
+*   Deprecated most of the 'dynamic finder' methods. All dynamic methods
  4
+    except for `find_by_...` and `find_by_...!` are deprecated. Here's
  5
+    how you can rewrite the code:
  6
+
  7
+      * `find_all_by_...` can be rewritten using `where(...)`
  8
+      * `find_last_by_...` can be rewritten using `where(...).last`
  9
+      * `scoped_by_...` can be rewritten using `where(...)`
  10
+      * `find_or_initialize_by_...` can be rewritten using
  11
+        `where(...).first_or_initialize`
  12
+      * `find_or_create_by_...` can be rewritten using
  13
+        `where(...).first_or_create!`
  14
+      * `find_or_create_by_...!` can be rewritten using
  15
+        `where(...).first_or_create!`
  16
+
  17
+    The implementation of the deprecated dynamic finders has been moved
  18
+    to the `active_record_deprecated_finders` gem. See below for details.
  19
+
  20
+    *Jon Leighton*
  21
+
  22
+*   Deprecated the old-style hash based finder API. This means that
  23
+    methods which previously accepted "finder options" no longer do. For
  24
+    example this:
  25
+
  26
+        Post.find(:all, :conditions => { :comments_count => 10 }, :limit => 5)
  27
+
  28
+    Should be rewritten in the new style which has existed since Rails 3:
  29
+
  30
+        Post.where(comments_count: 10).limit(5)
  31
+
  32
+    Note that as an interim step, it is possible to rewrite the above as:
  33
+
  34
+        Post.scoped(:where => { :comments_count => 10 }, :limit => 5)
  35
+
  36
+    This could save you a lot of work if there is a lot of old-style
  37
+    finder usage in your application.
  38
+
  39
+    Calling `Post.scoped(options)` is a shortcut for
  40
+    `Post.scoped.merge(options)`. `Relation#merge` now accepts a hash of
  41
+    options, but they must be identical to the names of the equivalent
  42
+    finder method. These are mostly identical to the old-style finder
  43
+    option names, except in the following cases:
  44
+
  45
+      * `:conditions` becomes `:where`
  46
+      * `:include` becomes `:includes`
  47
+      * `:extend` becomes `:extending`
  48
+
  49
+    The code to implement the deprecated features has been moved out to
  50
+    the `active_record_deprecated_finders` gem. This gem is a dependency
  51
+    of Active Record in Rails 4.0. It will no longer be a dependency
  52
+    from Rails 4.1, but if your app relies on the deprecated features
  53
+    then you can add it to your own Gemfile. It will be maintained by
  54
+    the Rails core team until Rails 5.0 is released.
  55
+
  56
+    *Jon Leighton*
  57
+
3 58
 *   It's not possible anymore to destroy a model marked as read only.
4 59
 
5 60
     *Johannes Barre*
6 61
 
7  
-
8 62
 *   Added ability to ActiveRecord::Relation#from to accept other ActiveRecord::Relation objects
9 63
 
10 64
       Record.from(subquery)

4 notes on commit 103ce30

Carlos Antonio da Silva

I think the ! shouldn't be here, not?

Jon Leighton

confirm, thanks for proof reading :)

Jeff Cohen

Why is removing dynamic finders a good idea? They have long been an excellent example of the type of DSL that Rails has often espoused.

They are also easy to use, easy to read, and for beginners, and provide a nice stepping stone to understanding how where clauses work.

Is there a technical reason for their removal that I'm overlooking?

Brian Hall

Unless I'm missing something, the answer is right there in the code comments - They're trivial to write using #where

Piotr Sarnacki
Collaborator

@JeffCohen DSLs should be used if they give you advantage over regular code. In this case dynamic finders does not give you a lot and they use method missing (which is not bad as a rule, but I think that it should not be used when it's not needed). Also, this is a matter of taste, but for me using where looks cleaner than using long method:

User.find_all_by_first_name_and_last_name 'Piotr', 'Sarnacki'
# vs.
User.where(first_name: 'Piotr', last_name: 'Sarnacki')

It turns out to also be shorter ;)

Jeff Cohen

@grumpit and @drogus thanks for the replies. I still think the fluid form reveals the intention better than a where clause with a hash, even though I'm usually all for shorter code :-)

Please sign in to comment.
Something went wrong with that request. Please try again.