activerecord 4.2.5 → 4.2.11.1

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 (44) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +156 -0
  3. data/lib/active_record.rb +2 -1
  4. data/lib/active_record/aggregations.rb +6 -3
  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/attribute_assignment.rb +1 -1
  10. data/lib/active_record/attribute_methods.rb +4 -8
  11. data/lib/active_record/attribute_methods/dirty.rb +1 -0
  12. data/lib/active_record/attribute_methods/write.rb +1 -1
  13. data/lib/active_record/attributes.rb +1 -0
  14. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -1
  15. data/lib/active_record/connection_adapters/abstract/database_statements.rb +2 -1
  16. data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -0
  17. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +2 -2
  18. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +21 -7
  19. data/lib/active_record/connection_adapters/abstract_adapter.rb +12 -0
  20. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +44 -9
  21. data/lib/active_record/connection_adapters/mysql2_adapter.rb +5 -19
  22. data/lib/active_record/connection_adapters/mysql_adapter.rb +9 -2
  23. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -0
  24. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +12 -1
  25. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +2 -12
  26. data/lib/active_record/enum.rb +1 -1
  27. data/lib/active_record/gem_version.rb +2 -2
  28. data/lib/active_record/migration.rb +30 -5
  29. data/lib/active_record/model_schema.rb +3 -1
  30. data/lib/active_record/nested_attributes.rb +12 -2
  31. data/lib/active_record/railtie.rb +4 -2
  32. data/lib/active_record/railties/databases.rake +7 -17
  33. data/lib/active_record/reflection.rb +3 -3
  34. data/lib/active_record/relation/calculations.rb +10 -3
  35. data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -1
  36. data/lib/active_record/relation/spawn_methods.rb +7 -3
  37. data/lib/active_record/schema_migration.rb +1 -4
  38. data/lib/active_record/tasks/database_tasks.rb +3 -0
  39. data/lib/active_record/tasks/mysql_database_tasks.rb +13 -9
  40. data/lib/active_record/tasks/postgresql_database_tasks.rb +2 -2
  41. data/lib/active_record/type/date.rb +4 -0
  42. data/lib/active_record/type/decimal.rb +17 -3
  43. data/lib/active_record/type/value.rb +5 -0
  44. metadata +7 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c74204a747f6ddf4c07b74945a1342b5eb999f87
4
- data.tar.gz: e43e4e5e5f118e54d025bd348048f62624db2a2e
2
+ SHA256:
3
+ metadata.gz: 4bf5ac2a8f9cb5f1fff8f39c4c48aebc5efd49af33503298a0061b994ed56070
4
+ data.tar.gz: 449af052b95d91b08d8fec21b0fcda62386c221f0d1ccc4d41fc9f893b19953c
5
5
  SHA512:
6
- metadata.gz: d90b5a92dd489bbbd2855543729c9cc69f896c902d37f378cf0e814aea96642a52a3dd83af62cedc704dca1b203a8664f47d9619ed7418495bcf1168e0c5e08d
7
- data.tar.gz: a561d0a53c92964c6daf1654ba181e6bf1f0990ee178a4da388deea9299dd11c736d65333d156ca8b5686e635aaf40c6696a8e7a25e72792fc586411fb88e754
6
+ metadata.gz: 3d204fb1f1c38831b042143a1fdd654cb4ebe0a596a14d49e421d3f4c686d9670254417f3c2733504cf6678a753acbd6852bf56397d05c2cbd76bdfcd9af7f44
7
+ data.tar.gz: 06d00a8204a4e725d17a388110a32ac3049bfd4dcca14b66d7f3235e4e94ee04789c695444a298730f5f14c1f27a6e98b53fbe34be7baee54689932431125a4e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,159 @@
1
+ ## Rails 4.2.11.1 (March 11, 2019) ##
2
+
3
+ * No changes.
4
+
5
+
6
+ ## Rails 4.2.11 (November 27, 2018) ##
7
+
8
+ * No changes.
9
+
10
+
11
+ ## Rails 4.2.10 (September 27, 2017) ##
12
+
13
+ * `Relation#joins` is no longer affected by the target model's
14
+ `current_scope`, with the exception of `unscoped`.
15
+
16
+ Fixes #29338.
17
+
18
+ *Sean Griffin*
19
+
20
+ ## Rails 4.2.9 (June 26, 2017) ##
21
+
22
+ * Fix regression caused by `collection_singular_ids=` ignoring different primary key on relationship.
23
+
24
+ *Nick Pezza*
25
+
26
+ * Fix `rake db:schema:load` with subdirectories.
27
+
28
+ *Ryuta Kamizono*
29
+
30
+ * Fix `rake db:migrate:status` with subdirectories.
31
+
32
+ *Ryuta Kamizono*
33
+
34
+ * Fix regression of #1969 with SELECT aliases in HAVING clause.
35
+
36
+ *Eugene Kenny*
37
+
38
+ * Fix `wait_timeout` to configurable for mysql2 adapter.
39
+
40
+ Fixes #26556.
41
+
42
+ *Ryuta Kamizono*
43
+
44
+ * Make `table_name=` reset current statement cache,
45
+ so queries are not run against the previous table name.
46
+
47
+ *namusyaka*
48
+
49
+
50
+ ## Rails 4.2.8 (February 21, 2017) ##
51
+
52
+ * Using a mysql2 connection after it fails to reconnect will now have an error message
53
+ saying the connection is closed rather than an undefined method error message.
54
+
55
+ *Dylan Thacker-Smith*
56
+
57
+ * Bust Model.attribute_names cache when resetting column information
58
+
59
+ *James Coleman*
60
+
61
+ * Fix query caching when type information is reset
62
+
63
+ Backports ancillary fix in 5.0.
64
+
65
+ *James Coleman*
66
+
67
+ * Allow `joins` to be unscoped.
68
+
69
+ Fixes #13775.
70
+
71
+ *Takashi Kokubun*
72
+
73
+ * Hashes can once again be passed to setters of `composed_of`, if all of the
74
+ mapping methods are methods implemented on `Hash`.
75
+
76
+ Fixes #25978.
77
+
78
+ *Sean Griffin*
79
+
80
+
81
+ ## Rails 4.2.7 (July 12, 2016) ##
82
+
83
+ * Inspecting an object with an associated array of over 10 elements no longer
84
+ truncates the array, preventing `inspect` from looping infinitely in some
85
+ cases.
86
+
87
+ *Kevin McPhillips*
88
+
89
+ * Ensure hashes can be assigned to attributes created using `composed_of`.
90
+ Fixes #25210.
91
+
92
+ *Sean Griffin*
93
+
94
+ * Queries such as `Computer.joins(:monitor).group(:status).count` will now be
95
+ interpreted as `Computer.joins(:monitor).group('computers.status').count`
96
+ so that when `Computer` and `Monitor` have both `status` columns we don't
97
+ have conflicts in projection.
98
+
99
+ *Rafael Sales*
100
+
101
+ * ActiveRecord::Relation#count: raise an ArgumentError when finder options
102
+ are specified or an ActiveRecord::StatementInvalid when an invalid type
103
+ is provided for a column name (e.g. a Hash).
104
+
105
+ Fixes #20434
106
+
107
+ *Konstantinos Rousis*
108
+
109
+ * Correctly pass MySQL options when using structure_dump or structure_load
110
+
111
+ Specifically, it fixes an issue when using SSL authentication.
112
+
113
+ *Alex Coomans*
114
+
115
+
116
+ ## Rails 4.2.6 (March 07, 2016) ##
117
+
118
+ * Fix a bug where using `t.foreign_key` twice with the same `to_table` within
119
+ the same table definition would only create one foreign key.
120
+
121
+ *George Millo*
122
+
123
+ * Fix regression in dirty attribute tracking after #dup. Changes to the
124
+ clone no longer show as changed attributes in the original object.
125
+
126
+ *Dominic Cleal*
127
+
128
+ * Fix regression when loading fixture files with symbol keys.
129
+
130
+ Closes #22584.
131
+
132
+ *Yves Senn*
133
+
134
+ * Fix `rake db:structure:dump` on Postgres when multiple schemas are used.
135
+
136
+ Fixes #22346.
137
+
138
+ *Nick Muerdter*, *ckoenig*
139
+
140
+ * Introduce `connection.data_sources` and `connection.data_source_exists?`.
141
+ These methods determine what relations can be used to back Active Record
142
+ models (usually tables and views).
143
+
144
+ *Yves Senn*, *Matthew Draper*
145
+
146
+
147
+ ## Rails 4.2.5.2 (February 26, 2016) ##
148
+
149
+ * No changes.
150
+
151
+
152
+ ## Rails 4.2.5.1 (January 25, 2015) ##
153
+
154
+ * No changes.
155
+
156
+
1
157
  ## Rails 4.2.5 (November 12, 2015) ##
2
158
 
3
159
  * No longer pass deprecated option `-i` to `pg_dump`.
data/lib/active_record.rb CHANGED
@@ -43,7 +43,6 @@ module ActiveRecord
43
43
  autoload :Explain
44
44
  autoload :Inheritance
45
45
  autoload :Integration
46
- autoload :LegacyYamlAdapter
47
46
  autoload :Migration
48
47
  autoload :Migrator, 'active_record/migration'
49
48
  autoload :ModelSchema
@@ -80,6 +79,8 @@ module ActiveRecord
80
79
  autoload :AttributeMethods
81
80
  autoload :AutosaveAssociation
82
81
 
82
+ autoload :LegacyYamlAdapter
83
+
83
84
  autoload :Relation
84
85
  autoload :AssociationRelation
85
86
  autoload :NullRelation
@@ -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
@@ -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
@@ -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(
@@ -287,9 +287,8 @@ module ActiveRecord
287
287
  # Returns an <tt>#inspect</tt>-like string for the value of the
288
288
  # attribute +attr_name+. String attributes are truncated up to 50
289
289
  # characters, Date and Time attributes are returned in the
290
- # <tt>:db</tt> format, Array attributes are truncated up to 10 values.
291
- # Other attributes return the value of <tt>#inspect</tt> without
292
- # modification.
290
+ # <tt>:db</tt> format. Other attributes return the value of
291
+ # <tt>#inspect</tt> without modification.
293
292
  #
294
293
  # person = Person.create!(name: 'David Heinemeier Hansson ' * 3)
295
294
  #
@@ -300,7 +299,7 @@ module ActiveRecord
300
299
  # # => "\"2012-10-22 00:15:07\""
301
300
  #
302
301
  # person.attribute_for_inspect(:tag_ids)
303
- # # => "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...]"
302
+ # # => "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]"
304
303
  def attribute_for_inspect(attr_name)
305
304
  value = read_attribute(attr_name)
306
305
 
@@ -308,9 +307,6 @@ module ActiveRecord
308
307
  "#{value[0, 50]}...".inspect
309
308
  elsif value.is_a?(Date) || value.is_a?(Time)
310
309
  %("#{value.to_s(:db)}")
311
- elsif value.is_a?(Array) && value.size > 10
312
- inspected = value.first(10).inspect
313
- %(#{inspected[0...-1]}, ...])
314
310
  else
315
311
  value.inspect
316
312
  end
@@ -368,7 +364,7 @@ module ActiveRecord
368
364
  # person = Person.new
369
365
  # person[:age] = '22'
370
366
  # person[:age] # => 22
371
- # person[:age] # => Fixnum
367
+ # person[:age].class # => Integer
372
368
  def []=(attr_name, value)
373
369
  write_attribute(attr_name, value)
374
370
  end
@@ -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)
@@ -136,6 +136,7 @@ module ActiveRecord
136
136
  @content_columns = nil
137
137
  @default_attributes = nil
138
138
  @persistable_attribute_names = nil
139
+ @attribute_names = nil
139
140
  end
140
141
 
141
142
  def raw_default_values
@@ -637,7 +637,7 @@ module ActiveRecord
637
637
  end
638
638
 
639
639
  def pool_from_any_process_for(owner)
640
- owner_to_pool = @owner_to_pool.values.find { |v| v[owner.name] }
640
+ owner_to_pool = @owner_to_pool.values.reverse.find { |v| v[owner.name] }
641
641
  owner_to_pool && owner_to_pool[owner.name]
642
642
  end
643
643
  end
@@ -287,6 +287,7 @@ module ActiveRecord
287
287
  # Inserts the given fixture into the table. Overridden in adapters that require
288
288
  # something beyond a simple insert (eg. Oracle).
289
289
  def insert_fixture(fixture, table_name)
290
+ fixture = fixture.stringify_keys
290
291
  columns = schema_cache.columns_hash(table_name)
291
292
 
292
293
  key_list = []
@@ -295,7 +296,7 @@ module ActiveRecord
295
296
  key_list << quote_column_name(name)
296
297
  quote(value, column)
297
298
  else
298
- raise Fixture::FixtureError, %(table "#{table_name}" has no column named "#{name}".)
299
+ raise Fixture::FixtureError, %(table "#{table_name}" has no column named #{name.inspect}.)
299
300
  end
300
301
  end
301
302
 
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/big_decimal/conversions'
2
+ require "active_support/multibyte/chars"
2
3
 
3
4
  module ActiveRecord
4
5
  module ConnectionAdapters # :nodoc:
@@ -99,7 +99,7 @@ module ActiveRecord
99
99
  def initialize(types, name, temporary, options, as = nil)
100
100
  @columns_hash = {}
101
101
  @indexes = {}
102
- @foreign_keys = {}
102
+ @foreign_keys = []
103
103
  @native = types
104
104
  @temporary = temporary
105
105
  @options = options
@@ -289,7 +289,7 @@ module ActiveRecord
289
289
  end
290
290
 
291
291
  def foreign_key(table_name, options = {}) # :nodoc:
292
- foreign_keys[table_name] = options
292
+ foreign_keys.push([table_name, options])
293
293
  end
294
294
 
295
295
  # Appends <tt>:datetime</tt> columns <tt>:created_at</tt> and
@@ -19,6 +19,20 @@ module ActiveRecord
19
19
  table_name[0...table_alias_length].tr('.', '_')
20
20
  end
21
21
 
22
+ # Returns the relation names useable to back Active Record models.
23
+ # For most adapters this means all tables and views.
24
+ def data_sources
25
+ tables
26
+ end
27
+
28
+ # Checks to see if the data source +name+ exists on the database.
29
+ #
30
+ # data_source_exists?(:ebooks)
31
+ #
32
+ def data_source_exists?(name)
33
+ data_sources.include?(name.to_s)
34
+ end
35
+
22
36
  # Checks to see if the table +table_name+ exists on the database.
23
37
  #
24
38
  # table_exists?(:developers)
@@ -213,7 +227,7 @@ module ActiveRecord
213
227
  end
214
228
  end
215
229
 
216
- td.foreign_keys.each_pair do |other_table_name, foreign_key_options|
230
+ td.foreign_keys.each do |other_table_name, foreign_key_options|
217
231
  add_foreign_key(table_name, other_table_name, foreign_key_options)
218
232
  end
219
233
 
@@ -827,10 +841,9 @@ module ActiveRecord
827
841
  version = version.to_i
828
842
  sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
829
843
 
830
- migrated = select_values("SELECT version FROM #{sm_table}").map { |v| v.to_i }
831
- paths = migrations_paths.map {|p| "#{p}/[0-9]*_*.rb" }
832
- versions = Dir[*paths].map do |filename|
833
- filename.split('/').last.split('_').first.to_i
844
+ migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i)
845
+ versions = ActiveRecord::Migrator.migration_files(migrations_paths).map do |file|
846
+ ActiveRecord::Migrator.parse_migration_filename(file).first.to_i
834
847
  end
835
848
 
836
849
  unless migrated.include?(version)
@@ -876,11 +889,12 @@ module ActiveRecord
876
889
  end
877
890
 
878
891
  # Given a set of columns and an ORDER BY clause, returns the columns for a SELECT DISTINCT.
879
- # Both PostgreSQL and Oracle overrides this for custom DISTINCT syntax - they
892
+ # PostgreSQL, MySQL, and Oracle overrides this for custom DISTINCT syntax - they
880
893
  # require the order columns appear in the SELECT.
881
894
  #
882
895
  # columns_for_distinct("posts.id", ["posts.created_at desc"])
883
- def columns_for_distinct(columns, orders) #:nodoc:
896
+ #
897
+ def columns_for_distinct(columns, orders) # :nodoc:
884
898
  columns
885
899
  end
886
900