activerecord 4.2.4 → 4.2.10

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +249 -0
  3. data/lib/active_record/aggregations.rb +6 -3
  4. data/lib/active_record/associations/association_scope.rb +1 -1
  5. data/lib/active_record/associations/collection_association.rb +17 -6
  6. data/lib/active_record/associations/collection_proxy.rb +2 -2
  7. data/lib/active_record/associations/has_many_through_association.rb +5 -0
  8. data/lib/active_record/associations/join_dependency/join_association.rb +7 -1
  9. data/lib/active_record/associations/join_dependency.rb +2 -1
  10. data/lib/active_record/associations/preloader/association.rb +5 -1
  11. data/lib/active_record/attribute_assignment.rb +1 -1
  12. data/lib/active_record/attribute_methods/dirty.rb +1 -0
  13. data/lib/active_record/attribute_methods/write.rb +1 -1
  14. data/lib/active_record/attribute_methods.rb +4 -8
  15. data/lib/active_record/attribute_set/builder.rb +21 -11
  16. data/lib/active_record/attribute_set.rb +4 -0
  17. data/lib/active_record/attributes.rb +1 -0
  18. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -1
  19. data/lib/active_record/connection_adapters/abstract/database_statements.rb +7 -2
  20. data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -0
  21. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +2 -2
  22. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +21 -7
  23. data/lib/active_record/connection_adapters/abstract_adapter.rb +12 -1
  24. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +44 -9
  25. data/lib/active_record/connection_adapters/column.rb +1 -1
  26. data/lib/active_record/connection_adapters/mysql2_adapter.rb +5 -19
  27. data/lib/active_record/connection_adapters/mysql_adapter.rb +9 -2
  28. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -0
  29. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +1 -1
  30. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +13 -2
  31. data/lib/active_record/connection_adapters/postgresql_adapter.rb +2 -6
  32. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +2 -12
  33. data/lib/active_record/core.rb +2 -0
  34. data/lib/active_record/enum.rb +2 -3
  35. data/lib/active_record/errors.rb +4 -3
  36. data/lib/active_record/gem_version.rb +1 -1
  37. data/lib/active_record/legacy_yaml_adapter.rb +30 -0
  38. data/lib/active_record/migration.rb +34 -6
  39. data/lib/active_record/model_schema.rb +3 -1
  40. data/lib/active_record/nested_attributes.rb +12 -2
  41. data/lib/active_record/railtie.rb +4 -2
  42. data/lib/active_record/railties/databases.rake +7 -17
  43. data/lib/active_record/reflection.rb +37 -25
  44. data/lib/active_record/relation/calculations.rb +10 -3
  45. data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -1
  46. data/lib/active_record/relation/query_methods.rb +1 -1
  47. data/lib/active_record/relation/spawn_methods.rb +7 -3
  48. data/lib/active_record/schema_migration.rb +1 -4
  49. data/lib/active_record/tasks/database_tasks.rb +4 -1
  50. data/lib/active_record/tasks/mysql_database_tasks.rb +30 -16
  51. data/lib/active_record/tasks/postgresql_database_tasks.rb +19 -8
  52. data/lib/active_record/type/date.rb +4 -0
  53. data/lib/active_record/type/decimal.rb +19 -3
  54. data/lib/active_record/type/value.rb +5 -0
  55. data/lib/active_record/validations/uniqueness.rb +7 -1
  56. data/lib/active_record.rb +2 -0
  57. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7713b03190184900b6e52a043faf4d62ee785ff0
4
- data.tar.gz: cb0520a2e5d6ce794efda315f397fea372b1aa97
3
+ metadata.gz: a044320a2084a8ed3f8e94b2e5bc434662f52fe7
4
+ data.tar.gz: 0356a6c53934287ca96cd302db2386c25d6e2d09
5
5
  SHA512:
6
- metadata.gz: 176cf4ae3f750d0b0d85ad9465db4e80cb20e9408839a386b4de279a16f75095b3a3ca8f9d380e09425095d45c48134d1985aa7e8bbcc242b06985077ec3025b
7
- data.tar.gz: aa611ec67a99a849bd0299b77cb89afcb2a655dce4a30f9a5c38d23f94157bb676abbf9c242666a689f7ceb528ca6d04ac65d5f3639773bf5664543eb2365372
6
+ metadata.gz: 5c7b0539438e82caaae756cefb47c55db7800fafd4d5cb2f4e23119f0b7b99b0bea3f1bb8be014b15814eaebeb8042cb5996a32cfb591a48cb743b6350ef70b2
7
+ data.tar.gz: bf3dc3ba36a8eedfc3db11f1dfed45bb02a3af88316cad292b405afcc32f76742371bf2c72c65f4b4cf5dc95b35471f0e25ab5279016b8b34bc0c9e0ec64763f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,252 @@
1
+ ## Rails 4.2.10 (September 27, 2017) ##
2
+
3
+ * `Relation#joins` is no longer affected by the target model's
4
+ `current_scope`, with the exception of `unscoped`.
5
+
6
+ Fixes #29338.
7
+
8
+ *Sean Griffin*
9
+
10
+ ## Rails 4.2.9 (June 26, 2017) ##
11
+
12
+ * Fix regression caused by `collection_singular_ids=` ignoring different primary key on relationship.
13
+
14
+ *Nick Pezza*
15
+
16
+ * Fix `rake db:schema:load` with subdirectories.
17
+
18
+ *Ryuta Kamizono*
19
+
20
+ * Fix `rake db:migrate:status` with subdirectories.
21
+
22
+ *Ryuta Kamizono*
23
+
24
+ * Fix regression of #1969 with SELECT aliases in HAVING clause.
25
+
26
+ *Eugene Kenny*
27
+
28
+ * Fix `wait_timeout` to configurable for mysql2 adapter.
29
+
30
+ Fixes #26556.
31
+
32
+ *Ryuta Kamizono*
33
+
34
+ * Make `table_name=` reset current statement cache,
35
+ so queries are not run against the previous table name.
36
+
37
+ *namusyaka*
38
+
39
+
40
+ ## Rails 4.2.8 (February 21, 2017) ##
41
+
42
+ * Using a mysql2 connection after it fails to reconnect will now have an error message
43
+ saying the connection is closed rather than an undefined method error message.
44
+
45
+ *Dylan Thacker-Smith*
46
+
47
+ * Bust Model.attribute_names cache when resetting column information
48
+
49
+ *James Coleman*
50
+
51
+ * Fix query caching when type information is reset
52
+
53
+ Backports ancillary fix in 5.0.
54
+
55
+ *James Coleman*
56
+
57
+ * Allow `joins` to be unscoped.
58
+
59
+ Fixes #13775.
60
+
61
+ *Takashi Kokubun*
62
+
63
+ * Hashes can once again be passed to setters of `composed_of`, if all of the
64
+ mapping methods are methods implemented on `Hash`.
65
+
66
+ Fixes #25978.
67
+
68
+ *Sean Griffin*
69
+
70
+
71
+ ## Rails 4.2.7 (July 12, 2016) ##
72
+
73
+ * Inspecting an object with an associated array of over 10 elements no longer
74
+ truncates the array, preventing `inspect` from looping infinitely in some
75
+ cases.
76
+
77
+ *Kevin McPhillips*
78
+
79
+ * Ensure hashes can be assigned to attributes created using `composed_of`.
80
+ Fixes #25210.
81
+
82
+ *Sean Griffin*
83
+
84
+ * Queries such as `Computer.joins(:monitor).group(:status).count` will now be
85
+ interpreted as `Computer.joins(:monitor).group('computers.status').count`
86
+ so that when `Computer` and `Monitor` have both `status` columns we don't
87
+ have conflicts in projection.
88
+
89
+ *Rafael Sales*
90
+
91
+ * ActiveRecord::Relation#count: raise an ArgumentError when finder options
92
+ are specified or an ActiveRecord::StatementInvalid when an invalid type
93
+ is provided for a column name (e.g. a Hash).
94
+
95
+ Fixes #20434
96
+
97
+ *Konstantinos Rousis*
98
+
99
+ * Correctly pass MySQL options when using structure_dump or structure_load
100
+
101
+ Specifically, it fixes an issue when using SSL authentication.
102
+
103
+ *Alex Coomans*
104
+
105
+
106
+ ## Rails 4.2.6 (March 07, 2016) ##
107
+
108
+ * Fix a bug where using `t.foreign_key` twice with the same `to_table` within
109
+ the same table definition would only create one foreign key.
110
+
111
+ *George Millo*
112
+
113
+ * Fix regression in dirty attribute tracking after #dup. Changes to the
114
+ clone no longer show as changed attributes in the original object.
115
+
116
+ *Dominic Cleal*
117
+
118
+ * Fix regression when loading fixture files with symbol keys.
119
+
120
+ Closes #22584.
121
+
122
+ *Yves Senn*
123
+
124
+ * Fix `rake db:structure:dump` on Postgres when multiple schemas are used.
125
+
126
+ Fixes #22346.
127
+
128
+ *Nick Muerdter*, *ckoenig*
129
+
130
+ * Introduce `connection.data_sources` and `connection.data_source_exists?`.
131
+ These methods determine what relations can be used to back Active Record
132
+ models (usually tables and views).
133
+
134
+ *Yves Senn*, *Matthew Draper*
135
+
136
+
137
+ ## Rails 4.2.5.2 (February 26, 2016) ##
138
+
139
+ * No changes.
140
+
141
+
142
+ ## Rails 4.2.5.1 (January 25, 2015) ##
143
+
144
+ * No changes.
145
+
146
+
147
+ ## Rails 4.2.5 (November 12, 2015) ##
148
+
149
+ * No longer pass deprecated option `-i` to `pg_dump`.
150
+
151
+ *Paul Sadauskas*
152
+
153
+ * Set `scope.reordering_value` to `true` if :reordering values are specified.
154
+
155
+ Fixes #21886.
156
+
157
+ *Hiroaki Izu*
158
+
159
+ * Avoid disabling errors on the PostgreSQL connection when enabling the
160
+ standard_conforming_strings setting. Errors were previously disabled because
161
+ the setting wasn't writable in Postgres 8.1 and didn't exist in earlier
162
+ versions. Now Rails only supports Postgres 8.2+ we're fine to assume the
163
+ setting exists. Disabling errors caused problems when using a connection
164
+ pooling tool like PgBouncer because it's not guaranteed to have the same
165
+ connection between calls to `execute` and it could leave the connection
166
+ with errors disabled.
167
+
168
+ Fixes #22101.
169
+
170
+ *Harry Marr*
171
+
172
+ * Includes HABTM returns correct size now. It's caused by the join dependency
173
+ only instantiates one HABTM object because the join table hasn't a primary key.
174
+
175
+ Fixes #16032.
176
+
177
+ Examples:
178
+
179
+ before:
180
+
181
+ Project.first.salaried_developers.size # => 3
182
+ Project.includes(:salaried_developers).first.salaried_developers.size # => 1
183
+
184
+ after:
185
+
186
+ Project.first.salaried_developers.size # => 3
187
+ Project.includes(:salaried_developers).first.salaried_developers.size # => 3
188
+
189
+ *Bigxiang*
190
+
191
+ * Descriptive error message when fixtures contain a missing column.
192
+
193
+ Closes #21201.
194
+
195
+ *Yves Senn*
196
+
197
+ * `bin/rake db:migrate` uses
198
+ `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of
199
+ `Migrator.migrations_paths`.
200
+
201
+ *Tobias Bielohlawek*
202
+
203
+ * Fix `rewhere` in a `has_many` association.
204
+
205
+ Fixes #21955.
206
+
207
+ *Josh Branchaud*, *Kal*
208
+
209
+ * Added run_cmd class method to ActiveRecord::Tasks::DatabaseTasks for
210
+ drying up Kernel.system() calls within this namespace and to avoid
211
+ shell expansion by using a paramter list instead of string as arguments
212
+ for Kernel.system(). Thanks to Nate Berkopec for supply patch to get
213
+ test units passing.
214
+
215
+ *Bryan Paxton*
216
+
217
+ * Avoid leaking the first relation we call `first` on, per model.
218
+
219
+ Fixes #21921.
220
+
221
+ *Matthew Draper*, *Jean Boussier*
222
+
223
+ * Allow deserialization of Active Record models that were YAML encoded prior
224
+ to Rails 4.2
225
+
226
+ *Sean Griffin*
227
+
228
+ * Correctly apply `unscope` when preloading through associations.
229
+
230
+ *Jimmy Bourassa*
231
+
232
+ * Ensure `select` quotes aliased attributes, even when using `from`.
233
+
234
+ Fixes #21488
235
+
236
+ *Sean Griffin & @johanlunds*
237
+
238
+ * Correct query for PostgreSQL 8.2 compatibility.
239
+
240
+ *Ben Murphy*, *Matthew Draper*
241
+
242
+ * Uniqueness validator raises descriptive error when running on a persisted
243
+ record without primary key.
244
+
245
+ Closes #21304.
246
+
247
+ *Yves Senn*
248
+
249
+
1
250
  ## Rails 4.2.4 (August 24, 2015) ##
2
251
 
3
252
  * Skip statement cache on through association reader.
@@ -244,14 +244,17 @@ module ActiveRecord
244
244
  def writer_method(name, class_name, mapping, allow_nil, converter)
245
245
  define_method("#{name}=") do |part|
246
246
  klass = class_name.constantize
247
- if part.is_a?(Hash)
248
- part = klass.new(*part.values)
249
- end
250
247
 
251
248
  unless part.is_a?(klass) || converter.nil? || part.nil?
252
249
  part = converter.respond_to?(:call) ? converter.call(part) : klass.send(converter, part)
253
250
  end
254
251
 
252
+ hash_from_multiparameter_assignment = part.is_a?(Hash) &&
253
+ part.each_key.all? { |k| k.is_a?(Integer) }
254
+ if hash_from_multiparameter_assignment
255
+ part = klass.new(*part.values)
256
+ end
257
+
255
258
  if part.nil? && allow_nil
256
259
  mapping.each { |key, _| self[key] = nil }
257
260
  @aggregation_cache[name] = nil
@@ -162,10 +162,10 @@ module ActiveRecord
162
162
  scope.includes! item.includes_values
163
163
  end
164
164
 
165
+ scope.unscope!(*item.unscope_values)
165
166
  scope.where_values += item.where_values
166
167
  scope.bind_values += item.bind_values
167
168
  scope.order_values |= item.order_values
168
- scope.unscope!(*item.unscope_values)
169
169
  end
170
170
  end
171
171
 
@@ -61,10 +61,21 @@ module ActiveRecord
61
61
 
62
62
  # Implements the ids writer method, e.g. foo.item_ids= for Foo.has_many :items
63
63
  def ids_writer(ids)
64
- pk_type = reflection.primary_key_type
65
- ids = Array(ids).reject { |id| id.blank? }
66
- ids.map! { |i| pk_type.type_cast_from_user(i) }
67
- replace(klass.find(ids).index_by { |r| r.id }.values_at(*ids))
64
+ pk_column = reflection.association_primary_key
65
+ pk_type = klass.type_for_attribute(pk_column)
66
+ ids = Array(ids).reject(&:blank?).map do |i|
67
+ pk_type.type_cast_from_user(i)
68
+ end
69
+
70
+ objs = klass.where(pk_column => ids).index_by do |r|
71
+ r.send(pk_column)
72
+ end.values_at(*ids).compact
73
+
74
+ if objs.size == ids.size
75
+ replace(objs.index_by { |r| r.send(pk_column) }.values_at(*ids))
76
+ else
77
+ klass.all.raise_record_not_found_exception!(ids, objs.size, ids.size)
78
+ end
68
79
  end
69
80
 
70
81
  def reset
@@ -264,7 +275,7 @@ module ActiveRecord
264
275
  _options = records.extract_options!
265
276
  dependent = _options[:dependent] || options[:dependent]
266
277
 
267
- records = find(records) if records.any? { |record| record.kind_of?(Fixnum) || record.kind_of?(String) }
278
+ records = find(records) if records.any? { |record| record.kind_of?(Integer) || record.kind_of?(String) }
268
279
  delete_or_destroy(records, dependent)
269
280
  end
270
281
 
@@ -275,7 +286,7 @@ module ActiveRecord
275
286
  # +:dependent+ option.
276
287
  def destroy(*records)
277
288
  return if records.empty?
278
- records = find(records) if records.any? { |record| record.kind_of?(Fixnum) || record.kind_of?(String) }
289
+ records = find(records) if records.any? { |record| record.kind_of?(Integer) || record.kind_of?(String) }
279
290
  delete_or_destroy(records, :destroy)
280
291
  end
281
292
 
@@ -562,7 +562,7 @@ module ActiveRecord
562
562
  # Pet.find(1)
563
563
  # # => ActiveRecord::RecordNotFound: Couldn't find Pet with id=1
564
564
  #
565
- # You can pass +Fixnum+ or +String+ values, it finds the records
565
+ # You can pass +Integer+ or +String+ values, it finds the records
566
566
  # responding to the +id+ and executes delete on them.
567
567
  #
568
568
  # class Person < ActiveRecord::Base
@@ -626,7 +626,7 @@ module ActiveRecord
626
626
  #
627
627
  # Pet.find(1, 2, 3) # => ActiveRecord::RecordNotFound: Couldn't find all Pets with IDs (1, 2, 3)
628
628
  #
629
- # You can pass +Fixnum+ or +String+ values, it finds the records
629
+ # You can pass +Integer+ or +String+ values, it finds the records
630
630
  # responding to the +id+ and then deletes them from the database.
631
631
  #
632
632
  # person.pets.size # => 3
@@ -94,6 +94,11 @@ module ActiveRecord
94
94
 
95
95
  through_record = through_association.build(*options_for_through_record)
96
96
  through_record.send("#{source_reflection.name}=", record)
97
+
98
+ if options[:source_type]
99
+ through_record.send("#{source_reflection.foreign_type}=", options[:source_type])
100
+ end
101
+
97
102
  through_record
98
103
  end
99
104
  end
@@ -52,7 +52,13 @@ module ActiveRecord
52
52
  end
53
53
  scope_chain_index += 1
54
54
 
55
- scope_chain_items.concat [klass.send(:build_default_scope, ActiveRecord::Relation.create(klass, table))].compact
55
+ klass_scope =
56
+ if klass.current_scope && klass.current_scope.values.blank?
57
+ klass.unscoped
58
+ else
59
+ klass.send(:build_default_scope, ActiveRecord::Relation.create(klass, table))
60
+ end
61
+ scope_chain_items.concat [klass_scope].compact
56
62
 
57
63
  rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right|
58
64
  left.merge right
@@ -151,7 +151,8 @@ module ActiveRecord
151
151
 
152
152
  message_bus.instrument('instantiation.active_record', payload) do
153
153
  result_set.each { |row_hash|
154
- parent = parents[row_hash[primary_key]] ||= join_root.instantiate(row_hash, column_aliases)
154
+ parent_key = primary_key ? row_hash[primary_key] : row_hash
155
+ parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases)
155
156
  construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
156
157
  }
157
158
  end
@@ -145,6 +145,10 @@ module ActiveRecord
145
145
  scope.joins! preload_values[:joins] || values[:joins]
146
146
  scope.order! preload_values[:order] || values[:order]
147
147
 
148
+ if preload_values[:reordering] || values[:reordering]
149
+ scope.reordering_value = true
150
+ end
151
+
148
152
  if preload_values[:readonly] || values[:readonly]
149
153
  scope.readonly!
150
154
  end
@@ -153,7 +157,7 @@ module ActiveRecord
153
157
  scope.where!(klass.table_name => { reflection.type => model.base_class.sti_name })
154
158
  end
155
159
 
156
- scope.unscope_values = Array(values[:unscope])
160
+ scope.unscope_values = Array(values[:unscope]) + Array(preload_values[:unscope])
157
161
  klass.default_scoped.merge(scope)
158
162
  end
159
163
  end
@@ -69,7 +69,7 @@ module ActiveRecord
69
69
  # by calling new on the column type or aggregation type (through composed_of) object with these parameters.
70
70
  # So having the pairs written_on(1) = "2004", written_on(2) = "6", written_on(3) = "24", will instantiate
71
71
  # written_on (a date type) with Date.new("2004", "6", "24"). You can also specify a typecast character in the
72
- # parentheses to have the parameters typecasted before they're used in the constructor. Use i for Fixnum and
72
+ # parentheses to have the parameters typecasted before they're used in the constructor. Use i for Integer and
73
73
  # f for Float. If all the values for a given attribute are empty, the attribute will be set to +nil+.
74
74
  def assign_multiparameter_attributes(pairs)
75
75
  execute_callstack_for_multiparameter_attributes(
@@ -40,6 +40,7 @@ module ActiveRecord
40
40
 
41
41
  def initialize_dup(other) # :nodoc:
42
42
  super
43
+ @original_raw_attributes = nil
43
44
  calculate_changes_from_defaults
44
45
  end
45
46
 
@@ -50,7 +50,7 @@ module ActiveRecord
50
50
  end
51
51
 
52
52
  # Updates the attribute identified by <tt>attr_name</tt> with the
53
- # specified +value+. Empty strings for fixnum and float columns are
53
+ # specified +value+. Empty strings for Integer and Float columns are
54
54
  # turned into +nil+.
55
55
  def write_attribute(attr_name, value)
56
56
  write_attribute_with_type_cast(attr_name, value, true)