Skip to content
This repository
Browse code

copy edits in collection proxy docs [ci skip]

  • Loading branch information...
commit 1c94868033c631dcb44d705f70433a64d48e0938 1 parent d31b765
Vijay Dev authored May 23, 2012
43  activerecord/lib/active_record/associations/collection_proxy.rb
@@ -92,6 +92,10 @@ class CollectionProxy < Relation
92 92
       #   #    ]
93 93
       #
94 94
       #   person.pets.select(:name) { |pet| pet.name =~ /oo/ }
  95
+      #   # => [
  96
+      #   #      #<Pet id: 2, name: "Spook">,
  97
+      #   #      #<Pet id: 3, name: "Choo-Choo">
  98
+      #   #    ]
95 99
 
96 100
       ##
97 101
       # :method: find
@@ -113,7 +117,7 @@ class CollectionProxy < Relation
113 117
       #   #       #<Pet id: 2, name: "Spook", person_id: 1>,
114 118
       #   #       #<Pet id: 3, name: "Choo-Choo", person_id: 1>
115 119
       #   #    ]
116  
-      #   
  120
+      #
117 121
       #   person.pets.find(1) # => #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>
118 122
       #   person.pets.find(4) # => ActiveRecord::RecordNotFound: Couldn't find Pet with id=4
119 123
       #
@@ -231,7 +235,7 @@ class CollectionProxy < Relation
231 235
       #
232 236
       # Returns a new object of the collection type that has been instantiated with
233 237
       # attributes, linked to this object and that has already been saved (if it
234  
-      # passed the validations).
  238
+      # passes the validations).
235 239
       #
236 240
       #   class Person
237 241
       #     has_many :pets
@@ -255,15 +259,14 @@ class CollectionProxy < Relation
255 259
       #   #       #<Pet id: 2, name: "Spook", person_id: 1>,
256 260
       #   #       #<Pet id: 3, name: "Choo-Choo", person_id: 1>
257 261
       #   #    ]
258  
-      
  262
+
259 263
       ##
260 264
       # :method: create!
261 265
       #
262 266
       # :call-seq:
263 267
       #   create!(attributes = {}, options = {}, &block)
264 268
       #
265  
-      # Like +create+, except that if the record is invalid will
266  
-      # raise an exception.
  269
+      # Like +create+, except that if the record is invalid, raises an exception.
267 270
       #
268 271
       #   class Person
269 272
       #     has_many :pets
@@ -340,8 +343,8 @@ class CollectionProxy < Relation
340 343
       ##
341 344
       # :method: delete_all
342 345
       #
343  
-      # Deletes all the records from the collection. For +has_many+ it will do the
344  
-      # deletion according to the strategy specified by the <tt>:dependent</tt>
  346
+      # Deletes all the records from the collection. For +has_many+ asssociations,
  347
+      # the deletion is done according to the strategy specified by the <tt>:dependent</tt>
345 348
       # option. Returns an array with the deleted records.
346 349
       #
347 350
       # If no <tt>:dependent</tt> option is given, then it will follow the
@@ -501,7 +504,7 @@ class CollectionProxy < Relation
501 504
       # You can pass +Fixnum+ or +String+ values, it finds the records
502 505
       # responding to the +id+ and then deletes them from the database.
503 506
       #
504  
-      #   person.pets.size # => 3  
  507
+      #   person.pets.size # => 3
505 508
       #   person.pets
506 509
       #   # => [
507 510
       #   #       #<Pet id: 4, name: "Benny", person_id: 1>,
@@ -529,7 +532,7 @@ class CollectionProxy < Relation
529 532
       #   person.pets       # => []
530 533
       #
531 534
       #   Pet.find(4, 5, 6) # => ActiveRecord::RecordNotFound: Couldn't find all Pets with IDs (4, 5, 6)
532  
-      
  535
+
533 536
       ##
534 537
       # :method: size
535 538
       #
@@ -541,11 +544,7 @@ class CollectionProxy < Relation
541 544
       #   end
542 545
       #
543 546
       #   person.pets.size # => 3
544  
-      #   # Executes:
545  
-      #   #
546  
-      #   #   SELECT COUNT(*)
547  
-      #   #     FROM "pets"
548  
-      #   #    WHERE "pets"."person_id" = 1
  547
+      #   # executes something like SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" = 1
549 548
       #
550 549
       #   person.pets # This will execute a SELECT * FROM query
551 550
       #   # => [
@@ -562,24 +561,18 @@ class CollectionProxy < Relation
562 561
       # :method: length
563 562
       #
564 563
       # Returns the size of the collection calling +size+ on the target.
565  
-      # If the collection has been already loaded +length+ and +size+ are
566  
-      # equivalent. If not and you are going to need the records anyway this
567  
-      # method will take one less query because loads the collection. Otherwise
568  
-      # +size+ is more efficient.
  564
+      # If the collection has been already loaded, +length+ and +size+ are
  565
+      # equivalent.
569 566
       #
570 567
       #   class Person < ActiveRecord::Base
571 568
       #     has_many :pets
572 569
       #   end
573 570
       #
574 571
       #   person.pets.length # => 3
575  
-      #   # Executes:
576  
-      #   #
577  
-      #   #   SELECT "pets".*
578  
-      #   #     FROM "pets"
579  
-      #   #    WHERE "pets"."person_id" = 1
  572
+      #   # executes something like SELECT "pets".* FROM "pets" WHERE "pets"."person_id" = 1
580 573
       #
581 574
       #   # Because the collection is loaded, you can
582  
-      #   # call the collection without execute a query:
  575
+      #   # call the collection with no additional queries:
583 576
       #   person.pets
584 577
       #   # => [
585 578
       #   #       #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
@@ -705,7 +698,7 @@ class CollectionProxy < Relation
705 698
                :sum, :count, :size, :length, :empty?,
706 699
                :any?, :many?, :include?,
707 700
                :to => :@association
708  
-  
  701
+
709 702
       def initialize(association)
710 703
         @association = association
711 704
         super association.klass, association.klass.arel_table

0 notes on commit 1c94868

Please sign in to comment.
Something went wrong with that request. Please try again.