From fe48c97e26e68fb32c5980416f8e3a1f4c57a479 Mon Sep 17 00:00:00 2001
From: Ryuta Kamizono <kamipo@gmail.com>
Date: Mon, 25 Jul 2016 00:15:32 +0900
Subject: `FinderMethods` uses `records` (`load_target`) when `loaded?` is true

---
 activerecord/lib/active_record/associations/collection_proxy.rb | 2 +-
 activerecord/lib/active_record/relation/finder_methods.rb       | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

(limited to 'activerecord/lib')

diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index db3037d8f9..56dee10df2 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -29,7 +29,7 @@ module ActiveRecord
     # instantiation of the actual post records.
     class CollectionProxy < Relation
       delegate(*(ActiveRecord::Calculations.public_instance_methods - [:count]), to: :scope)
-      delegate :find_nth, :exists?, :update_all, :arel, to: :scope
+      delegate :exists?, :update_all, :arel, to: :scope
 
       def initialize(klass, association) #:nodoc:
         @association = association
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index d255cad91b..916dca33bd 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -514,7 +514,7 @@ module ActiveRecord
 
     def find_take
       if loaded?
-        @records.first
+        records.first
       else
         @take ||= limit(1).records.first
       end
@@ -531,7 +531,7 @@ module ActiveRecord
         MSG
       end
       if loaded?
-        @records[index]
+        records[index]
       else
         offset ||= offset_index
         @offsets[offset + index] ||= find_nth_with_limit_and_offset(index, 1, offset: offset).first
@@ -557,7 +557,7 @@ module ActiveRecord
 
     def find_nth_from_last(index)
       if loaded?
-        @records[-index]
+        records[-index]
       else
         relation = if order_values.empty? && primary_key
                      order(arel_attribute(primary_key).asc)
@@ -578,7 +578,7 @@ module ActiveRecord
 
     def find_nth_with_limit_and_offset(index, limit, offset:) # :nodoc:
       if loaded?
-        @records[index, limit]
+        records[index, limit]
       else
         index += offset
         find_nth_with_limit(index, limit)
-- 
cgit v1.2.3