1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

find_all_by is deprecated in AR 4

This commit is contained in:
Akira Matsuda 2013-01-02 04:36:33 +09:00
parent 545ee23f0a
commit ad8275396a
3 changed files with 5 additions and 9 deletions

View file

@ -162,12 +162,9 @@ module ActiveRecord #:nodoc:
# #
# Dynamic attribute-based finders are a cleaner way of getting (and/or creating) objects # Dynamic attribute-based finders are a cleaner way of getting (and/or creating) objects
# by simple queries without turning to SQL. They work by appending the name of an attribute # by simple queries without turning to SQL. They work by appending the name of an attribute
# to <tt>find_by_</tt>, <tt>find_last_by_</tt>, or <tt>find_all_by_</tt> and thus produces finders # to <tt>find_by_</tt>, or <tt>find_last_by_</tt> and thus produces finders
# like <tt>Person.find_by_user_name</tt>, <tt>Person.find_all_by_last_name</tt>, and # like <tt>Person.find_by_user_name</tt>, and # <tt>Payment.find_by_transaction_id</tt>. Instead of writing
# <tt>Payment.find_by_transaction_id</tt>. Instead of writing
# <tt>Person.where(user_name: user_name).first</tt>, you just do <tt>Person.find_by_user_name(user_name)</tt>. # <tt>Person.where(user_name: user_name).first</tt>, you just do <tt>Person.find_by_user_name(user_name)</tt>.
# And instead of writing <tt>Person.where(last_name: last_name).all</tt>, you just do
# <tt>Person.find_all_by_last_name(last_name)</tt>.
# #
# It's possible to add an exclamation point (!) on the end of the dynamic finders to get them to raise an # It's possible to add an exclamation point (!) on the end of the dynamic finders to get them to raise an
# <tt>ActiveRecord::RecordNotFound</tt> error if they do not return any records, # <tt>ActiveRecord::RecordNotFound</tt> error if they do not return any records,
@ -180,7 +177,7 @@ module ActiveRecord #:nodoc:
# #
# It's even possible to call these dynamic finder methods on relations and named scopes. # It's even possible to call these dynamic finder methods on relations and named scopes.
# #
# Payment.order("created_on").find_all_by_amount(50) # Payment.order("created_on").find_by_amount(50)
# Payment.pending.find_last_by_amount(100) # Payment.pending.find_last_by_amount(100)
# #
# The same dynamic finder style can be used to create the object if it doesn't already exist. # The same dynamic finder style can be used to create the object if it doesn't already exist.

View file

@ -168,7 +168,6 @@ Additionally, the `after_find` callback is triggered by the following finder met
* `all` * `all`
* `first` * `first`
* `find` * `find`
* `find_all_by_*`
* `find_by_*` * `find_by_*`
* `find_by_*!` * `find_by_*!`
* `find_by_sql` * `find_by_sql`
@ -176,7 +175,7 @@ Additionally, the `after_find` callback is triggered by the following finder met
The `after_initialize` callback is triggered every time a new object of the class is initialized. The `after_initialize` callback is triggered every time a new object of the class is initialized.
NOTE: The `find_all_by_*`, `find_by_*` and `find_by_*!` methods are dynamic finders generated automatically for every attribute. Learn more about them at the [Dynamic finders section](active_record_querying.html#dynamic-finders) NOTE: The `find_by_*` and `find_by_*!` methods are dynamic finders generated automatically for every attribute. Learn more about them at the [Dynamic finders section](active_record_querying.html#dynamic-finders)
Skipping Callbacks Skipping Callbacks
------------------ ------------------

View file

@ -1228,7 +1228,7 @@ Client.unscoped {
Dynamic Finders Dynamic Finders
--------------- ---------------
For every field (also known as an attribute) you define in your table, Active Record provides a finder method. If you have a field called `first_name` on your `Client` model for example, you get `find_by_first_name` and `find_all_by_first_name` for free from Active Record. If you have a `locked` field on the `Client` model, you also get `find_by_locked` and `find_all_by_locked` methods. For every field (also known as an attribute) you define in your table, Active Record provides a finder method. If you have a field called `first_name` on your `Client` model for example, you get `find_by_first_name` for free from Active Record. If you have a `locked` field on the `Client` model, you also get `find_by_locked` and methods.
You can also use `find_last_by_*` methods which will find the last record matching your argument. You can also use `find_last_by_*` methods which will find the last record matching your argument.