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,3 +1,5 @@
1
+ require 'active_support/core_ext/object/blank'
2
+
1
3
  module ActiveRecord
2
4
  module Calculations
3
5
  # Count operates using three different approaches.
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/object/blank'
2
+
1
3
  module ActiveRecord
2
4
  module FinderMethods
3
5
  # Find operates with four different retrieval approaches:
@@ -175,7 +177,7 @@ module ActiveRecord
175
177
  end
176
178
 
177
179
  def construct_relation_for_association_find(join_dependency)
178
- relation = except(:includes, :eager_load, :preload, :select).select(@klass.send(:column_aliases, join_dependency))
180
+ relation = except(:includes, :eager_load, :preload, :select).select(column_aliases(join_dependency))
179
181
  apply_join_dependency(relation, join_dependency)
180
182
  end
181
183
 
@@ -184,7 +186,7 @@ module ActiveRecord
184
186
  relation = association.join_relation(relation)
185
187
  end
186
188
 
187
- limitable_reflections = @klass.send(:using_limitable_reflections?, join_dependency.reflections)
189
+ limitable_reflections = using_limitable_reflections?(join_dependency.reflections)
188
190
 
189
191
  if !limitable_reflections && relation.limit_value
190
192
  limited_id_condition = construct_limited_ids_condition(relation.except(:select))
@@ -311,5 +313,14 @@ module ActiveRecord
311
313
  end
312
314
  end
313
315
 
316
+ def column_aliases(join_dependency)
317
+ join_dependency.joins.collect{|join| join.column_names_with_alias.collect{|column_name, aliased_name|
318
+ "#{connection.quote_table_name join.aliased_table_name}.#{connection.quote_column_name column_name} AS #{aliased_name}"}}.flatten.join(", ")
319
+ end
320
+
321
+ def using_limitable_reflections?(reflections)
322
+ reflections.collect(&:collection?).length.zero?
323
+ end
324
+
314
325
  end
315
326
  end
@@ -20,19 +20,14 @@ module ActiveRecord
20
20
  table = Arel::Table.new(table_name, :engine => @engine)
21
21
  end
22
22
 
23
- attribute = table[column] || Arel::Attribute.new(table, column.to_sym)
23
+ attribute = table[column]
24
24
 
25
25
  case value
26
26
  when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope
27
27
  values = value.to_a
28
28
  attribute.in(values)
29
29
  when Range
30
- # TODO : Arel should handle ranges with excluded end.
31
- if value.exclude_end?
32
- [attribute.gteq(value.begin), attribute.lt(value.end)]
33
- else
34
- attribute.in(value)
35
- end
30
+ attribute.in(value)
36
31
  else
37
32
  attribute.eq(value)
38
33
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/object/blank'
2
+
1
3
  module ActiveRecord
2
4
  module QueryMethods
3
5
  extend ActiveSupport::Concern
@@ -6,9 +8,10 @@ module ActiveRecord
6
8
  (ActiveRecord::Relation::ASSOCIATION_METHODS + ActiveRecord::Relation::MULTI_VALUE_METHODS).each do |query_method|
7
9
  attr_accessor :"#{query_method}_values"
8
10
 
11
+ next if [:where, :having].include?(query_method)
9
12
  class_eval <<-CEVAL
10
13
  def #{query_method}(*args)
11
- new_relation = spawn
14
+ new_relation = clone
12
15
  value = Array.wrap(args.flatten).reject {|x| x.blank? }
13
16
  new_relation.#{query_method}_values += value if value.present?
14
17
  new_relation
@@ -19,7 +22,7 @@ module ActiveRecord
19
22
  [:where, :having].each do |query_method|
20
23
  class_eval <<-CEVAL
21
24
  def #{query_method}(*args)
22
- new_relation = spawn
25
+ new_relation = clone
23
26
  value = build_where(*args)
24
27
  new_relation.#{query_method}_values += [*value] if value.present?
25
28
  new_relation
@@ -32,7 +35,7 @@ module ActiveRecord
32
35
 
33
36
  class_eval <<-CEVAL
34
37
  def #{query_method}(value = true)
35
- new_relation = spawn
38
+ new_relation = clone
36
39
  new_relation.#{query_method}_value = value
37
40
  new_relation
38
41
  end
@@ -41,12 +44,12 @@ module ActiveRecord
41
44
  end
42
45
 
43
46
  def lock(locks = true)
44
- relation = spawn
47
+ relation = clone
45
48
  case locks
46
49
  when String, TrueClass, NilClass
47
- spawn.tap {|new_relation| new_relation.lock_value = locks || true }
50
+ clone.tap {|new_relation| new_relation.lock_value = locks || true }
48
51
  else
49
- spawn.tap {|new_relation| new_relation.lock_value = false }
52
+ clone.tap {|new_relation| new_relation.lock_value = false }
50
53
  end
51
54
  end
52
55
 
@@ -133,13 +136,8 @@ module ActiveRecord
133
136
  arel = h.is_a?(String) ? arel.having(h) : arel.having(*h)
134
137
  end
135
138
 
136
- if defined?(@limit_value) && @limit_value.present?
137
- arel = arel.take(@limit_value)
138
- end
139
-
140
- if defined?(@offset_value) && @offset_value.present?
141
- arel = arel.skip(@offset_value)
142
- end
139
+ arel = arel.take(@limit_value) if @limit_value.present?
140
+ arel = arel.skip(@offset_value) if @offset_value.present?
143
141
 
144
142
  @group_values.uniq.each do |g|
145
143
  arel = arel.group(g) if g.present?
@@ -162,19 +160,14 @@ module ActiveRecord
162
160
  arel = arel.project(quoted_table_name + '.*')
163
161
  end
164
162
 
165
- arel =
166
- if defined?(@from_value) && @from_value.present?
167
- arel.from(@from_value)
168
- else
169
- arel.from(quoted_table_name)
170
- end
163
+ arel = @from_value.present? ? arel.from(@from_value) : arel.from(quoted_table_name)
171
164
 
172
165
  case @lock_value
173
166
  when TrueClass
174
167
  arel = arel.lock
175
168
  when String
176
169
  arel = arel.lock(@lock_value)
177
- end
170
+ end if @lock_value.present?
178
171
 
179
172
  arel
180
173
  end
@@ -184,16 +177,16 @@ module ActiveRecord
184
177
 
185
178
  builder = PredicateBuilder.new(table.engine)
186
179
 
187
- conditions = if [String, Array].include?(args.first.class)
188
- @klass.send(:sanitize_sql, args.size > 1 ? args : args.first)
189
- elsif args.first.is_a?(Hash)
190
- attributes = @klass.send(:expand_hash_conditions_for_aggregates, args.first)
180
+ opts = args.first
181
+ case opts
182
+ when String, Array
183
+ @klass.send(:sanitize_sql, args.size > 1 ? args : opts)
184
+ when Hash
185
+ attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts)
191
186
  builder.build_from_hash(attributes, table)
192
187
  else
193
- args.first
188
+ opts
194
189
  end
195
-
196
- conditions
197
190
  end
198
191
 
199
192
  private
@@ -1,37 +1,19 @@
1
+ require 'active_support/core_ext/object/blank'
2
+
1
3
  module ActiveRecord
2
4
  module SpawnMethods
3
- def spawn
4
- clone.reset
5
- end
6
-
7
5
  def merge(r)
8
- merged_relation = spawn
6
+ merged_relation = clone
9
7
  return merged_relation unless r
10
8
 
11
- merged_relation = merged_relation.eager_load(r.eager_load_values).preload(r.preload_values).includes(r.includes_values)
12
-
13
- merged_relation.readonly_value = r.readonly_value unless r.readonly_value.nil?
14
- merged_relation.limit_value = r.limit_value if r.limit_value.present?
15
- merged_relation.lock_value = r.lock_value unless merged_relation.lock_value
16
- merged_relation.offset_value = r.offset_value if r.offset_value.present?
17
-
18
- merged_relation = merged_relation.
19
- joins(r.joins_values).
20
- group(r.group_values).
21
- select(r.select_values).
22
- from(r.from_value).
23
- having(r.having_values)
24
-
25
- merged_relation.order_values = r.order_values if r.order_values.present?
26
-
27
- merged_relation.create_with_value = @create_with_value
28
-
29
- if @create_with_value && r.create_with_value
30
- merged_relation.create_with_value = @create_with_value.merge(r.create_with_value)
31
- else
32
- merged_relation.create_with_value = r.create_with_value || @create_with_value
9
+ (ActiveRecord::Relation::ASSOCIATION_METHODS + ActiveRecord::Relation::MULTI_VALUE_METHODS).reject {|m| [:joins, :where].include?(m)}.each do |method|
10
+ unless (value = r.send(:"#{method}_values")).blank?
11
+ merged_relation.send(:"#{method}_values=", value)
12
+ end
33
13
  end
34
14
 
15
+ merged_relation = merged_relation.joins(r.joins_values)
16
+
35
17
  merged_wheres = @where_values
36
18
 
37
19
  r.where_values.each do |w|
@@ -44,6 +26,14 @@ module ActiveRecord
44
26
 
45
27
  merged_relation.where_values = merged_wheres
46
28
 
29
+ ActiveRecord::Relation::SINGLE_VALUE_METHODS.reject {|m| m == :lock}.each do |method|
30
+ unless (value = r.send(:"#{method}_value")).nil?
31
+ merged_relation.send(:"#{method}_value=", value)
32
+ end
33
+ end
34
+
35
+ merged_relation.lock_value = r.lock_value unless merged_relation.lock_value
36
+
47
37
  merged_relation
48
38
  end
49
39
 
@@ -83,7 +73,7 @@ module ActiveRecord
83
73
  :order, :select, :readonly, :group, :having, :from, :lock ]
84
74
 
85
75
  def apply_finder_options(options)
86
- relation = spawn
76
+ relation = clone
87
77
  return relation unless options
88
78
 
89
79
  options.assert_valid_keys(VALID_FIND_OPTIONS)
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/object/blank'
2
+
1
3
  module ActiveRecord
2
4
  # Allows programmers to programmatically define a schema in a portable
3
5
  # DSL. This means you can define tables, indexes, etc. without using SQL
@@ -67,13 +67,11 @@ module ActiveRecord
67
67
 
68
68
  if value.nil? || (options[:case_sensitive] || !column.text?)
69
69
  sql = "#{sql_attribute} #{operator}"
70
- params = [value]
71
70
  else
72
- sql = "LOWER(#{sql_attribute}) #{operator}"
73
- params = [value.mb_chars.downcase]
71
+ sql = "LOWER(#{sql_attribute}) = LOWER(?)"
74
72
  end
75
73
 
76
- [sql, params]
74
+ [sql, [value]]
77
75
  end
78
76
  end
79
77
 
@@ -2,8 +2,9 @@ module ActiveRecord
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = "0.beta"
5
+ TINY = 0
6
+ BUILD = "beta2"
6
7
 
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
+ STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
8
9
  end
9
10
  end
@@ -1,4 +1,4 @@
1
- require 'generators/active_record'
1
+ require 'rails/generators/active_record'
2
2
 
3
3
  module ActiveRecord
4
4
  module Generators
@@ -1,4 +1,4 @@
1
- require 'generators/active_record'
1
+ require 'rails/generators/active_record'
2
2
 
3
3
  module ActiveRecord
4
4
  module Generators
@@ -1,4 +1,4 @@
1
- require 'generators/active_record'
1
+ require 'rails/generators/active_record'
2
2
 
3
3
  module ActiveRecord
4
4
  module Generators
@@ -1,4 +1,4 @@
1
- require 'generators/active_record'
1
+ require 'rails/generators/active_record'
2
2
 
3
3
  module ActiveRecord
4
4
  module Generators
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta
4
+ prerelease: true
5
+ segments:
6
+ - 3
7
+ - 0
8
+ - 0
9
+ - beta2
10
+ version: 3.0.0.beta2
5
11
  platform: ruby
6
12
  authors:
7
13
  - David Heinemeier Hansson
@@ -9,40 +15,54 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-04 00:00:00 -08:00
18
+ date: 2010-04-01 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: activesupport
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
20
25
  requirements:
21
26
  - - "="
22
27
  - !ruby/object:Gem::Version
23
- version: 3.0.0.beta
24
- version:
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ - beta2
33
+ version: 3.0.0.beta2
34
+ type: :runtime
35
+ version_requirements: *id001
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: activemodel
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
30
40
  requirements:
31
41
  - - "="
32
42
  - !ruby/object:Gem::Version
33
- version: 3.0.0.beta
34
- version:
43
+ segments:
44
+ - 3
45
+ - 0
46
+ - 0
47
+ - beta2
48
+ version: 3.0.0.beta2
49
+ type: :runtime
50
+ version_requirements: *id002
35
51
  - !ruby/object:Gem::Dependency
36
52
  name: arel
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
40
55
  requirements:
41
56
  - - ~>
42
57
  - !ruby/object:Gem::Version
43
- version: 0.2.0
44
- version:
45
- description: Object-relational mapper framework (part of Rails).
58
+ segments:
59
+ - 0
60
+ - 3
61
+ - 3
62
+ version: 0.3.3
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ description: Databases on Rails. Build a persistent domain model by mapping database tables to Ruby classes. Strong conventions for associations, validations, aggregations, migrations, and testing come baked-in.
46
66
  email: david@loudthinking.com
47
67
  executables: []
48
68
 
@@ -79,7 +99,6 @@ files:
79
99
  - lib/active_record/attribute_methods.rb
80
100
  - lib/active_record/autosave_association.rb
81
101
  - lib/active_record/base.rb
82
- - lib/active_record/batches.rb
83
102
  - lib/active_record/callbacks.rb
84
103
  - lib/active_record/connection_adapters/abstract/connection_pool.rb
85
104
  - lib/active_record/connection_adapters/abstract/connection_specification.rb
@@ -95,6 +114,7 @@ files:
95
114
  - lib/active_record/connection_adapters/sqlite_adapter.rb
96
115
  - lib/active_record/dynamic_finder_match.rb
97
116
  - lib/active_record/dynamic_scope_match.rb
117
+ - lib/active_record/errors.rb
98
118
  - lib/active_record/fixtures.rb
99
119
  - lib/active_record/locale/en.yml
100
120
  - lib/active_record/locking/optimistic.rb
@@ -107,8 +127,9 @@ files:
107
127
  - lib/active_record/railtie.rb
108
128
  - lib/active_record/railties/controller_runtime.rb
109
129
  - lib/active_record/railties/databases.rake
110
- - lib/active_record/railties/subscriber.rb
130
+ - lib/active_record/railties/log_subscriber.rb
111
131
  - lib/active_record/reflection.rb
132
+ - lib/active_record/relation/batches.rb
112
133
  - lib/active_record/relation/calculations.rb
113
134
  - lib/active_record/relation/finder_methods.rb
114
135
  - lib/active_record/relation/predicate_builder.rb
@@ -128,16 +149,16 @@ files:
128
149
  - lib/active_record/validations.rb
129
150
  - lib/active_record/version.rb
130
151
  - lib/active_record.rb
131
- - lib/generators/active_record/migration/migration_generator.rb
132
- - lib/generators/active_record/migration/templates/migration.rb
133
- - lib/generators/active_record/model/model_generator.rb
134
- - lib/generators/active_record/model/templates/migration.rb
135
- - lib/generators/active_record/model/templates/model.rb
136
- - lib/generators/active_record/observer/observer_generator.rb
137
- - lib/generators/active_record/observer/templates/observer.rb
138
- - lib/generators/active_record/session_migration/session_migration_generator.rb
139
- - lib/generators/active_record/session_migration/templates/migration.rb
140
- - lib/generators/active_record.rb
152
+ - lib/rails/generators/active_record/migration/migration_generator.rb
153
+ - lib/rails/generators/active_record/migration/templates/migration.rb
154
+ - lib/rails/generators/active_record/model/model_generator.rb
155
+ - lib/rails/generators/active_record/model/templates/migration.rb
156
+ - lib/rails/generators/active_record/model/templates/model.rb
157
+ - lib/rails/generators/active_record/observer/observer_generator.rb
158
+ - lib/rails/generators/active_record/observer/templates/observer.rb
159
+ - lib/rails/generators/active_record/session_migration/session_migration_generator.rb
160
+ - lib/rails/generators/active_record/session_migration/templates/migration.rb
161
+ - lib/rails/generators/active_record.rb
141
162
  has_rdoc: true
142
163
  homepage: http://www.rubyonrails.org
143
164
  licenses: []
@@ -152,18 +173,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
173
  requirements:
153
174
  - - ">="
154
175
  - !ruby/object:Gem::Version
155
- version: "0"
156
- version:
176
+ segments:
177
+ - 1
178
+ - 8
179
+ - 7
180
+ version: 1.8.7
157
181
  required_rubygems_version: !ruby/object:Gem::Requirement
158
182
  requirements:
159
183
  - - ">"
160
184
  - !ruby/object:Gem::Version
185
+ segments:
186
+ - 1
187
+ - 3
188
+ - 1
161
189
  version: 1.3.1
162
- version:
163
190
  requirements: []
164
191
 
165
192
  rubyforge_project: activerecord
166
- rubygems_version: 1.3.5
193
+ rubygems_version: 1.3.6
167
194
  signing_key:
168
195
  specification_version: 3
169
196
  summary: Object-relational mapper framework (part of Rails).