activerecord 3.0.0.beta → 3.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (53) hide show
  1. data/CHANGELOG +8 -1
  2. data/lib/active_record.rb +9 -6
  3. data/lib/active_record/aggregations.rb +5 -0
  4. data/lib/active_record/association_preload.rb +7 -2
  5. data/lib/active_record/associations.rb +74 -54
  6. data/lib/active_record/associations/association_collection.rb +1 -0
  7. data/lib/active_record/associations/association_proxy.rb +2 -1
  8. data/lib/active_record/associations/has_many_association.rb +4 -0
  9. data/lib/active_record/associations/has_many_through_association.rb +1 -0
  10. data/lib/active_record/attribute_methods/dirty.rb +11 -9
  11. data/lib/active_record/attribute_methods/primary_key.rb +6 -0
  12. data/lib/active_record/attribute_methods/query.rb +2 -0
  13. data/lib/active_record/base.rb +57 -212
  14. data/lib/active_record/callbacks.rb +10 -0
  15. data/lib/active_record/connection_adapters/abstract/database_statements.rb +24 -1
  16. data/lib/active_record/connection_adapters/abstract/query_cache.rb +2 -0
  17. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +10 -5
  18. data/lib/active_record/connection_adapters/abstract_adapter.rb +1 -0
  19. data/lib/active_record/connection_adapters/mysql_adapter.rb +22 -5
  20. data/lib/active_record/connection_adapters/postgresql_adapter.rb +34 -8
  21. data/lib/active_record/dynamic_finder_match.rb +3 -0
  22. data/lib/active_record/errors.rb +165 -0
  23. data/lib/active_record/fixtures.rb +1 -0
  24. data/lib/active_record/migration.rb +8 -6
  25. data/lib/active_record/named_scope.rb +14 -5
  26. data/lib/active_record/nested_attributes.rb +6 -2
  27. data/lib/active_record/query_cache.rb +2 -0
  28. data/lib/active_record/railtie.rb +30 -19
  29. data/lib/active_record/railties/databases.rake +13 -7
  30. data/lib/active_record/railties/{subscriber.rb → log_subscriber.rb} +7 -2
  31. data/lib/active_record/reflection.rb +5 -3
  32. data/lib/active_record/relation.rb +13 -2
  33. data/lib/active_record/relation/batches.rb +84 -0
  34. data/lib/active_record/relation/calculations.rb +2 -0
  35. data/lib/active_record/relation/finder_methods.rb +13 -2
  36. data/lib/active_record/relation/predicate_builder.rb +2 -7
  37. data/lib/active_record/relation/query_methods.rb +20 -27
  38. data/lib/active_record/relation/spawn_methods.rb +18 -28
  39. data/lib/active_record/schema.rb +2 -0
  40. data/lib/active_record/validations/uniqueness.rb +2 -4
  41. data/lib/active_record/version.rb +3 -2
  42. data/lib/{generators → rails/generators}/active_record.rb +0 -0
  43. data/lib/{generators → rails/generators}/active_record/migration/migration_generator.rb +1 -1
  44. data/lib/{generators → rails/generators}/active_record/migration/templates/migration.rb +0 -0
  45. data/lib/{generators → rails/generators}/active_record/model/model_generator.rb +1 -1
  46. data/lib/{generators → rails/generators}/active_record/model/templates/migration.rb +0 -0
  47. data/lib/{generators → rails/generators}/active_record/model/templates/model.rb +0 -0
  48. data/lib/{generators → rails/generators}/active_record/observer/observer_generator.rb +1 -1
  49. data/lib/{generators → rails/generators}/active_record/observer/templates/observer.rb +0 -0
  50. data/lib/{generators → rails/generators}/active_record/session_migration/session_migration_generator.rb +1 -1
  51. data/lib/{generators → rails/generators}/active_record/session_migration/templates/migration.rb +0 -0
  52. metadata +61 -34
  53. data/lib/active_record/batches.rb +0 -79
@@ -1,79 +0,0 @@
1
- module ActiveRecord
2
- module Batches # :nodoc:
3
- extend ActiveSupport::Concern
4
-
5
- # When processing large numbers of records, it's often a good idea to do
6
- # so in batches to prevent memory ballooning.
7
- module ClassMethods
8
- # Yields each record that was found by the find +options+. The find is
9
- # performed by find_in_batches with a batch size of 1000 (or as
10
- # specified by the <tt>:batch_size</tt> option).
11
- #
12
- # Example:
13
- #
14
- # Person.find_each(:conditions => "age > 21") do |person|
15
- # person.party_all_night!
16
- # end
17
- #
18
- # Note: This method is only intended to use for batch processing of
19
- # large amounts of records that wouldn't fit in memory all at once. If
20
- # you just need to loop over less than 1000 records, it's probably
21
- # better just to use the regular find methods.
22
- def find_each(options = {})
23
- find_in_batches(options) do |records|
24
- records.each { |record| yield record }
25
- end
26
-
27
- self
28
- end
29
-
30
- # Yields each batch of records that was found by the find +options+ as
31
- # an array. The size of each batch is set by the <tt>:batch_size</tt>
32
- # option; the default is 1000.
33
- #
34
- # You can control the starting point for the batch processing by
35
- # supplying the <tt>:start</tt> option. This is especially useful if you
36
- # want multiple workers dealing with the same processing queue. You can
37
- # make worker 1 handle all the records between id 0 and 10,000 and
38
- # worker 2 handle from 10,000 and beyond (by setting the <tt>:start</tt>
39
- # option on that worker).
40
- #
41
- # It's not possible to set the order. That is automatically set to
42
- # ascending on the primary key ("id ASC") to make the batch ordering
43
- # work. This also mean that this method only works with integer-based
44
- # primary keys. You can't set the limit either, that's used to control
45
- # the the batch sizes.
46
- #
47
- # Example:
48
- #
49
- # Person.find_in_batches(:conditions => "age > 21") do |group|
50
- # sleep(50) # Make sure it doesn't get too crowded in there!
51
- # group.each { |person| person.party_all_night! }
52
- # end
53
- def find_in_batches(options = {})
54
- raise "You can't specify an order, it's forced to be #{batch_order}" if options[:order]
55
- raise "You can't specify a limit, it's forced to be the batch_size" if options[:limit]
56
-
57
- start = options.delete(:start).to_i
58
- batch_size = options.delete(:batch_size) || 1000
59
-
60
- with_scope(:find => options.merge(:order => batch_order, :limit => batch_size)) do
61
- records = find(:all, :conditions => [ "#{table_name}.#{primary_key} >= ?", start ])
62
-
63
- while records.any?
64
- yield records
65
-
66
- break if records.size < batch_size
67
- records = find(:all, :conditions => [ "#{table_name}.#{primary_key} > ?", records.last.id ])
68
- end
69
- end
70
- end
71
-
72
-
73
- private
74
- def batch_order
75
- "#{table_name}.#{primary_key} ASC"
76
- end
77
- end
78
- end
79
- end