From 390d86ae899f6aba735d8efa0f7f23e05c6957a5 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 25 May 2012 22:18:56 -0500 Subject: add CollectionProxy#to_ary documentation --- .../active_record/associations/collection_proxy.rb | 37 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 2b59b07eb2..5b5aef070d 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -470,7 +470,7 @@ module ActiveRecord # :call-seq: # delete(*records) # - # Deletes the +records+ supplied and remove them from the collection. For + # 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 :dependent option. Returns an array with the # deleted records. @@ -567,7 +567,7 @@ module ActiveRecord # :call-seq: # destroy(*records) # - # Destroys the +records+ supplied and remove them from the collection. + # 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. # @@ -838,6 +838,39 @@ module ActiveRecord load_target == other end + # Returns a new array of objects from the collection. If the collection + # hasn't been loaded, it fetches the records from the database. + # + # class Person < ActiveRecord::Base + # has_many :pets + # end + # + # person.pets + # # => [ + # # #, + # # #, + # # # + # # ] + # + # other_pets = person.pets.to_ary + # # => [ + # # #, + # # #, + # # # + # # ] + # + # other_pets.replace([Pet.new(name: 'BooGoo')]) + # + # other_pets + # # => [#] + # + # person.pets + # # This is not affected by replace + # # => [ + # # #, + # # #, + # # # + # # ] def to_ary load_target.dup end -- cgit v1.2.3