activerecord 5.0.0.1 → 5.0.1.rc1

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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +196 -2
  3. data/README.rdoc +1 -1
  4. data/lib/active_record.rb +1 -1
  5. data/lib/active_record/aggregations.rb +4 -2
  6. data/lib/active_record/association_relation.rb +4 -1
  7. data/lib/active_record/associations.rb +5 -0
  8. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +4 -2
  9. data/lib/active_record/associations/builder/singular_association.rb +10 -1
  10. data/lib/active_record/associations/collection_association.rb +22 -17
  11. data/lib/active_record/associations/collection_proxy.rb +20 -7
  12. data/lib/active_record/associations/has_many_through_association.rb +4 -0
  13. data/lib/active_record/associations/join_dependency.rb +10 -4
  14. data/lib/active_record/associations/join_dependency/join_part.rb +2 -2
  15. data/lib/active_record/associations/preloader/association.rb +18 -4
  16. data/lib/active_record/associations/preloader/collection_association.rb +0 -1
  17. data/lib/active_record/associations/preloader/singular_association.rb +0 -1
  18. data/lib/active_record/associations/singular_association.rb +8 -2
  19. data/lib/active_record/attribute.rb +3 -3
  20. data/lib/active_record/attribute_methods.rb +3 -7
  21. data/lib/active_record/attribute_methods/primary_key.rb +14 -1
  22. data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
  23. data/lib/active_record/attribute_set.rb +2 -0
  24. data/lib/active_record/attribute_set/builder.rb +29 -7
  25. data/lib/active_record/attributes.rb +3 -3
  26. data/lib/active_record/autosave_association.rb +15 -11
  27. data/lib/active_record/base.rb +1 -1
  28. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +40 -32
  29. data/lib/active_record/connection_adapters/abstract/database_statements.rb +1 -1
  30. data/lib/active_record/connection_adapters/abstract/query_cache.rb +29 -0
  31. data/lib/active_record/connection_adapters/abstract/quoting.rb +4 -4
  32. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +8 -7
  33. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +37 -33
  34. data/lib/active_record/connection_adapters/abstract_adapter.rb +28 -5
  35. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +42 -45
  36. data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
  37. data/lib/active_record/connection_adapters/mysql/database_statements.rb +6 -23
  38. data/lib/active_record/connection_adapters/mysql/quoting.rb +1 -1
  39. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -5
  40. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +8 -0
  41. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +12 -1
  42. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +2 -2
  43. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +2 -0
  44. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +7 -1
  45. data/lib/active_record/connection_adapters/postgresql_adapter.rb +6 -2
  46. data/lib/active_record/core.rb +3 -1
  47. data/lib/active_record/enum.rb +6 -5
  48. data/lib/active_record/gem_version.rb +2 -2
  49. data/lib/active_record/integration.rb +13 -10
  50. data/lib/active_record/migration.rb +6 -5
  51. data/lib/active_record/model_schema.rb +134 -47
  52. data/lib/active_record/no_touching.rb +4 -0
  53. data/lib/active_record/persistence.rb +10 -4
  54. data/lib/active_record/query_cache.rb +13 -15
  55. data/lib/active_record/querying.rb +3 -3
  56. data/lib/active_record/railties/controller_runtime.rb +1 -1
  57. data/lib/active_record/reflection.rb +8 -0
  58. data/lib/active_record/relation.rb +7 -4
  59. data/lib/active_record/relation/calculations.rb +11 -11
  60. data/lib/active_record/relation/delegation.rb +1 -1
  61. data/lib/active_record/relation/finder_methods.rb +11 -9
  62. data/lib/active_record/relation/query_methods.rb +3 -3
  63. data/lib/active_record/result.rb +7 -1
  64. data/lib/active_record/sanitization.rb +11 -1
  65. data/lib/active_record/schema_dumper.rb +10 -17
  66. data/lib/active_record/scoping/named.rb +1 -1
  67. data/lib/active_record/statement_cache.rb +2 -2
  68. data/lib/active_record/table_metadata.rb +4 -3
  69. data/lib/active_record/touch_later.rb +6 -1
  70. data/lib/active_record/type/internal/abstract_json.rb +5 -1
  71. data/lib/active_record/validations/uniqueness.rb +3 -4
  72. metadata +9 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03a6d180e9ad1f0b0245bbf843f33de758ff41f8
4
- data.tar.gz: 3680e9da9480357ba1a0f27b5b7c2a22fe43c3d4
3
+ metadata.gz: 953b40722753f09afe5e56d51a78a2aca83a26cf
4
+ data.tar.gz: 8331cc743634b2444a933cb84edbdc0dff79abfd
5
5
  SHA512:
6
- metadata.gz: 7b2c9b69ef86ccb5b3152036494b3a6305fa13c4d8b89cecd64e4a1f7b34c8b76ed24356164fd4eb1c996d6b21aa51f84f1e0a0dae865133e04a4137481a43c1
7
- data.tar.gz: c930e7945627ff78210190c18e04fb3fb615632ee00395e53e43e610e4888d5c3656b64d636bd86c6b21b11ae673a2e02e8973e292b5bfdce2e7692c773f32d7
6
+ metadata.gz: 3836e3ac44e8afe18c3fe46e957b9c0e59da3ff22ac3f1e2f5db91da867e40785b61db201266e5e86b7f2aaf27da250d9142547c4eb0802a2b76fd786d18053d
7
+ data.tar.gz: 96552fa27ac3c8516e5b88a16144730b812ea5e9948104befb4a3d4a417f73ec2e0f4690d724238a6113fa3224a47ecdcd73ffb0c699668c783fdafd95a99772
@@ -1,6 +1,200 @@
1
+ ## Rails 5.0.1.rc1 (December 01, 2016) ##
2
+
3
+ * Fix that unsigned with zerofill is treated as signed.
4
+
5
+ Fixes #27125.
6
+
7
+ *Ryuta Kamizono*
8
+
9
+ * Fix the uniqueness validation scope with a polymorphic association.
10
+
11
+ *Sergey Alekseev*
12
+
13
+ * Raise ActiveRecord::RecordNotFound from collection `*_ids` setters
14
+ for unknown IDs with a better error message.
15
+
16
+ Changes the collection `*_ids` setters to cast provided IDs the data
17
+ type of the primary key set in the association, not the model
18
+ primary key.
19
+
20
+ *Dominic Cleal*
21
+
22
+ * Introduce `Model#reload_<association>` to bring back the behavior
23
+ of `Article.category(true)` where `category` is a singular
24
+ association.
25
+
26
+ The force reloading of the association reader was deprecated in
27
+ #20888. Unfortunately the suggested alternative of
28
+ `article.reload.category` does not expose the same behavior.
29
+
30
+ This patch adds a reader method with the prefix `reload_` for
31
+ singular associations. This method has the same semantics as
32
+ passing true to the association reader used to have.
33
+
34
+ *Yves Senn*
35
+
36
+ * Make sure eager loading `ActiveRecord::Associations` also loads
37
+ constants defined in `ActiveRecord::Associations::Preloader`.
38
+
39
+ *Yves Senn*
40
+
41
+ * Allow `ActionController::Parameters`-like objects to be passed as
42
+ values for Postgres HStore columns.
43
+
44
+ Fixes #26904.
45
+
46
+ *Jon Moss*
47
+
48
+ * Configure query caching (per thread) on the connection pool.
49
+
50
+ Moving the configuration to the pool means we don't allocate a connection
51
+ until it's actually needed.
52
+
53
+ Applications that manually interact with the connection pool and/or query
54
+ cache may notice that the connection's cache is now cleared and disabled
55
+ when it gets returned to the pool, even if the request is not yet completed.
56
+
57
+ *Samuel Cochran*, *Matthew Draper*
58
+
59
+ * Fixed support for case insensitive comparisons of `text` columns in
60
+ PostgreSQL.
61
+
62
+ *Edho Arief*
63
+
64
+ * Return `true` from `update_attribute` when the value of the attribute
65
+ to be updated is unchanged.
66
+
67
+ Fixes #26593.
68
+
69
+ *Prathamesh Sonpatki*
70
+
71
+ * Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`
72
+
73
+ *Trung Duc Tran*
74
+
75
+ * Always store errors details information with symbols.
76
+
77
+ When the association is autosaved we were storing the details with
78
+ string keys. This was creating inconsistency with other details that are
79
+ added using the `Errors#add` method. It was also inconsistent with the
80
+ `Errors#messages` storage.
81
+
82
+ To fix this inconsistency we are always storing with symbols. This will
83
+ cause a small breaking change because in those cases the details could
84
+ be accessed as strings keys but now it can not.
85
+
86
+ Fix #26499.
87
+
88
+ *Rafael Mendonça França*, *Marcus Vieira*
89
+
90
+ * Using a mysql2 connection after it fails to reconnect will now have an error message
91
+ saying the connection is closed rather than an undefined method error message.
92
+
93
+ *Dylan Thacker-Smith*
94
+
95
+ * Remove unnecessarily association load when a `belongs_to` association has already been
96
+ loaded then the foreign key is changed directly and the record saved.
97
+
98
+ *James Coleman*
99
+
100
+ * PostgreSQL array columns will now respect the encoding of strings contained
101
+ in the array.
102
+
103
+ Fixes #26326.
104
+
105
+ *Sean Griffin*
106
+
107
+ * Inverse association instances will now be set before `after_find` or
108
+ `after_initialize` callbacks are run.
109
+
110
+ Fixes #26320.
111
+
112
+ *Sean Griffin*
113
+
114
+ * Avoid loading records from database when they are already loaded using
115
+ the `pluck` method on a collection.
116
+
117
+ Fixes #25921.
118
+
119
+ *Ryuta Kamizono*
120
+
121
+ * Sqlite3 migrations to add a column to an existing table can now be
122
+ successfully rolled back when the column was given and invalid column
123
+ type.
124
+
125
+ Fixes #26087
126
+
127
+ *Travis O'Neill*
128
+
129
+ * Hashes can once again be passed to setters of `composed_of`, if all of the
130
+ mapping methods are methods implemented on `Hash`.
131
+
132
+ Fixes #25978.
133
+
134
+ *Sean Griffin*
135
+
136
+ * Doing count on relations that contain LEFT OUTER JOIN Arel node no longer
137
+ force a DISTINCT. This solves issues when using count after a left_joins.
138
+
139
+ *Maxime Handfield Lapointe*
140
+
141
+ * RecordNotFound raised by association.find exposes `id`, `primary_key` and
142
+ `model` methods to be consistent with RecordNotFound raised by Record.find.
143
+
144
+ *Michel Pigassou*
145
+
146
+ * Fix the SELECT statement in `#table_comment` for MySQL.
147
+
148
+ *Takeshi Akima*
149
+
150
+ * Virtual attributes will no longer raise when read on models loaded from the
151
+ database
152
+
153
+ *Sean Griffin*
154
+
155
+ * Fixes multi-parameter attributes conversion with invalid params.
156
+
157
+ *Hiroyuki Ishii*
158
+
159
+ * Add newline between each migration in `structure.sql`.
160
+
161
+ Keeps schema migration inserts as a single commit, but allows for easier
162
+ git diff-ing. Fixes #25504.
163
+
164
+ *Grey Baker*, *Norberto Lopes*
165
+
166
+ * Using `group` with an attribute that has a custom type will properly cast
167
+ the hash keys after calling a calculation method like `count`.
168
+
169
+ Fixes #25595.
170
+
171
+ *Sean Griffin*
172
+
173
+ * Ensure concurrent invocations of the connection reaper cannot allocate the
174
+ same connection to two threads.
175
+
176
+ Fixes #25585.
177
+
178
+ *Matthew Draper*
179
+
180
+ * Fixed dumping of foreign key's referential actions when MySQL connection
181
+ uses `sql_mode = ANSI_QUOTES`.
182
+
183
+ Fixes #25300.
184
+
185
+ *Ryuta Kamizono*
186
+
187
+
1
188
  ## Rails 5.0.0 (June 30, 2016) ##
2
189
 
190
+ * Inspecting an object with an associated array of over 10 elements no longer
191
+ truncates the array, preventing `inspect` from looping infinitely in some
192
+ cases.
193
+
194
+ *Kevin McPhillips*
195
+
3
196
  * Ensure hashes can be assigned to attributes created using `composed_of`.
197
+
4
198
  Fixes #25210.
5
199
 
6
200
  *Sean Griffin*
@@ -279,7 +473,7 @@
279
473
 
280
474
  *Takashi Kokubun*
281
475
 
282
- * Add ActiveRecord `#second_to_last` and `#third_to_last` methods.
476
+ * Add `#second_to_last` and `#third_to_last` finder methods.
283
477
 
284
478
  *Brian Christian*
285
479
 
@@ -1020,7 +1214,7 @@
1020
1214
 
1021
1215
  *Mehmet Emin İNAÇ*
1022
1216
 
1023
- * Add `cache_key` to ActiveRecord::Relation.
1217
+ * Add `cache_key` to `ActiveRecord::Relation`.
1024
1218
 
1025
1219
  Example:
1026
1220
 
@@ -192,7 +192,7 @@ The latest version of Active Record can be installed with RubyGems:
192
192
 
193
193
  Source code can be downloaded as part of the Rails project on GitHub:
194
194
 
195
- * https://github.com/rails/rails/tree/master/activerecord
195
+ * https://github.com/rails/rails/tree/5-0-stable/activerecord
196
196
 
197
197
 
198
198
  == License
@@ -68,7 +68,6 @@ module ActiveRecord
68
68
  autoload :StatementCache
69
69
  autoload :Store
70
70
  autoload :Suppressor
71
- autoload :TableMetadata
72
71
  autoload :Timestamp
73
72
  autoload :Transactions
74
73
  autoload :Translation
@@ -101,6 +100,7 @@ module ActiveRecord
101
100
  end
102
101
 
103
102
  autoload :Result
103
+ autoload :TableMetadata
104
104
  end
105
105
 
106
106
  module Coders
@@ -261,8 +261,10 @@ module ActiveRecord
261
261
  part = converter.respond_to?(:call) ? converter.call(part) : klass.send(converter, part)
262
262
  end
263
263
 
264
- if part.is_a?(Hash)
265
- raise ArgumentError unless part.size == part.keys.max
264
+ hash_from_multiparameter_assignment = part.is_a?(Hash) &&
265
+ part.each_key.all? { |k| k.is_a?(Integer) }
266
+ if hash_from_multiparameter_assignment
267
+ raise ArgumentError unless part.size == part.each_key.max
266
268
  part = klass.new(*part.sort.map(&:last))
267
269
  end
268
270
 
@@ -29,7 +29,10 @@ module ActiveRecord
29
29
  private
30
30
 
31
31
  def exec_queries
32
- super.each { |r| @association.set_inverse_instance r }
32
+ super do |r|
33
+ @association.set_inverse_instance r
34
+ yield r if block_given?
35
+ end
33
36
  end
34
37
  end
35
38
  end
@@ -224,6 +224,11 @@ module ActiveRecord
224
224
  autoload :AliasTracker
225
225
  end
226
226
 
227
+ def self.eager_load!
228
+ super
229
+ Preloader.eager_load!
230
+ end
231
+
227
232
  # Returns the association instance for the given name, instantiating it if it doesn't already exist
228
233
  def association(name) #:nodoc:
229
234
  association = association_instance_get(name)
@@ -76,8 +76,10 @@ module ActiveRecord::Associations::Builder # :nodoc:
76
76
  left_model.retrieve_connection
77
77
  end
78
78
 
79
- def self.primary_key
80
- false
79
+ private
80
+
81
+ def self.suppress_composite_primary_key(pk)
82
+ pk unless pk.is_a?(Array)
81
83
  end
82
84
  }
83
85
 
@@ -8,7 +8,16 @@ module ActiveRecord::Associations::Builder # :nodoc:
8
8
 
9
9
  def self.define_accessors(model, reflection)
10
10
  super
11
- define_constructors(model.generated_association_methods, reflection.name) if reflection.constructable?
11
+ mixin = model.generated_association_methods
12
+ name = reflection.name
13
+
14
+ define_constructors(mixin, name) if reflection.constructable?
15
+
16
+ mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
17
+ def reload_#{name}
18
+ association(:#{name}).force_reload_reader
19
+ end
20
+ CODE
12
21
  end
13
22
 
14
23
  # Defines the (build|create)_association methods for belongs_to or has_one association
@@ -69,13 +69,17 @@ module ActiveRecord
69
69
 
70
70
  # Implements the ids writer method, e.g. foo.item_ids= for Foo.has_many :items
71
71
  def ids_writer(ids)
72
- pk_type = reflection.primary_key_type
72
+ pk_type = reflection.association_primary_key_type
73
73
  ids = Array(ids).reject(&:blank?)
74
74
  ids.map! { |i| pk_type.cast(i) }
75
75
  records = klass.where(reflection.association_primary_key => ids).index_by do |r|
76
76
  r.send(reflection.association_primary_key)
77
- end.values_at(*ids)
78
- replace(records)
77
+ end.values_at(*ids).compact
78
+ if records.size != ids.size
79
+ scope.raise_record_not_found_exception!(ids, records.size, ids.size, reflection.association_primary_key)
80
+ else
81
+ replace(records)
82
+ end
79
83
  end
80
84
 
81
85
  def reset
@@ -312,9 +316,9 @@ module ActiveRecord
312
316
  else
313
317
  target.size
314
318
  end
315
- elsif !loaded? && !association_scope.group_values.empty?
319
+ elsif !association_scope.group_values.empty?
316
320
  load_target.size
317
- elsif !loaded? && !association_scope.distinct_value && target.is_a?(Array)
321
+ elsif !association_scope.distinct_value && target.is_a?(Array)
318
322
  unsaved_records = target.select(&:new_record?)
319
323
  unsaved_records.size + count_records
320
324
  else
@@ -426,15 +430,12 @@ module ActiveRecord
426
430
  def replace_on_target(record, index, skip_callbacks)
427
431
  callback(:before_add, record) unless skip_callbacks
428
432
 
429
- was_loaded = loaded?
430
433
  yield(record) if block_given?
431
434
 
432
- unless !was_loaded && loaded?
433
- if index
434
- @target[index] = record
435
- else
436
- @target << record
437
- end
435
+ if index
436
+ @target[index] = record
437
+ else
438
+ append_record(record)
438
439
  end
439
440
 
440
441
  callback(:after_add, record) unless skip_callbacks
@@ -454,7 +455,7 @@ module ActiveRecord
454
455
  end
455
456
 
456
457
  private
457
- def get_records
458
+ def get_records(&block)
458
459
  return scope.to_a if skip_statement_cache?
459
460
 
460
461
  conn = klass.connection
@@ -466,13 +467,13 @@ module ActiveRecord
466
467
  end
467
468
 
468
469
  binds = AssociationScope.get_bind_values(owner, reflection.chain)
469
- sc.execute binds, klass, klass.connection
470
+ sc.execute(binds, klass, klass.connection, &block)
470
471
  end
471
472
 
472
473
  def find_target
473
- records = get_records
474
- records.each { |record| set_inverse_instance(record) }
475
- records
474
+ get_records do |record|
475
+ set_inverse_instance(record)
476
+ end
476
477
  end
477
478
 
478
479
  # We have some records loaded from the database (persisted) and some that are
@@ -657,6 +658,10 @@ module ActiveRecord
657
658
  set_inverse_instance record if record.is_a? ActiveRecord::Base
658
659
  end
659
660
  end
661
+
662
+ def append_record(record)
663
+ @target << record unless @target.include?(record)
664
+ end
660
665
  end
661
666
  end
662
667
  end
@@ -28,8 +28,7 @@ module ActiveRecord
28
28
  # is computed directly through SQL and does not trigger by itself the
29
29
  # instantiation of the actual post records.
30
30
  class CollectionProxy < Relation
31
- delegate(*(ActiveRecord::Calculations.public_instance_methods - [:count]), to: :scope)
32
- delegate :find_nth, to: :scope
31
+ delegate :exists?, :update_all, :arel, to: :scope
33
32
 
34
33
  def initialize(klass, association) #:nodoc:
35
34
  @association = association
@@ -732,6 +731,14 @@ module ActiveRecord
732
731
  @association.count(column_name)
733
732
  end
734
733
 
734
+ def calculate(operation, column_name)
735
+ null_scope? ? scope.calculate(operation, column_name) : super
736
+ end
737
+
738
+ def pluck(*column_names)
739
+ null_scope? ? scope.pluck(*column_names) : super
740
+ end
741
+
735
742
  # Returns the size of the collection. If the collection hasn't been loaded,
736
743
  # it executes a <tt>SELECT COUNT(*)</tt> query. Else it calls <tt>collection.size</tt>.
737
744
  #
@@ -787,7 +794,7 @@ module ActiveRecord
787
794
  # Returns +true+ if the collection is empty. If the collection has been
788
795
  # loaded it is equivalent
789
796
  # to <tt>collection.size.zero?</tt>. If the collection has not been loaded,
790
- # it is equivalent to <tt>collection.exists?</tt>. If the collection has
797
+ # it is equivalent to <tt>!collection.exists?</tt>. If the collection has
791
798
  # not already been loaded and you are going to fetch the records anyway it
792
799
  # is better to check <tt>collection.length.zero?</tt>.
793
800
  #
@@ -891,10 +898,6 @@ module ActiveRecord
891
898
  !!@association.include?(record)
892
899
  end
893
900
 
894
- def arel #:nodoc:
895
- scope.arel
896
- end
897
-
898
901
  def proxy_association
899
902
  @association
900
903
  end
@@ -1068,6 +1071,16 @@ module ActiveRecord
1068
1071
  proxy_association.reset_scope
1069
1072
  self
1070
1073
  end
1074
+
1075
+ private
1076
+
1077
+ def null_scope?
1078
+ @association.null_scope?
1079
+ end
1080
+
1081
+ def exec_queries
1082
+ load_target
1083
+ end
1071
1084
  end
1072
1085
  end
1073
1086
  end