Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

find_last_by is deprecated in AR 4

  • Loading branch information...
commit 44717a9d548c95c7b01e7e0dce061257b3a93646 1 parent ad82753
@amatsuda amatsuda authored
View
7 activerecord/lib/active_record/base.rb
@@ -162,9 +162,9 @@ module ActiveRecord #:nodoc:
#
# 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
- # to <tt>find_by_</tt>, or <tt>find_last_by_</tt> and thus produces finders
- # like <tt>Person.find_by_user_name</tt>, and # <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>.
+ # to <tt>find_by_</tt> # like <tt>Person.find_by_user_name</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>.
#
# 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,
@@ -178,7 +178,6 @@ module ActiveRecord #:nodoc:
# It's even possible to call these dynamic finder methods on relations and named scopes.
#
# Payment.order("created_on").find_by_amount(50)
- # 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.
# This dynamic finder is called with <tt>find_or_create_by_</tt> and will return the object if
View
2  guides/source/active_record_querying.md
@@ -1230,8 +1230,6 @@ 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` 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 specify an exclamation point (`!`) on the end of the dynamic finders to get them to raise an `ActiveRecord::RecordNotFound` error if they do not return any records, like `Client.find_by_name!("Ryan")`
If you want to find both by name and locked, you can chain these finders together by simply typing "`and`" between the fields. For example, `Client.find_by_first_name_and_locked("Ryan", true)`.
Please sign in to comment.
Something went wrong with that request. Please try again.