activerecord 6.1.0 → 6.1.6.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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +466 -26
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/active_record/aggregations.rb +4 -4
  6. data/lib/active_record/association_relation.rb +10 -0
  7. data/lib/active_record/associations/association.rb +13 -7
  8. data/lib/active_record/associations/association_scope.rb +7 -5
  9. data/lib/active_record/associations/belongs_to_association.rb +8 -5
  10. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +7 -2
  11. data/lib/active_record/associations/builder/association.rb +23 -2
  12. data/lib/active_record/associations/builder/belongs_to.rb +2 -2
  13. data/lib/active_record/associations/collection_association.rb +16 -8
  14. data/lib/active_record/associations/has_many_association.rb +1 -1
  15. data/lib/active_record/associations/join_dependency/join_association.rb +8 -7
  16. data/lib/active_record/associations/join_dependency.rb +1 -1
  17. data/lib/active_record/associations/preloader/association.rb +1 -3
  18. data/lib/active_record/associations.rb +6 -2
  19. data/lib/active_record/attributes.rb +1 -1
  20. data/lib/active_record/coders/yaml_column.rb +13 -1
  21. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +5 -5
  22. data/lib/active_record/connection_adapters/abstract/database_statements.rb +1 -1
  23. data/lib/active_record/connection_adapters/abstract/query_cache.rb +1 -1
  24. data/lib/active_record/connection_adapters/abstract/quoting.rb +3 -3
  25. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +1 -1
  26. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +8 -0
  27. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +7 -1
  28. data/lib/active_record/connection_adapters/abstract/transaction.rb +14 -3
  29. data/lib/active_record/connection_adapters/abstract_adapter.rb +10 -11
  30. data/lib/active_record/connection_adapters/legacy_pool_manager.rb +6 -2
  31. data/lib/active_record/connection_adapters/mysql/database_statements.rb +2 -0
  32. data/lib/active_record/connection_adapters/mysql/quoting.rb +17 -2
  33. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +4 -1
  34. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +4 -1
  35. data/lib/active_record/connection_adapters/pool_config.rb +13 -3
  36. data/lib/active_record/connection_adapters/pool_manager.rb +5 -1
  37. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +3 -1
  38. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
  39. data/lib/active_record/connection_adapters/postgresql_adapter.rb +2 -8
  40. data/lib/active_record/connection_adapters/schema_cache.rb +43 -11
  41. data/lib/active_record/connection_adapters/sql_type_metadata.rb +0 -2
  42. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +2 -0
  43. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
  44. data/lib/active_record/connection_adapters.rb +2 -0
  45. data/lib/active_record/connection_handling.rb +22 -14
  46. data/lib/active_record/core.rb +68 -31
  47. data/lib/active_record/database_configurations/connection_url_resolver.rb +1 -0
  48. data/lib/active_record/database_configurations/hash_config.rb +1 -1
  49. data/lib/active_record/database_configurations/url_config.rb +1 -1
  50. data/lib/active_record/database_configurations.rb +2 -1
  51. data/lib/active_record/enum.rb +52 -34
  52. data/lib/active_record/fixtures.rb +5 -2
  53. data/lib/active_record/gem_version.rb +2 -2
  54. data/lib/active_record/insert_all.rb +5 -1
  55. data/lib/active_record/internal_metadata.rb +2 -0
  56. data/lib/active_record/legacy_yaml_adapter.rb +1 -1
  57. data/lib/active_record/locking/optimistic.rb +14 -4
  58. data/lib/active_record/log_subscriber.rb +3 -2
  59. data/lib/active_record/migration/compatibility.rb +9 -5
  60. data/lib/active_record/migration.rb +1 -1
  61. data/lib/active_record/model_schema.rb +5 -5
  62. data/lib/active_record/railtie.rb +18 -0
  63. data/lib/active_record/railties/console_sandbox.rb +2 -4
  64. data/lib/active_record/railties/databases.rake +24 -17
  65. data/lib/active_record/reflection.rb +1 -1
  66. data/lib/active_record/relation/calculations.rb +8 -4
  67. data/lib/active_record/relation/finder_methods.rb +2 -2
  68. data/lib/active_record/relation/predicate_builder/association_query_value.rb +3 -3
  69. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +9 -5
  70. data/lib/active_record/relation/predicate_builder.rb +5 -6
  71. data/lib/active_record/relation/query_methods.rb +11 -8
  72. data/lib/active_record/relation/where_clause.rb +19 -16
  73. data/lib/active_record/relation.rb +10 -17
  74. data/lib/active_record/scoping/default.rb +1 -3
  75. data/lib/active_record/signed_id.rb +1 -1
  76. data/lib/active_record/statement_cache.rb +2 -2
  77. data/lib/active_record/table_metadata.rb +6 -3
  78. data/lib/active_record/tasks/database_tasks.rb +2 -1
  79. data/lib/active_record/test_fixtures.rb +42 -1
  80. data/lib/active_record/transactions.rb +4 -2
  81. data/lib/active_record/validations/numericality.rb +1 -1
  82. data/lib/active_record.rb +1 -1
  83. data/lib/arel/collectors/bind.rb +2 -2
  84. data/lib/arel/collectors/composite.rb +3 -3
  85. data/lib/arel/collectors/sql_string.rb +1 -1
  86. data/lib/arel/collectors/substitute_binds.rb +1 -1
  87. data/lib/arel/nodes/homogeneous_in.rb +4 -0
  88. data/lib/arel/predications.rb +2 -2
  89. data/lib/arel/visitors/to_sql.rb +1 -1
  90. metadata +14 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 418812373f3ff5fd16133fe0928b94b80b78b8a366abfc23a205fcb2ccc5a3e3
4
- data.tar.gz: 70db1902a8fc82b1c46f8a7731ffb358357bc8cac29564a57881a732dbd2a65a
3
+ metadata.gz: 2093e13defc611f0ec1e62d7efd445bcd1c5b182d8aab24f3dd3625047ce2f9f
4
+ data.tar.gz: 8d3e9a6daab9d0026cc1826d1caf2f24fee239d05b63cbb0eac866b1daded767
5
5
  SHA512:
6
- metadata.gz: 31ae64f629cb62f63bc37c74a888d557f9f0b102d401f2f9cf62c7d31655d99e5161ae9bc7f8be874c7a9cf27ec879dde3c04075df5cb2b5868891c0db144a50
7
- data.tar.gz: cfc9585f3a6f53187707a9d96503269e3d4b1c5f1fe8c5f4db3bdefe8ce636042b6cf1fe9fb233491d1e8197f52293a7018a2f9925f1e34644ad1e30b134d59f
6
+ metadata.gz: 3e6be64f1492b2441290abac0af6cde31950acef133ccdd98202b2ab719dc48b0f969eda318b4712c508cde2f29b3a6c381c27c6e7467b4ee25ec97209717d7a
7
+ data.tar.gz: 924c8bcbbaa608deb02263437e76947737b041b39a86818585e3d087530f0d1e3fdc537fc10d1177fe6cf2413deaf47f655342435312a5d473a4789e7a35631f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,443 @@
1
+ ## Rails 6.1.6.1 (July 12, 2022) ##
2
+
3
+ * Change ActiveRecord::Coders::YAMLColumn default to safe_load
4
+
5
+ This adds two new configuration options The configuration options are as
6
+ follows:
7
+
8
+ * `config.active_storage.use_yaml_unsafe_load`
9
+
10
+ When set to true, this configuration option tells Rails to use the old
11
+ "unsafe" YAML loading strategy, maintaining the existing behavior but leaving
12
+ the possible escalation vulnerability in place. Setting this option to true
13
+ is *not* recommended, but can aid in upgrading.
14
+
15
+ * `config.active_record.yaml_column_permitted_classes`
16
+
17
+ The "safe YAML" loading method does not allow all classes to be deserialized
18
+ by default. This option allows you to specify classes deemed "safe" in your
19
+ application. For example, if your application uses Symbol and Time in
20
+ serialized data, you can add Symbol and Time to the allowed list as follows:
21
+
22
+ ```
23
+ config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
24
+ ```
25
+
26
+ [CVE-2022-32224]
27
+
28
+
29
+ ## Rails 6.1.5.1 (April 26, 2022) ##
30
+
31
+ * No changes.
32
+
33
+
34
+ ## Rails 6.1.5 (March 09, 2022) ##
35
+
36
+ * Fix `ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` for Ruby 2.6.
37
+
38
+ Ruby 2.6 and 2.7 have slightly different implementations of the `String#-@` method.
39
+ In Ruby 2.6, the receiver of the `String#-@` method is modified under certain circumstances.
40
+ This was later identified as a bug (https://bugs.ruby-lang.org/issues/15926) and only
41
+ fixed in Ruby 2.7.
42
+
43
+ Before the changes in this commit, the
44
+ `ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` method, which internally
45
+ calls the `String#-@` method, could also modify an input string argument in Ruby 2.6 --
46
+ changing a tainted, unfrozen string into a tainted, frozen string.
47
+
48
+ Fixes #43056
49
+
50
+ *Eric O'Hanlon*
51
+
52
+ * Fix migration compatibility to create SQLite references/belongs_to column as integer when
53
+ migration version is 6.0.
54
+
55
+ `reference`/`belongs_to` in migrations with version 6.0 were creating columns as
56
+ bigint instead of integer for the SQLite Adapter.
57
+
58
+ *Marcelo Lauxen*
59
+
60
+ * Fix dbconsole for 3-tier config.
61
+
62
+ *Eileen M. Uchitelle*
63
+
64
+ * Better handle SQL queries with invalid encoding.
65
+
66
+ ```ruby
67
+ Post.create(name: "broken \xC8 UTF-8")
68
+ ```
69
+
70
+ Would cause all adapters to fail in a non controlled way in the code
71
+ responsible to detect write queries.
72
+
73
+ The query is now properly passed to the database connection, which might or might
74
+ not be able to handle it, but will either succeed or failed in a more correct way.
75
+
76
+ *Jean Boussier*
77
+
78
+ * Ignore persisted in-memory records when merging target lists.
79
+
80
+ *Kevin Sjöberg*
81
+
82
+ * Fix regression bug that caused ignoring additional conditions for preloading
83
+ `has_many` through relations.
84
+
85
+ Fixes #43132
86
+
87
+ *Alexander Pauly*
88
+
89
+ * Fix `ActiveRecord::InternalMetadata` to not be broken by
90
+ `config.active_record.record_timestamps = false`
91
+
92
+ Since the model always create the timestamp columns, it has to set them, otherwise it breaks
93
+ various DB management tasks.
94
+
95
+ Fixes #42983
96
+
97
+ *Jean Boussier*
98
+
99
+ * Fix duplicate active record objects on `inverse_of`.
100
+
101
+ *Justin Carvalho*
102
+
103
+ * Fix duplicate objects stored in has many association after save.
104
+
105
+ Fixes #42549.
106
+
107
+ *Alex Ghiculescu*
108
+
109
+ * Fix performance regression in `CollectionAssocation#build`.
110
+
111
+ *Alex Ghiculescu*
112
+
113
+ * Fix retrieving default value for text column for MariaDB.
114
+
115
+ *fatkodima*
116
+
117
+
118
+ ## Rails 6.1.4.7 (March 08, 2022) ##
119
+
120
+ * No changes.
121
+
122
+
123
+ ## Rails 6.1.4.6 (February 11, 2022) ##
124
+
125
+ * No changes.
126
+
127
+
128
+ ## Rails 6.1.4.5 (February 11, 2022) ##
129
+
130
+ * No changes.
131
+
132
+
133
+ ## Rails 6.1.4.4 (December 15, 2021) ##
134
+
135
+ * No changes.
136
+
137
+
138
+ ## Rails 6.1.4.3 (December 14, 2021) ##
139
+
140
+ * No changes.
141
+
142
+
143
+ ## Rails 6.1.4.2 (December 14, 2021) ##
144
+
145
+ * No changes.
146
+
147
+
148
+ ## Rails 6.1.4.1 (August 19, 2021) ##
149
+
150
+ * No changes.
151
+
152
+
153
+ ## Rails 6.1.4 (June 24, 2021) ##
154
+
155
+ * Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
156
+
157
+ *Jamie McCarthy*
158
+
159
+ * Raise an error if `pool_config` is `nil` in `set_pool_config`.
160
+
161
+ *Eileen M. Uchitelle*
162
+
163
+ * Fix compatibility with `psych >= 4`.
164
+
165
+ Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load`. To preserve compatibility
166
+ Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
167
+
168
+ *Jean Boussier*
169
+
170
+ * Support using replicas when using `rails dbconsole`.
171
+
172
+ *Christopher Thornton*
173
+
174
+ * Restore connection pools after transactional tests.
175
+
176
+ *Eugene Kenny*
177
+
178
+ * Change `upsert_all` to fails cleanly for MySQL when `:unique_by` is used.
179
+
180
+ *Bastian Bartmann*
181
+
182
+ * Fix user-defined `self.default_scope` to respect table alias.
183
+
184
+ *Ryuta Kamizono*
185
+
186
+ * Clear `@cache_keys` cache after `update_all`, `delete_all`, `destroy_all`.
187
+
188
+ *Ryuta Kamizono*
189
+
190
+ * Changed Arel predications `contains` and `overlaps` to use
191
+ `quoted_node` so that PostgreSQL arrays are quoted properly.
192
+
193
+ *Bradley Priest*
194
+
195
+ * Fix `merge` when the `where` clauses have string contents.
196
+
197
+ *Ryuta Kamizono*
198
+
199
+ * Fix rollback of parent destruction with nested `dependent: :destroy`.
200
+
201
+ *Jacopo Beschi*
202
+
203
+ * Fix binds logging for `"WHERE ... IN ..."` statements.
204
+
205
+ *Ricardo Díaz*
206
+
207
+ * Handle `false` in relation strict loading checks.
208
+
209
+ Previously when a model had strict loading set to true and then had a
210
+ relation set `strict_loading` to false the false wasn't considered when
211
+ deciding whether to raise/warn about strict loading.
212
+
213
+ ```
214
+ class Dog < ActiveRecord::Base
215
+ self.strict_loading_by_default = true
216
+
217
+ has_many :treats, strict_loading: false
218
+ end
219
+ ```
220
+
221
+ In the example, `dog.treats` would still raise even though
222
+ `strict_loading` was set to false. This is a bug affecting more than
223
+ Active Storage which is why I made this PR superseding #41461. We need
224
+ to fix this for all applications since the behavior is a little
225
+ surprising. I took the test from #41461 and the code suggestion from #41453
226
+ with some additions.
227
+
228
+ *Eileen M. Uchitelle*, *Radamés Roriz*
229
+
230
+ * Fix numericality validator without precision.
231
+
232
+ *Ryuta Kamizono*
233
+
234
+ * Fix aggregate attribute on Enum types.
235
+
236
+ *Ryuta Kamizono*
237
+
238
+ * Fix `CREATE INDEX` statement generation for PostgreSQL.
239
+
240
+ *eltongo*
241
+
242
+ * Fix where clause on enum attribute when providing array of strings.
243
+
244
+ *Ryuta Kamizono*
245
+
246
+ * Fix `unprepared_statement` to work it when nesting.
247
+
248
+ *Ryuta Kamizono*
249
+
250
+
251
+ ## Rails 6.1.3.2 (May 05, 2021) ##
252
+
253
+ * No changes.
254
+
255
+
256
+ ## Rails 6.1.3.1 (March 26, 2021) ##
257
+
258
+ * No changes.
259
+
260
+
261
+ ## Rails 6.1.3 (February 17, 2021) ##
262
+
263
+ * Fix the MySQL adapter to always set the right collation and charset
264
+ to the connection session.
265
+
266
+ *Rafael Mendonça França*
267
+
268
+ * Fix MySQL adapter handling of time objects when prepared statements
269
+ are enabled.
270
+
271
+ *Rafael Mendonça França*
272
+
273
+ * Fix scoping in enum fields using conditions that would generate
274
+ an `IN` clause.
275
+
276
+ *Ryuta Kamizono*
277
+
278
+ * Skip optimised #exist? query when #include? is called on a relation
279
+ with a having clause
280
+
281
+ Relations that have aliased select values AND a having clause that
282
+ references an aliased select value would generate an error when
283
+ #include? was called, due to an optimisation that would generate
284
+ call #exists? on the relation instead, which effectively alters
285
+ the select values of the query (and thus removes the aliased select
286
+ values), but leaves the having clause intact. Because the having
287
+ clause is then referencing an aliased column that is no longer
288
+ present in the simplified query, an ActiveRecord::InvalidStatement
289
+ error was raised.
290
+
291
+ An sample query affected by this problem:
292
+
293
+ ```ruby
294
+ Author.select('COUNT(*) as total_posts', 'authors.*')
295
+ .joins(:posts)
296
+ .group(:id)
297
+ .having('total_posts > 2')
298
+ .include?(Author.first)
299
+ ```
300
+
301
+ This change adds an addition check to the condition that skips the
302
+ simplified #exists? query, which simply checks for the presence of
303
+ a having clause.
304
+
305
+ Fixes #41417
306
+
307
+ *Michael Smart*
308
+
309
+ * Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
310
+ without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
311
+ up in perpetual crash state for being inconsistent with Postgres.
312
+
313
+ *wbharding*, *Martin Tepper*
314
+
315
+
316
+ ## Rails 6.1.2.1 (February 10, 2021) ##
317
+
318
+ * Fix possible DoS vector in PostgreSQL money type
319
+
320
+ Carefully crafted input can cause a DoS via the regular expressions used
321
+ for validating the money format in the PostgreSQL adapter. This patch
322
+ fixes the regexp.
323
+
324
+ Thanks to @dee-see from Hackerone for this patch!
325
+
326
+ [CVE-2021-22880]
327
+
328
+ *Aaron Patterson*
329
+
330
+
331
+ ## Rails 6.1.2 (February 09, 2021) ##
332
+
333
+ * Fix timestamp type for sqlite3.
334
+
335
+ *Eileen M. Uchitelle*
336
+
337
+ * Make destroy async transactional.
338
+
339
+ An active record rollback could occur while enqueuing a job. In this
340
+ case the job would enqueue even though the database deletion
341
+ rolledback putting things in a funky state.
342
+
343
+ Now the jobs are only enqueued until after the db transaction has been committed.
344
+
345
+ *Cory Gwin*
346
+
347
+ * Fix malformed packet error in MySQL statement for connection configuration.
348
+
349
+ *robinroestenburg*
350
+
351
+ * Connection specification now passes the "url" key as a configuration for the
352
+ adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
353
+ urls with the "jdbc" prefix were passed to the Active Record Adapter, others
354
+ are assumed to be adapter specification urls.
355
+
356
+ Fixes #41137.
357
+
358
+ *Jonathan Bracy*
359
+
360
+ * Fix granular connection swapping when there are multiple abstract classes.
361
+
362
+ *Eileen M. Uchitelle*
363
+
364
+ * Fix `find_by` with custom primary key for belongs_to association.
365
+
366
+ *Ryuta Kamizono*
367
+
368
+ * Add support for `rails console --sandbox` for multiple database applications.
369
+
370
+ *alpaca-tc*
371
+
372
+ * Fix `where` on polymorphic association with empty array.
373
+
374
+ *Ryuta Kamizono*
375
+
376
+ * Fix preventing writes for `ApplicationRecord`.
377
+
378
+ *Eileen M. Uchitelle*
379
+
380
+
381
+ ## Rails 6.1.1 (January 07, 2021) ##
382
+
383
+ * Fix fixtures loading when strict loading is enabled for the association.
384
+
385
+ *Alex Ghiculescu*
386
+
387
+ * Fix `where` with custom primary key for belongs_to association.
388
+
389
+ *Ryuta Kamizono*
390
+
391
+ * Fix `where` with aliased associations.
392
+
393
+ *Ryuta Kamizono*
394
+
395
+ * Fix `composed_of` with symbol mapping.
396
+
397
+ *Ryuta Kamizono*
398
+
399
+ * Don't skip money's type cast for pluck and calculations.
400
+
401
+ *Ryuta Kamizono*
402
+
403
+ * Fix `where` on polymorphic association with non Active Record object.
404
+
405
+ *Ryuta Kamizono*
406
+
407
+ * Make sure `db:prepare` works even the schema file doesn't exist.
408
+
409
+ *Rafael Mendonça França*
410
+
411
+ * Fix complicated `has_many :through` with nested where condition.
412
+
413
+ *Ryuta Kamizono*
414
+
415
+ * Handle STI models for `has_many dependent: :destroy_async`.
416
+
417
+ *Muhammad Usman*
418
+
419
+ * Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
420
+
421
+ Previously, passing `false` would trigger the option validation logic
422
+ to throw an error saying :polymorphic would not be a valid option.
423
+
424
+ *glaszig*
425
+
426
+ * Allow adding nonnamed expression indexes to be revertible.
427
+
428
+ Fixes #40732.
429
+
430
+ Previously, the following code would raise an error, when executed while rolling back,
431
+ and the index name should be specified explicitly. Now, the index name is inferred
432
+ automatically.
433
+
434
+ ```ruby
435
+ add_index(:items, "to_tsvector('english', description)")
436
+ ```
437
+
438
+ *fatkodima*
439
+
440
+
1
441
  ## Rails 6.1.0 (December 09, 2020) ##
2
442
 
3
443
  * Only warn about negative enums if a positive form that would cause conflicts exists.
@@ -38,21 +478,21 @@
38
478
 
39
479
  Before:
40
480
 
41
- AnimalsRecord.connected_to(role: :reading) do
42
- MealsRecord.connected_to(role: :reading) do
43
- Dog.first # read from animals replica
44
- Dinner.first # read from meals replica
45
- Person.first # read from primary writer
481
+ AnimalsRecord.connected_to(role: :reading) do
482
+ MealsRecord.connected_to(role: :reading) do
483
+ Dog.first # read from animals replica
484
+ Dinner.first # read from meals replica
485
+ Person.first # read from primary writer
486
+ end
46
487
  end
47
- end
48
488
 
49
489
  After:
50
490
 
51
- ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
52
- Dog.first # read from animals replica
53
- Dinner.first # read from meals replica
54
- Person.first # read from primary writer
55
- end
491
+ ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
492
+ Dog.first # read from animals replica
493
+ Dinner.first # read from meals replica
494
+ Person.first # read from primary writer
495
+ end
56
496
 
57
497
  *Eileen M. Uchitelle*, *John Crepezzi*
58
498
 
@@ -170,13 +610,13 @@
170
610
 
171
611
  Before:
172
612
 
173
- User.where.not(name: "Jon", role: "admin")
174
- # SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
613
+ User.where.not(name: "Jon", role: "admin")
614
+ # SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
175
615
 
176
616
  After:
177
617
 
178
- User.where.not(name: "Jon", role: "admin")
179
- # SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
618
+ User.where.not(name: "Jon", role: "admin")
619
+ # SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
180
620
 
181
621
  *Rafael Mendonça França*
182
622
 
@@ -284,7 +724,7 @@
284
724
 
285
725
  attribute :duration, :interval
286
726
 
287
- To keep old behavior until 6.2 is released:
727
+ To keep old behavior until 7.0 is released:
288
728
 
289
729
  attribute :duration, :string
290
730
 
@@ -456,8 +896,8 @@
456
896
  *Ryuta Kamizono*
457
897
 
458
898
  * Merging conditions on the same column no longer maintain both conditions,
459
- and will be consistently replaced by the latter condition in Rails 6.2.
460
- To migrate to Rails 6.2's behavior, use `relation.merge(other, rewhere: true)`.
899
+ and will be consistently replaced by the latter condition in Rails 7.0.
900
+ To migrate to Rails 7.0's behavior, use `relation.merge(other, rewhere: true)`.
461
901
 
462
902
  ```ruby
463
903
  # Rails 6.1 (IN clause is replaced by merger side equality condition)
@@ -466,10 +906,10 @@
466
906
  # Rails 6.1 (both conflict conditions exists, deprecated)
467
907
  Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
468
908
 
469
- # Rails 6.1 with rewhere to migrate to Rails 6.2's behavior
909
+ # Rails 6.1 with rewhere to migrate to Rails 7.0's behavior
470
910
  Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
471
911
 
472
- # Rails 6.2 (same behavior with IN clause, mergee side condition is consistently replaced)
912
+ # Rails 7.0 (same behavior with IN clause, mergee side condition is consistently replaced)
473
913
  Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
474
914
  Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
475
915
  ```
@@ -561,7 +1001,7 @@
561
1001
 
562
1002
  * Deprecate aggregations with group by duplicated fields.
563
1003
 
564
- To migrate to Rails 6.2's behavior, use `uniq!(:group)` to deduplicate group fields.
1004
+ To migrate to Rails 7.0's behavior, use `uniq!(:group)` to deduplicate group fields.
565
1005
 
566
1006
  ```ruby
567
1007
  accounts = Account.group(:firm_id)
@@ -585,7 +1025,7 @@
585
1025
 
586
1026
  * Deprecate duplicated query annotations.
587
1027
 
588
- To migrate to Rails 6.2's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
1028
+ To migrate to Rails 7.0's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
589
1029
 
590
1030
  ```ruby
591
1031
  accounts = Account.where(id: [1, 2]).annotate("david and mary")
@@ -863,14 +1303,14 @@
863
1303
  Deprecated behavior:
864
1304
 
865
1305
  ```ruby
866
- db_config = ActiveRecord::Base.configs_for(env_name: "development", spec_name: "primary")
1306
+ db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
867
1307
  db_config.spec_name
868
1308
  ```
869
1309
 
870
1310
  New behavior:
871
1311
 
872
1312
  ```ruby
873
- db_config = ActiveRecord::Base.configs_for(env_name: "development", name: "primary")
1313
+ db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary")
874
1314
  db_config.name
875
1315
  ```
876
1316
 
@@ -1006,13 +1446,13 @@
1006
1446
 
1007
1447
  * Deprecate `#remove_connection` in favor of `#remove_connection_pool` when called on the handler.
1008
1448
 
1009
- `#remove_connection` is deprecated in order to support returning a `DatabaseConfig` object instead of a `Hash`. Use `#remove_connection_pool`, `#remove_connection` will be removed in 6.2.
1449
+ `#remove_connection` is deprecated in order to support returning a `DatabaseConfig` object instead of a `Hash`. Use `#remove_connection_pool`, `#remove_connection` will be removed in Rails 7.0.
1010
1450
 
1011
1451
  *Eileen M. Uchitelle*, *John Crepezzi*
1012
1452
 
1013
1453
  * Deprecate `#default_hash` and it's alias `#[]` on database configurations.
1014
1454
 
1015
- Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in 6.2.
1455
+ Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in Rails 7.0.
1016
1456
 
1017
1457
  *Eileen M. Uchitelle*, *John Crepezzi*
1018
1458
 
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004-2020 David Heinemeier Hansson
1
+ Copyright (c) 2004-2022 David Heinemeier Hansson
2
2
 
3
3
  Arel originally copyright (c) 2007-2016 Nick Kallen, Bryan Helmkamp, Emilio Tagua, Aaron Patterson
4
4
 
data/README.rdoc CHANGED
@@ -194,7 +194,7 @@ The latest version of Active Record can be installed with RubyGems:
194
194
 
195
195
  Source code can be downloaded as part of the Rails project on GitHub:
196
196
 
197
- * https://github.com/rails/rails/tree/master/activerecord
197
+ * https://github.com/rails/rails/tree/main/activerecord
198
198
 
199
199
 
200
200
  == License
@@ -244,8 +244,8 @@ module ActiveRecord
244
244
  private
245
245
  def reader_method(name, class_name, mapping, allow_nil, constructor)
246
246
  define_method(name) do
247
- if @aggregation_cache[name].nil? && (!allow_nil || mapping.any? { |key, _| !_read_attribute(key).nil? })
248
- attrs = mapping.collect { |key, _| _read_attribute(key) }
247
+ if @aggregation_cache[name].nil? && (!allow_nil || mapping.any? { |key, _| !read_attribute(key).nil? })
248
+ attrs = mapping.collect { |key, _| read_attribute(key) }
249
249
  object = constructor.respond_to?(:call) ?
250
250
  constructor.call(*attrs) :
251
251
  class_name.constantize.send(constructor, *attrs)
@@ -271,10 +271,10 @@ module ActiveRecord
271
271
  end
272
272
 
273
273
  if part.nil? && allow_nil
274
- mapping.each { |key, _| self[key] = nil }
274
+ mapping.each { |key, _| write_attribute(key, nil) }
275
275
  @aggregation_cache[name] = nil
276
276
  else
277
- mapping.each { |key, value| self[key] = part.send(value) }
277
+ mapping.each { |key, value| write_attribute(key, part.send(value)) }
278
278
  @aggregation_cache[name] = part.freeze
279
279
  end
280
280
  end
@@ -27,6 +27,16 @@ module ActiveRecord
27
27
  RUBY
28
28
  end
29
29
 
30
+ def build(attributes = nil, &block)
31
+ if attributes.is_a?(Array)
32
+ attributes.collect { |attr| build(attr, &block) }
33
+ else
34
+ block = current_scope_restoring_block(&block)
35
+ scoping { _new(attributes, &block) }
36
+ end
37
+ end
38
+ alias new build
39
+
30
40
  private
31
41
  def _new(attributes, &block)
32
42
  @association.build(attributes, &block)
@@ -211,12 +211,8 @@ module ActiveRecord
211
211
 
212
212
  private
213
213
  def find_target
214
- if owner.strict_loading? && owner.validation_context.nil?
215
- Base.strict_loading_violation!(owner: owner.class, association: klass)
216
- end
217
-
218
- if reflection.strict_loading? && owner.validation_context.nil?
219
- Base.strict_loading_violation!(owner: owner.class, association: reflection.name)
214
+ if strict_loading? && owner.validation_context.nil?
215
+ Base.strict_loading_violation!(owner: owner.class, reflection: reflection)
220
216
  end
221
217
 
222
218
  scope = self.scope
@@ -231,6 +227,12 @@ module ActiveRecord
231
227
  sc.execute(binds, klass.connection) { |record| set_inverse_instance(record) }
232
228
  end
233
229
 
230
+ def strict_loading?
231
+ return reflection.strict_loading? if reflection.options.key?(:strict_loading)
232
+
233
+ owner.strict_loading?
234
+ end
235
+
234
236
  # The scope for this association.
235
237
  #
236
238
  # Note that the association_scope is merged into the target_scope only when the
@@ -331,7 +333,11 @@ module ActiveRecord
331
333
  end
332
334
 
333
335
  def enqueue_destroy_association(options)
334
- owner.class.destroy_association_async_job&.perform_later(**options)
336
+ job_class = owner.class.destroy_association_async_job
337
+
338
+ if job_class
339
+ owner._after_commit_jobs.push([job_class, options])
340
+ end
335
341
  end
336
342
 
337
343
  def inversable?(record)