aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_proxy.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_proxy.rb')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb53
1 files changed, 32 insertions, 21 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 806a905323..36f6c1b9c3 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -28,7 +28,6 @@ module ActiveRecord
# is computed directly through SQL and does not trigger by itself the
# instantiation of the actual post records.
class CollectionProxy < Relation
- delegate(*(ActiveRecord::Calculations.public_instance_methods - [:count]), to: :scope)
delegate :exists?, :update_all, :arel, to: :scope
def initialize(klass, association) #:nodoc:
@@ -167,44 +166,44 @@ module ActiveRecord
# another_person_without.pets # => []
# another_person_without.pets.first # => nil
# another_person_without.pets.first(3) # => []
- def first(*args)
- @association.first(*args)
+ def first(limit = nil)
+ @association.first(limit)
end
# Same as #first except returns only the second record.
- def second(*args)
- @association.second(*args)
+ def second
+ @association.second
end
# Same as #first except returns only the third record.
- def third(*args)
- @association.third(*args)
+ def third
+ @association.third
end
# Same as #first except returns only the fourth record.
- def fourth(*args)
- @association.fourth(*args)
+ def fourth
+ @association.fourth
end
# Same as #first except returns only the fifth record.
- def fifth(*args)
- @association.fifth(*args)
+ def fifth
+ @association.fifth
end
# Same as #first except returns only the forty second record.
# Also known as accessing "the reddit".
- def forty_two(*args)
- @association.forty_two(*args)
+ def forty_two
+ @association.forty_two
end
# Same as #first except returns only the third-to-last record.
- def third_to_last(*args)
- @association.third_to_last(*args)
+ def third_to_last
+ @association.third_to_last
end
# Same as #first except returns only the second-to-last record.
- def second_to_last(*args)
- @association.second_to_last(*args)
+ def second_to_last
+ @association.second_to_last
end
# Returns the last record, or the last +n+ records, from the collection.
@@ -233,8 +232,8 @@ module ActiveRecord
# another_person_without.pets # => []
# another_person_without.pets.last # => nil
# another_person_without.pets.last(3) # => []
- def last(*args)
- @association.last(*args)
+ def last(limit = nil)
+ @association.last(limit)
end
# Gives a record (or N records if a parameter is supplied) from the collection
@@ -262,8 +261,8 @@ module ActiveRecord
# another_person_without.pets # => []
# another_person_without.pets.take # => nil
# another_person_without.pets.take(2) # => []
- def take(n = nil)
- @association.take(n)
+ def take(limit = nil)
+ @association.take(limit)
end
# Returns a new object of the collection type that has been instantiated
@@ -738,6 +737,14 @@ module ActiveRecord
@association.count(column_name, &block)
end
+ def calculate(operation, column_name)
+ null_scope? ? scope.calculate(operation, column_name) : super
+ end
+
+ def pluck(*column_names)
+ null_scope? ? scope.pluck(*column_names) : super
+ end
+
# Returns the size of the collection. If the collection hasn't been loaded,
# it executes a <tt>SELECT COUNT(*)</tt> query. Else it calls <tt>collection.size</tt>.
#
@@ -1073,6 +1080,10 @@ module ActiveRecord
private
+ def null_scope?
+ @association.null_scope?
+ end
+
def exec_queries
load_target
end