From d138921cece0c4923849ff61100fcce56e98e967 Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Sun, 27 May 2012 08:25:00 -0700 Subject: "a sql" -> "an SQL" per API documentation guidelines --- activerecord/lib/active_record/relation/calculations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 31d99f0192..ab32bfe70a 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -118,7 +118,7 @@ module ActiveRecord # Person.all.map(&:name) # # Pluck returns an Array of attribute values type-casted to match - # the plucked column name, if it can be deduced. Plucking a SQL fragment + # the plucked column name, if it can be deduced. Plucking an SQL fragment # returns String values by default. # # Examples: -- cgit v1.2.3 From 011863673a353c334ddb2c93227dceadc5d7c3b6 Mon Sep 17 00:00:00 2001 From: Alvaro Pereyra Date: Mon, 28 May 2012 02:28:35 -0500 Subject: Adds examples to FinderMethods#first [ci skip] --- activerecord/lib/active_record/relation/finder_methods.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 9d62e726d4..c1783dba72 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -87,6 +87,7 @@ module ActiveRecord # Person.where(["user_name = ?", user_name]).first # Person.where(["user_name = :u", { :u => user_name }]).first # Person.order("created_on DESC").offset(5).first + # Person.first(3) # returns the first objects fetched by SELECT * FROM people LIMIT 3 def first(limit = nil) if limit if order_values.empty? && primary_key -- cgit v1.2.3 From 19de3d8d7fe623b8c9d67676f8113296ebdbb640 Mon Sep 17 00:00:00 2001 From: Alvaro Pereyra Date: Mon, 28 May 2012 02:51:47 -0500 Subject: Updates examples for FinderMethods [ci skip] --- .../lib/active_record/relation/finder_methods.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 0abb801074..3d6a7a9d86 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -88,7 +88,7 @@ module ActiveRecord # Person.where(["user_name = ?", user_name]).first # Person.where(["user_name = :u", { :u => user_name }]).first # Person.order("created_on DESC").offset(5).first - # Person.first(3) # returns the first objects fetched by SELECT * FROM people LIMIT 3 + # Person.first(3) # returns the first 3 objects fetched by SELECT * FROM people LIMIT 3 def first(limit = nil) if limit if order_values.empty? && primary_key @@ -115,6 +115,15 @@ module ActiveRecord # Person.last # returns the last object fetched by SELECT * FROM people # Person.where(["user_name = ?", user_name]).last # Person.order("created_on DESC").offset(5).last + # Person.last(3) # returns the last 3 objects fetched by SELECT * FROM people. + # + # Take note that in that last case, the results are sorted in ascending order: + # + # [#, #, #] + # + # and not + # + # [#, #, #] def last(limit = nil) if limit if order_values.empty? && primary_key @@ -133,6 +142,9 @@ module ActiveRecord last or raise RecordNotFound end + # Runs the query on the database and returns records with the used query + # methods. + # # Examples: # # Person.all # returns an array of objects for all the rows fetched by SELECT * FROM people @@ -167,8 +179,8 @@ module ActiveRecord # ==== Examples # Person.exists?(5) # Person.exists?('5') - # Person.exists?(:name => "David") # Person.exists?(['name LIKE ?', "%#{query}%"]) + # Person.exists?(:name => "David") # Person.exists? def exists?(id = false) id = id.id if ActiveRecord::Model === id -- cgit v1.2.3 From a3d18d2ec0d73ed8eb92c913e324884aab7aa85b Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Mon, 28 May 2012 02:55:11 -0500 Subject: fix typo and remove 'examples' noise [ci skip] --- .../lib/active_record/relation/finder_methods.rb | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 3d6a7a9d86..5f6898b45a 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -7,8 +7,6 @@ module ActiveRecord # If no record can be found for all of the listed ids, then RecordNotFound will be raised. If the primary key # is an integer, find by id coerces its arguments using +to_i+. # - # ==== Examples - # # Person.find(1) # returns the object for ID = 1 # Person.find("1") # returns the object for ID = 1 # Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6) @@ -49,7 +47,6 @@ module ActiveRecord # # Post.find_by name: 'Spartacus', rating: 4 # Post.find_by "published_at < ?", 2.weeks.ago - # def find_by(*args) where(*args).take end @@ -64,8 +61,6 @@ module ActiveRecord # order. The order will depend on the database implementation. # If an order is supplied it will be respected. # - # Examples: - # # Person.take # returns an object fetched by SELECT * FROM people # Person.take(5) # returns 5 objects fetched by SELECT * FROM people LIMIT 5 # Person.where(["name LIKE '%?'", name]).take @@ -82,13 +77,11 @@ module ActiveRecord # Find the first record (or first N records if a parameter is supplied). # If no order is defined it will order by primary key. # - # Examples: - # # Person.first # returns the first object fetched by SELECT * FROM people # Person.where(["user_name = ?", user_name]).first # Person.where(["user_name = :u", { :u => user_name }]).first # Person.order("created_on DESC").offset(5).first - # Person.first(3) # returns the first 3 objects fetched by SELECT * FROM people LIMIT 3 + # Person.first(3) # returns the first three objects fetched by SELECT * FROM people LIMIT 3 def first(limit = nil) if limit if order_values.empty? && primary_key @@ -110,20 +103,18 @@ module ActiveRecord # Find the last record (or last N records if a parameter is supplied). # If no order is defined it will order by primary key. # - # Examples: - # # Person.last # returns the last object fetched by SELECT * FROM people # Person.where(["user_name = ?", user_name]).last # Person.order("created_on DESC").offset(5).last - # Person.last(3) # returns the last 3 objects fetched by SELECT * FROM people. + # Person.last(3) # returns the last three objects fetched by SELECT * FROM people. # - # Take note that in that last case, the results are sorted in ascending order: + # Take note that in that last case, the results are sorted in ascending order: # - # [#, #, #] + # [#, #, #] # - # and not + # and not: # - # [#, #, #] + # [#, #, #] def last(limit = nil) if limit if order_values.empty? && primary_key @@ -145,8 +136,6 @@ module ActiveRecord # Runs the query on the database and returns records with the used query # methods. # - # Examples: - # # Person.all # returns an array of objects for all the rows fetched by SELECT * FROM people # Person.where(["category IN (?)", categories]).limit(50).all # Person.where({ :friends => ["Bob", "Steve", "Fred"] }).all @@ -176,7 +165,6 @@ module ActiveRecord # 'Jamie'), since it would be sanitized and then queried against # the primary key column, like id = 'name = \'Jamie\''. # - # ==== Examples # Person.exists?(5) # Person.exists?('5') # Person.exists?(['name LIKE ?', "%#{query}%"]) -- cgit v1.2.3 From 2bef137d99a473e5f6a423bc796bc76b63c9bcf0 Mon Sep 17 00:00:00 2001 From: Alvaro Pereyra Date: Mon, 28 May 2012 03:24:37 -0500 Subject: Adds to Batch processing documentation [ci skip] --- activerecord/lib/active_record/relation/batches.rb | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index 15f838a5ab..7330f1e215 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -2,20 +2,28 @@ require 'active_support/core_ext/object/blank' module ActiveRecord module Batches - # Yields each record that was found by the find +options+. The find is - # performed by find_in_batches with a batch size of 1000 (or as + # Looping through a collection of records from the database + # (using the +all+ method, for example) could be too straneous to your + # memory if you have large amounts of them since it will try + # to instantiate all the objects of it at once. + # + # If that's the case, batch processing methods allow you to still work + # with all the records found by the find +options+ but using groups of + # a batch size (defaulting to 1000) at a time, greatly reducing the use of memory. + # + # The find_each method performs by using +find_in_batches+ with a batch size of 1000 (or as # specified by the :batch_size option). # - # Example: + # Person.all.find_each do |person| + # person.do_awesome_stuff + # end # # Person.where("age > 21").find_each do |person| # person.party_all_night! # end # - # Note: This method is only intended to use for batch processing of - # large amounts of records that wouldn't fit in memory all at once. If - # you just need to loop over less than 1000 records, it's probably - # better just to use the regular find methods. + # If needed, you can also send the :start option to specify + # an offset to control the starting point. def find_each(options = {}) find_in_batches(options) do |records| records.each { |record| yield record } @@ -39,12 +47,15 @@ module ActiveRecord # primary keys. You can't set the limit either, that's used to control # the batch sizes. # - # Example: - # # Person.where("age > 21").find_in_batches do |group| # sleep(50) # Make sure it doesn't get too crowded in there! # group.each { |person| person.party_all_night! } # end + # + # # Let's process the next 2000 party guys + # Person.all.find_in_batches(start: 2000, batch_size: 2000) do |group| + # group.each { |person| person.party_all_night! } + # end def find_in_batches(options = {}) options.assert_valid_keys(:start, :batch_size) -- cgit v1.2.3 From 501d98b812202d87c11a68d0d78d26f6befd47a7 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Mon, 28 May 2012 10:41:42 -0500 Subject: change example on CollectionProxy#delete to accept multiple values --- activerecord/lib/active_record/associations/collection_proxy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 294aa63f75..f6183f8527 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -520,7 +520,7 @@ module ActiveRecord # # # # # ] # - # person.pets.delete([Pet.find(1), Pet.find(3)]) + # person.pets.delete(Pet.find(1), Pet.find(3)) # # => [ # # #, # # # -- cgit v1.2.3 From 032f502f1221129d8446d3e25cd8956469b43456 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 30 May 2012 22:40:49 +0530 Subject: copy edit the batches docs [ci skip] --- activerecord/lib/active_record/relation/batches.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index 7330f1e215..fb4388d4b2 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -3,15 +3,13 @@ require 'active_support/core_ext/object/blank' module ActiveRecord module Batches # Looping through a collection of records from the database - # (using the +all+ method, for example) could be too straneous to your - # memory if you have large amounts of them since it will try - # to instantiate all the objects of it at once. + # (using the +all+ method, for example) is very inefficient + # since it will try to instantiate all the objects at once. # - # If that's the case, batch processing methods allow you to still work - # with all the records found by the find +options+ but using groups of - # a batch size (defaulting to 1000) at a time, greatly reducing the use of memory. + # In that case, batch processing methods allow you to work + # with the records in batches, thereby greatly reducing memory consumption. # - # The find_each method performs by using +find_in_batches+ with a batch size of 1000 (or as + # The find_each method uses find_in_batches with a batch size of 1000 (or as # specified by the :batch_size option). # # Person.all.find_each do |person| @@ -22,7 +20,7 @@ module ActiveRecord # person.party_all_night! # end # - # If needed, you can also send the :start option to specify + # You can also pass the :start option to specify # an offset to control the starting point. def find_each(options = {}) find_in_batches(options) do |records| @@ -52,7 +50,7 @@ module ActiveRecord # group.each { |person| person.party_all_night! } # end # - # # Let's process the next 2000 party guys + # # Let's process the next 2000 records # Person.all.find_in_batches(start: 2000, batch_size: 2000) do |group| # group.each { |person| person.party_all_night! } # end -- cgit v1.2.3