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.rb32
1 files changed, 8 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index c113957faa..e73f940334 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -42,11 +42,15 @@ module ActiveRecord
@association.load_target
end
+ # Returns +true+ if the association has been loaded, otherwise +false+.
+ #
+ # person.pets.loaded? # => false
+ # person.pets
+ # person.pets.loaded? # => true
def loaded?
@association.loaded?
end
- ##
# Works in two ways.
#
# *First:* Specify a subset of fields to be selected from the result set.
@@ -104,9 +108,8 @@ module ActiveRecord
@association.select(select, &block)
end
- ##
# Finds an object in the collection responding to the +id+. Uses the same
- # rules as +ActiveRecord::Base.find+. Returns +ActiveRecord::RecordNotFound++
+ # rules as <tt>ActiveRecord::Base.find</tt>. Returns <tt>ActiveRecord::RecordNotFound</tt>
# error if the object can not be found.
#
# class Person < ActiveRecord::Base
@@ -135,7 +138,6 @@ module ActiveRecord
@association.find(*args, &block)
end
- ##
# Returns the first record, or the first +n+ records, from the collection.
# If the collection is empty, the first form returns +nil+, and the second
# form returns an empty array.
@@ -166,7 +168,6 @@ module ActiveRecord
@association.first(*args)
end
- ##
# Returns the last record, or the last +n+ records, from the collection.
# If the collection is empty, the first form returns +nil+, and the second
# form returns an empty array.
@@ -197,7 +198,6 @@ module ActiveRecord
@association.last(*args)
end
- ##
# Returns a new object of the collection type that has been instantiated
# with +attributes+ and linked to this object, but have not yet been saved.
# You can pass an array of attributes hashes, this will return an array
@@ -226,7 +226,6 @@ module ActiveRecord
@association.build(attributes, &block)
end
- ##
# Returns a new object of the collection type that has been instantiated with
# attributes, linked to this object and that has already been saved (if it
# passes the validations).
@@ -257,7 +256,6 @@ module ActiveRecord
@association.create(attributes, &block)
end
- ##
# Like +create+, except that if the record is invalid, raises an exception.
#
# class Person
@@ -274,7 +272,6 @@ module ActiveRecord
@association.create!(attributes, &block)
end
- ##
# Add one or more records to the collection by setting their foreign keys
# to the association's primary key. Since << flattens its argument list and
# inserts each record, +push+ and +concat+ behave identically. Returns +self+
@@ -303,7 +300,6 @@ module ActiveRecord
@association.concat(*records)
end
- ##
# Replace this collection with +other_array+. This will perform a diff
# and delete/add only records that have changed.
#
@@ -330,7 +326,6 @@ module ActiveRecord
@association.replace(other_array)
end
- ##
# Deletes all the records from the collection. For +has_many+ associations,
# the deletion is done according to the strategy specified by the <tt>:dependent</tt>
# option. Returns an array with the deleted records.
@@ -423,7 +418,6 @@ module ActiveRecord
@association.delete_all
end
- ##
# Deletes the records of the collection directly from the database.
# This will _always_ remove the records ignoring the +:dependent+
# option.
@@ -450,7 +444,6 @@ module ActiveRecord
@association.destroy_all
end
- ##
# Deletes the +records+ supplied and removes them from the collection. For
# +has_many+ associations, the deletion is done according to the strategy
# specified by the <tt>:dependent</tt> option. Returns an array with the
@@ -514,7 +507,7 @@ module ActiveRecord
# Pet.find(1, 3)
# # => ActiveRecord::RecordNotFound: Couldn't find all Pets with IDs (1, 3)
#
- # If it is set to <tt>:delete_all</tt>, all the +records+ are deleted
+ # If it is set to <tt>:delete_all</tt>, all the +records+ are deleted
# *without* calling their +destroy+ method.
#
# class Person < ActiveRecord::Base
@@ -569,7 +562,6 @@ module ActiveRecord
@association.delete(*records)
end
- ##
# Destroys the +records+ supplied and removes them from the collection.
# This method will _always_ remove record from the database ignoring
# the +:dependent+ option. Returns an array with the removed records.
@@ -642,7 +634,6 @@ module ActiveRecord
@association.destroy(*records)
end
- ##
# Specifies whether the records should be unique or not.
#
# class Person < ActiveRecord::Base
@@ -661,7 +652,6 @@ module ActiveRecord
@association.uniq
end
- ##
# Count all records using SQL.
#
# class Person < ActiveRecord::Base
@@ -679,7 +669,6 @@ module ActiveRecord
@association.count(column_name, options)
end
- ##
# Returns the size of the collection. If the collection hasn't been loaded,
# it executes a <tt>SELECT COUNT(*)</tt> query.
#
@@ -704,7 +693,6 @@ module ActiveRecord
@association.size
end
- ##
# Returns the size of the collection calling +size+ on the target.
# If the collection has been already loaded, +length+ and +size+ are
# equivalent.
@@ -728,7 +716,6 @@ module ActiveRecord
@association.length
end
- ##
# Returns +true+ if the collection is empty.
#
# class Person < ActiveRecord::Base
@@ -746,7 +733,6 @@ module ActiveRecord
@association.empty?
end
- ##
# Returns +true+ if the collection is not empty.
#
# class Person < ActiveRecord::Base
@@ -780,7 +766,6 @@ module ActiveRecord
@association.any?(&block)
end
- ##
# Returns true if the collection has more than one record.
# Equivalent to <tt>collection.size > 1</tt>.
#
@@ -819,7 +804,6 @@ module ActiveRecord
@association.many?(&block)
end
- ##
# Returns +true+ if the given object is present in the collection.
#
# class Person < ActiveRecord::Base
@@ -889,7 +873,7 @@ module ActiveRecord
end
# Returns a new array of objects from the collection. If the collection
- # hasn't been loaded, it fetches the records from the database.
+ # hasn't been loaded, it fetches the records from the database.
#
# class Person < ActiveRecord::Base
# has_many :pets