From 44717a9d548c95c7b01e7e0dce061257b3a93646 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 2 Jan 2013 04:42:47 +0900 Subject: [PATCH] find_last_by is deprecated in AR 4 --- activerecord/lib/active_record/base.rb | 7 +++---- guides/source/active_record_querying.md | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 8285261e3e..3d374fe9b4 100644 --- a/activerecord/lib/active_record/base.rb +++ b/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 find_by_, or find_last_by_ and thus produces finders - # like Person.find_by_user_name, and # Payment.find_by_transaction_id. Instead of writing - # Person.where(user_name: user_name).first, you just do Person.find_by_user_name(user_name). + # to find_by_ # like Person.find_by_user_name. + # Instead of writing # Person.where(user_name: user_name).first, you just do + # Person.find_by_user_name(user_name). # # It's possible to add 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, @@ -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 find_or_create_by_ and will return the object if diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 618dd2652b..62d6294ae5 100644 --- a/guides/source/active_record_querying.md +++ b/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)`.