activerecord 7.0.4.3 → 7.0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +318 -7
  3. data/README.rdoc +2 -2
  4. data/lib/active_record/associations/collection_association.rb +1 -1
  5. data/lib/active_record/associations/collection_proxy.rb +5 -0
  6. data/lib/active_record/associations/preloader/through_association.rb +1 -1
  7. data/lib/active_record/associations.rb +15 -6
  8. data/lib/active_record/attribute_methods/read.rb +1 -1
  9. data/lib/active_record/attribute_methods/time_zone_conversion.rb +0 -4
  10. data/lib/active_record/attribute_methods.rb +5 -7
  11. data/lib/active_record/callbacks.rb +12 -14
  12. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +20 -16
  13. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +2 -1
  14. data/lib/active_record/connection_adapters/abstract_adapter.rb +4 -17
  15. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +15 -9
  16. data/lib/active_record/connection_adapters/mysql/database_statements.rb +1 -1
  17. data/lib/active_record/connection_adapters/mysql/quoting.rb +13 -2
  18. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +4 -1
  19. data/lib/active_record/connection_adapters/postgresql/column.rb +2 -0
  20. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +1 -5
  21. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
  22. data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +1 -1
  23. data/lib/active_record/connection_adapters/postgresql/quoting.rb +5 -2
  24. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +3 -2
  25. data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -10
  26. data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -1
  27. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +5 -2
  28. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +6 -0
  29. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +2 -2
  30. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +2 -4
  31. data/lib/active_record/disable_joins_association_relation.rb +1 -1
  32. data/lib/active_record/explain_subscriber.rb +1 -1
  33. data/lib/active_record/gem_version.rb +2 -2
  34. data/lib/active_record/locking/optimistic.rb +32 -18
  35. data/lib/active_record/middleware/database_selector.rb +3 -3
  36. data/lib/active_record/migration/command_recorder.rb +1 -2
  37. data/lib/active_record/migration/compatibility.rb +19 -54
  38. data/lib/active_record/migration.rb +53 -4
  39. data/lib/active_record/persistence.rb +7 -5
  40. data/lib/active_record/railties/controller_runtime.rb +3 -4
  41. data/lib/active_record/reflection.rb +8 -0
  42. data/lib/active_record/relation/calculations.rb +50 -23
  43. data/lib/active_record/relation/predicate_builder/association_query_value.rb +20 -1
  44. data/lib/active_record/relation/query_attribute.rb +23 -0
  45. data/lib/active_record/relation/query_methods.rb +35 -8
  46. data/lib/active_record/result.rb +6 -4
  47. data/lib/active_record/schema_dumper.rb +4 -0
  48. data/lib/active_record/store.rb +1 -1
  49. data/lib/active_record/table_metadata.rb +6 -2
  50. data/lib/active_record/transactions.rb +3 -3
  51. data/lib/active_record/type/serialized.rb +8 -4
  52. data/lib/arel/filter_predications.rb +1 -1
  53. data/lib/arel/nodes/and.rb +4 -0
  54. data/lib/arel/nodes/filter.rb +1 -1
  55. metadata +13 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1843d8f02a5d07f57fce55b1b30a097c2544aee0a3bf6b4a3b607fe8b5722c5
4
- data.tar.gz: 26ec900241ea5ac33a26eb695e970f50384215bcceade7b31ff9b7ab7da7ffc3
3
+ metadata.gz: d0dafed5cde1fc09899d9caea484b616eee6a654c8cdc2a4980900466a8e2ed5
4
+ data.tar.gz: 7a70971a3a00e75b2c1cce9c7e139a6eef609d0f3b650418ddf93c242e4539f0
5
5
  SHA512:
6
- metadata.gz: 10ab5e977258e62e32c71f893378b130fa980da5340e30c62a1150f57945605ba3c41fad811729f9bea5088581fc1d01cf64cad7312654efdd012e0b2df8111a
7
- data.tar.gz: 97d7537041f85e7ecfd7d035c3fd37df74e5cd3031993ee69342e7500c350c1dbc78cb9d248b05cc304fd0d6ca98e8b38747a98cb202c7138394c08f44849f85
6
+ metadata.gz: 770556493365d077a3bd6b825f2f1f68c7b2b124908ba8e5efd264d97f0ea7735c9594654017fb13d501d7e1818bf3a4d6e1435ce93e9081a39bae6f1d59851c
7
+ data.tar.gz: 30ddf2ad9e7eed26fe0ff9e453a7e201bd576ea0f0564dfded84333f4527e093f61b44fb02b2aedd4b2676354ba18e334ac17146b26ded1a6bbabda47d35221f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,314 @@
1
+ ## Rails 7.0.8.6 (October 23, 2024) ##
2
+
3
+ * No changes.
4
+
5
+
6
+ ## Rails 7.0.8.5 (October 15, 2024) ##
7
+
8
+ * No changes.
9
+
10
+
11
+ ## Rails 7.0.8.4 (June 04, 2024) ##
12
+
13
+ * No changes.
14
+
15
+
16
+ ## Rails 7.0.8.3 (May 17, 2024) ##
17
+
18
+ * No changes.
19
+
20
+
21
+ ## Rails 7.0.8.2 (May 16, 2024) ##
22
+
23
+ * No changes.
24
+
25
+
26
+ ## Rails 7.0.8.1 (February 21, 2024) ##
27
+
28
+ * No changes.
29
+
30
+
31
+ ## Rails 7.0.8 (September 09, 2023) ##
32
+
33
+ * Fix `change_column` not setting `precision: 6` on `datetime` columns when
34
+ using 7.0+ Migrations and SQLite.
35
+
36
+ *Hartley McGuire*
37
+
38
+ * Fix unscope is not working in specific case
39
+
40
+ Before:
41
+ ```ruby
42
+ Post.where(id: 1...3).unscope(where: :id).to_sql # "SELECT `posts`.* FROM `posts` WHERE `posts`.`id` >= 1 AND `posts`.`id` < 3"
43
+
44
+ ```
45
+
46
+ After:
47
+ ```ruby
48
+ Post.where(id: 1...3).unscope(where: :id).to_sql # "SELECT `posts`.* FROM `posts`"
49
+ ```
50
+
51
+ Fixes #48094.
52
+
53
+ *Kazuya Hatanaka*
54
+
55
+ * Fix associations to a STI model including a `class_name` parameter
56
+
57
+ ```ruby
58
+ class Product < ApplicationRecord
59
+ has_many :requests, as: :requestable, class_name: "ProductRequest", dependent: :destroy
60
+ end
61
+
62
+ # STI tables
63
+ class Request < ApplicationRecord
64
+ belongs_to :requestable, polymorphic: true
65
+
66
+ validate :request_type, presence: true
67
+ end
68
+
69
+ class ProductRequest < Request
70
+ belongs_to :user
71
+ end
72
+ ```
73
+
74
+ Accessing such association would lead to:
75
+
76
+ ```
77
+ table_metadata.rb:22:in `has_column?': undefined method `key?' for nil:NilClass (NoMethodError)
78
+ ```
79
+
80
+ *Romain Filinto*
81
+
82
+ * Fix `change_table` setting datetime precision for 6.1 Migrations
83
+
84
+ *Hartley McGuire*
85
+
86
+ * Fix change_column setting datetime precision for 6.1 Migrations
87
+
88
+ *Hartley McGuire*
89
+
90
+ ## Rails 7.0.7.2 (August 22, 2023) ##
91
+
92
+ * No changes.
93
+
94
+
95
+ ## Rails 7.0.7.1 (August 22, 2023) ##
96
+
97
+ * No changes.
98
+
99
+
100
+ ## Rails 7.0.7 (August 09, 2023) ##
101
+
102
+ * Restores functionality to the missing method when using enums and fixes.
103
+
104
+ *paulreece*
105
+
106
+ * Fix `StatementCache::Substitute` with serialized type.
107
+
108
+ *ywenc*
109
+
110
+ * Fix `:db_runtime` on notification payload when application have multiple databases.
111
+
112
+ *Eileen M. Uchitelle*
113
+
114
+ * Correctly dump check constraints for MySQL 8.0.16+.
115
+
116
+ *Steve Hill*
117
+
118
+ * Fix `ActiveRecord::QueryMethods#in_order_of` to include `nil`s, to match the
119
+ behavior of `Enumerable#in_order_of`.
120
+
121
+ For example, `Post.in_order_of(:title, [nil, "foo"])` will now include posts
122
+ with `nil` titles, the same as `Post.all.to_a.in_order_of(:title, [nil, "foo"])`.
123
+
124
+ *fatkodima*
125
+
126
+ * Revert "Fix autosave associations with validations added on `:base` of the associated objects."
127
+
128
+ This change intended to remove the :base attribute from the message,
129
+ but broke many assumptions which key these errors were stored.
130
+
131
+ *zzak*
132
+
133
+ * Fix `#previously_new_record?` to return true for destroyed records.
134
+
135
+ Before, if a record was created and then destroyed, `#previously_new_record?` would return true.
136
+ Now, any UPDATE or DELETE to a record is considered a change, and will result in `#previously_new_record?`
137
+ returning false.
138
+
139
+ *Adrianna Chang*
140
+
141
+ * Revert breaking changes to `has_one` relationship deleting the old record before the new one is validated.
142
+
143
+ *zzak*
144
+
145
+ * Fix support for Active Record instances being uses in queries.
146
+
147
+ As of `7.0.5`, query arguments were deep duped to avoid mutations impacting
148
+ the query cache, but this had the adverse effect to clearing the primary key when
149
+ the query argument contained an `ActiveRecord::Base` instance.
150
+
151
+ This broke the `noticed` gem.
152
+
153
+ *Jean Boussier*
154
+
155
+
156
+ ## Rails 7.0.6 (June 29, 2023) ##
157
+
158
+ * Fix autosave associations with validations added on `:base` of the associated objects.
159
+
160
+ *fatkodima*
161
+
162
+ * Fix result with anonymous PostgreSQL columns of different type from json.
163
+
164
+ *Oleksandr Avoiants*
165
+
166
+ * Preserve timestamp when setting an `ActiveSupport::TimeWithZone` value to `timestamptz` attribute.
167
+
168
+ *fatkodima*
169
+
170
+ * Fix assignment into an `has_one` relationship deleting the old record before the new one is validated.
171
+
172
+ *Jean Boussier*
173
+
174
+ * Fix where on association with has_one/has_many polymorphic relations.
175
+
176
+ Before:
177
+ ```ruby
178
+ Treasure.where(price_estimates: PriceEstimate.all)
179
+ #=> SELECT (...) WHERE "treasures"."id" IN (SELECT "price_estimates"."estimate_of_id" FROM "price_estimates")
180
+ ```
181
+
182
+ Later:
183
+ ```ruby
184
+ Treasure.where(price_estimates: PriceEstimate.all)
185
+ #=> SELECT (...) WHERE "treasures"."id" IN (SELECT "price_estimates"."estimate_of_id" FROM "price_estimates" WHERE "price_estimates"."estimate_of_type" = 'Treasure')
186
+ ```
187
+
188
+ *Lázaro Nixon*
189
+
190
+ * Fix decrementing counter caches on optimistically locked record deletion
191
+
192
+ *fatkodima*
193
+
194
+ * Ensure binary-destined values have binary encoding during type cast.
195
+
196
+ *Matthew Draper*
197
+
198
+ * Preserve existing column default functions when altering table in SQLite.
199
+
200
+ *fatkodima*
201
+
202
+ * Remove table alias added when using `where.missing` or `where.associated`.
203
+
204
+ *fatkodima*
205
+
206
+ * Fix `Enumerable#in_order_of` to only flatten first level to preserve nesting.
207
+
208
+ *Miha Rekar*
209
+
210
+
211
+ ## Rails 7.0.5.1 (June 26, 2023) ##
212
+
213
+ * No changes.
214
+
215
+ ## Rails 7.0.5 (May 24, 2023) ##
216
+
217
+ * Type cast `#attribute_changed?` `:from` and `:to` options.
218
+
219
+ *Andrew Novoselac*
220
+
221
+ * Fix `index_exists?` when column is an array.
222
+
223
+ *Eileen M. Uchitelle*
224
+
225
+ * Handle `Date` objects for PostgreSQL `timestamptz` columns.
226
+
227
+ *Alex Ghiculescu*
228
+
229
+ * Fix collation for changing column to non-string.
230
+
231
+ *Hartley McGuire*
232
+
233
+ * Map through subtype in `PostgreSQL::OID::Array`.
234
+
235
+ *Jonathan Hefner*
236
+
237
+ * Store correct environment in `internal_metadata` when run rails `db:prepare`.
238
+
239
+ *fatkodima*
240
+
241
+ * Make sure `ActiveRecord::Relation#sum` works with objects that implement `#coerce` without deprecation.
242
+
243
+ *Alex Ghiculescu*
244
+
245
+ * Fix retrieving foreign keys referencing tables named like keywords in PostgreSQL and MySQL.
246
+
247
+ *fatkodima*
248
+
249
+ * Support UUIDs in Disable Joins.
250
+
251
+ *Samuel Cochran*
252
+
253
+ * Fix Active Record's explain for queries starting with comments.
254
+
255
+ *fatkodima*
256
+
257
+ * Fix incorrectly preloading through association records when middle association has been loaded.
258
+
259
+ *Joshua Young*
260
+
261
+ * Fix where.missing and where.associated for parent/child associations.
262
+
263
+ *fatkodima*
264
+
265
+ * Fix Enumerable#in_order_of to preserve duplicates.
266
+
267
+ *fatkodima*
268
+
269
+ * Fix autoincrement on primary key for mysql.
270
+
271
+ *Eileen M. Uchitelle*
272
+
273
+ * Restore ability to redefine column in `create_table` for Rails 5.2 migrations.
274
+
275
+ *fatkodima*
276
+
277
+ * Fix schema cache dumping of virtual columns.
278
+
279
+ *fatkodima*
280
+
281
+ * Fix Active Record grouped calculations on joined tables on column present in both tables.
282
+
283
+ *fatkodima*
284
+
285
+ * Fix mutation detection for serialized attributes backed by binary columns.
286
+
287
+ *Jean Boussier*
288
+
289
+ * Fix a bug where using groups and counts with long table names would return incorrect results.
290
+
291
+ *Shota Toguchi*, *Yusaku Ono*
292
+
293
+ * Fix erroneous nil default precision on virtual datetime columns.
294
+
295
+ Prior to this change, virtual datetime columns did not have the same
296
+ default precision as regular datetime columns, resulting in the following
297
+ being erroneously equivalent:
298
+
299
+ t.virtual :name, type: datetime, as: "expression"
300
+ t.virtual :name, type: datetime, precision: nil, as: "expression"
301
+
302
+ This change fixes the default precision lookup, so virtual and regular
303
+ datetime column default precisions match.
304
+
305
+ *Sam Bostock*
306
+
307
+ * Fix a case where the query cache can return wrong values. See #46044
308
+
309
+ *Aaron Patterson*
310
+
311
+
1
312
  ## Rails 7.0.4.3 (March 13, 2023) ##
2
313
 
3
314
  * No changes.
@@ -17,7 +328,7 @@
17
328
  carefully crafted input.
18
329
 
19
330
  This commit makes the sanitization more robust by replacing any
20
- occurrances of "/*" or "*/" with "/ *" or "* /". It also performs a
331
+ occurrences of "/*" or "*/" with "/ *" or "* /". It also performs a
21
332
  first pass to remove one surrounding comment to avoid compatibility
22
333
  issues for users relying on the existing removal.
23
334
 
@@ -142,21 +453,21 @@
142
453
 
143
454
  This adds two new configuration options The configuration options are as
144
455
  follows:
145
-
146
- * `config.active_storage.use_yaml_unsafe_load`
147
-
456
+
457
+ * `config.active_record.use_yaml_unsafe_load`
458
+
148
459
  When set to true, this configuration option tells Rails to use the old
149
460
  "unsafe" YAML loading strategy, maintaining the existing behavior but leaving
150
461
  the possible escalation vulnerability in place. Setting this option to true
151
462
  is *not* recommended, but can aid in upgrading.
152
-
463
+
153
464
  * `config.active_record.yaml_column_permitted_classes`
154
-
465
+
155
466
  The "safe YAML" loading method does not allow all classes to be deserialized
156
467
  by default. This option allows you to specify classes deemed "safe" in your
157
468
  application. For example, if your application uses Symbol and Time in
158
469
  serialized data, you can add Symbol and Time to the allowed list as follows:
159
-
470
+
160
471
  ```
161
472
  config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
162
473
  ```
data/README.rdoc CHANGED
@@ -192,7 +192,7 @@ The latest version of Active Record can be installed with RubyGems:
192
192
 
193
193
  $ gem install activerecord
194
194
 
195
- Source code can be downloaded as part of the Rails project on GitHub:
195
+ Source code can be downloaded as part of the \Rails project on GitHub:
196
196
 
197
197
  * https://github.com/rails/rails/tree/main/activerecord
198
198
 
@@ -210,7 +210,7 @@ API documentation is at:
210
210
 
211
211
  * https://api.rubyonrails.org
212
212
 
213
- Bug reports for the Ruby on Rails project can be filed here:
213
+ Bug reports for the Ruby on \Rails project can be filed here:
214
214
 
215
215
  * https://github.com/rails/rails/issues
216
216
 
@@ -79,7 +79,7 @@ module ActiveRecord
79
79
  def reset
80
80
  super
81
81
  @target = []
82
- @replaced_or_added_targets = Set.new
82
+ @replaced_or_added_targets = Set.new.compare_by_identity
83
83
  @association_ids = nil
84
84
  end
85
85
 
@@ -1102,6 +1102,11 @@ module ActiveRecord
1102
1102
  super
1103
1103
  end
1104
1104
 
1105
+ def pretty_print(pp) # :nodoc:
1106
+ load_target if find_from_target?
1107
+ super
1108
+ end
1109
+
1105
1110
  delegate_methods = [
1106
1111
  QueryMethods,
1107
1112
  SpawnMethods,
@@ -74,7 +74,7 @@ module ActiveRecord
74
74
  end
75
75
 
76
76
  def middle_records
77
- through_preloaders.flat_map(&:preloaded_records)
77
+ through_records_by_owner.values.flatten
78
78
  end
79
79
 
80
80
  def through_preloaders
@@ -586,8 +586,11 @@ module ActiveRecord
586
586
  # has_many :birthday_events, ->(user) { where(starts_on: user.birthday) }, class_name: 'Event'
587
587
  # end
588
588
  #
589
- # Note: Joining, eager loading, and preloading of these associations is not possible.
590
- # These operations happen before instance creation and the scope will be called with a +nil+ argument.
589
+ # Note: Joining or eager loading such associations is not possible because
590
+ # those operations happen before instance creation. Such associations
591
+ # _can_ be preloaded, but doing so will perform N+1 queries because there
592
+ # will be a different scope for each record (similar to preloading
593
+ # polymorphic scopes).
591
594
  #
592
595
  # == Association callbacks
593
596
  #
@@ -1600,6 +1603,12 @@ module ActiveRecord
1600
1603
  #
1601
1604
  # Note that NestedAttributes::ClassMethods#accepts_nested_attributes_for sets
1602
1605
  # <tt>:autosave</tt> to <tt>true</tt>.
1606
+ # [:touch]
1607
+ # If true, the associated object will be touched (the +updated_at+ / +updated_on+ attributes set to current time)
1608
+ # when this record is either saved or destroyed. If you specify a symbol, that attribute
1609
+ # will be updated with the current time in addition to the +updated_at+ / +updated_on+ attribute.
1610
+ # Please note that no validation will be performed when touching, and only the +after_touch+,
1611
+ # +after_commit+, and +after_rollback+ callbacks will be executed.
1603
1612
  # [:inverse_of]
1604
1613
  # Specifies the name of the #belongs_to association on the associated object
1605
1614
  # that is the inverse of this #has_one association.
@@ -1747,11 +1756,11 @@ module ActiveRecord
1747
1756
  # Note that NestedAttributes::ClassMethods#accepts_nested_attributes_for
1748
1757
  # sets <tt>:autosave</tt> to <tt>true</tt>.
1749
1758
  # [:touch]
1750
- # If true, the associated object will be touched (the updated_at/on attributes set to current time)
1759
+ # If true, the associated object will be touched (the +updated_at+ / +updated_on+ attributes set to current time)
1751
1760
  # when this record is either saved or destroyed. If you specify a symbol, that attribute
1752
- # will be updated with the current time in addition to the updated_at/on attribute.
1753
- # Please note that with touching no validation is performed and only the +after_touch+,
1754
- # +after_commit+ and +after_rollback+ callbacks are executed.
1761
+ # will be updated with the current time in addition to the +updated_at+ / +updated_on+ attribute.
1762
+ # Please note that no validation will be performed when touching, and only the +after_touch+,
1763
+ # +after_commit+, and +after_rollback+ callbacks will be executed.
1755
1764
  # [:inverse_of]
1756
1765
  # Specifies the name of the #has_one or #has_many association on the associated
1757
1766
  # object that is the inverse of this #belongs_to association.
@@ -23,7 +23,7 @@ module ActiveRecord
23
23
 
24
24
  # Returns the value of the attribute identified by <tt>attr_name</tt> after
25
25
  # it has been typecast (for example, "2004-12-12" in a date column is cast
26
- # to a date object, like Date.new(2004, 12, 12)).
26
+ # to a date object, like <tt>Date.new(2004, 12, 12)</tt>).
27
27
  def read_attribute(attr_name, &block)
28
28
  name = attr_name.to_s
29
29
  name = self.class.attribute_aliases[name] || name
@@ -19,8 +19,6 @@ module ActiveRecord
19
19
 
20
20
  if value.is_a?(Hash)
21
21
  set_time_zone_without_conversion(super)
22
- elsif value.is_a?(Range)
23
- Range.new(user_input_in_time_zone(value.begin), user_input_in_time_zone(value.end), value.exclude_end?)
24
22
  elsif value.respond_to?(:in_time_zone)
25
23
  begin
26
24
  super(user_input_in_time_zone(value)) || super
@@ -42,8 +40,6 @@ module ActiveRecord
42
40
  value.in_time_zone
43
41
  elsif value.respond_to?(:infinite?) && value.infinite?
44
42
  value
45
- elsif value.is_a?(Range)
46
- Range.new(convert_time_to_time_zone(value.begin), convert_time_to_time_zone(value.end), value.exclude_end?)
47
43
  else
48
44
  map_avoiding_infinite_recursion(value) { |v| convert_time_to_time_zone(v) }
49
45
  end
@@ -310,8 +310,8 @@ module ActiveRecord
310
310
  end
311
311
 
312
312
  # Returns the value of the attribute identified by <tt>attr_name</tt> after it has been typecast (for example,
313
- # "2004-12-12" in a date column is cast to a date object, like Date.new(2004, 12, 12)). It raises
314
- # <tt>ActiveModel::MissingAttributeError</tt> if the identified attribute is missing.
313
+ # "2004-12-12" in a date column is cast to a date object, like <tt>Date.new(2004, 12, 12)</tt>). It raises
314
+ # ActiveModel::MissingAttributeError if the identified attribute is missing.
315
315
  #
316
316
  # Note: +:id+ is always present.
317
317
  #
@@ -331,7 +331,6 @@ module ActiveRecord
331
331
  end
332
332
 
333
333
  # Updates the attribute identified by <tt>attr_name</tt> with the specified +value+.
334
- # (Alias for the protected #write_attribute method).
335
334
  #
336
335
  # class Person < ActiveRecord::Base
337
336
  # end
@@ -360,10 +359,9 @@ module ActiveRecord
360
359
  # end
361
360
  #
362
361
  # private
363
- #
364
- # def print_accessed_fields
365
- # p @posts.first.accessed_fields
366
- # end
362
+ # def print_accessed_fields
363
+ # p @posts.first.accessed_fields
364
+ # end
367
365
  # end
368
366
  #
369
367
  # Which allows you to quickly change your code to:
@@ -224,14 +224,13 @@ module ActiveRecord
224
224
  # after_save :do_something_else
225
225
  #
226
226
  # private
227
+ # def log_children
228
+ # # Child processing
229
+ # end
227
230
  #
228
- # def log_children
229
- # # Child processing
230
- # end
231
- #
232
- # def do_something_else
233
- # # Something else
234
- # end
231
+ # def do_something_else
232
+ # # Something else
233
+ # end
235
234
  # end
236
235
  #
237
236
  # In this case the +log_children+ is executed before +do_something_else+.
@@ -249,14 +248,13 @@ module ActiveRecord
249
248
  # after_commit :do_something_else
250
249
  #
251
250
  # private
251
+ # def log_children
252
+ # # Child processing
253
+ # end
252
254
  #
253
- # def log_children
254
- # # Child processing
255
- # end
256
- #
257
- # def do_something_else
258
- # # Something else
259
- # end
255
+ # def do_something_else
256
+ # # Something else
257
+ # end
260
258
  # end
261
259
  #
262
260
  # In this case the +do_something_else+ is executed before +log_children+.
@@ -411,20 +411,7 @@ module ActiveRecord
411
411
  name = name.to_s
412
412
  type = type.to_sym if type
413
413
 
414
- if @columns_hash[name]
415
- if @columns_hash[name].primary_key?
416
- raise ArgumentError, "you can't redefine the primary key column '#{name}'. To define a custom primary key, pass { id: false } to create_table."
417
- else
418
- raise ArgumentError, "you can't define an already defined column '#{name}'."
419
- end
420
- end
421
-
422
- if @conn.supports_datetime_with_precision?
423
- if type == :datetime && !options.key?(:precision)
424
- options[:precision] = 6
425
- end
426
- end
427
-
414
+ raise_on_duplicate_column(name)
428
415
  @columns_hash[name] = new_column_definition(name, type, **options)
429
416
 
430
417
  if index
@@ -491,6 +478,13 @@ module ActiveRecord
491
478
  type = integer_like_primary_key_type(type, options)
492
479
  end
493
480
  type = aliased_types(type.to_s, type)
481
+
482
+ if @conn.supports_datetime_with_precision?
483
+ if type == :datetime && !options.key?(:precision)
484
+ options[:precision] = 6
485
+ end
486
+ end
487
+
494
488
  options[:primary_key] ||= type == :primary_key
495
489
  options[:null] = false if options[:primary_key]
496
490
  create_column_definition(name, type, options)
@@ -525,6 +519,16 @@ module ActiveRecord
525
519
  def integer_like_primary_key_type(type, options)
526
520
  type
527
521
  end
522
+
523
+ def raise_on_duplicate_column(name)
524
+ if @columns_hash[name]
525
+ if @columns_hash[name].primary_key?
526
+ raise ArgumentError, "you can't redefine the primary key column '#{name}'. To define a custom primary key, pass { id: false } to create_table."
527
+ else
528
+ raise ArgumentError, "you can't define an already defined column '#{name}'."
529
+ end
530
+ end
531
+ end
528
532
  end
529
533
 
530
534
  class AlterTable # :nodoc:
@@ -661,8 +665,8 @@ module ActiveRecord
661
665
  # end
662
666
  #
663
667
  # See {connection.index_exists?}[rdoc-ref:SchemaStatements#index_exists?]
664
- def index_exists?(column_name, options = {})
665
- @base.index_exists?(name, column_name, options)
668
+ def index_exists?(column_name, **options)
669
+ @base.index_exists?(name, column_name, **options)
666
670
  end
667
671
 
668
672
  # Renames the given index on the table.
@@ -98,6 +98,7 @@ module ActiveRecord
98
98
  #
99
99
  def index_exists?(table_name, column_name, **options)
100
100
  checks = []
101
+ column_name = options[:column] if column_name.nil?
101
102
 
102
103
  if column_name.present?
103
104
  column_names = Array(column_name).map(&:to_s)
@@ -263,7 +264,7 @@ module ActiveRecord
263
264
  #
264
265
  # generates:
265
266
  #
266
- # CREATE TABLE order (
267
+ # CREATE TABLE orders (
267
268
  # product_id bigint NOT NULL,
268
269
  # client_id bigint NOT NULL
269
270
  # );
@@ -71,14 +71,6 @@ module ActiveRecord
71
71
  /\A(?:[(\s]|#{COMMENT_REGEX})*#{Regexp.union(*parts)}/
72
72
  end
73
73
 
74
- def self.quoted_column_names # :nodoc:
75
- @quoted_column_names ||= {}
76
- end
77
-
78
- def self.quoted_table_names # :nodoc:
79
- @quoted_table_names ||= {}
80
- end
81
-
82
74
  def initialize(connection, logger = nil, config = {}) # :nodoc:
83
75
  super()
84
76
 
@@ -593,6 +585,10 @@ module ActiveRecord
593
585
  #
594
586
  # This is useful for when you need to call a proprietary method such as
595
587
  # PostgreSQL's lo_* methods.
588
+ #
589
+ # Active Record cannot track if the database is getting modified using
590
+ # this client. If that is the case, generally you'll want to invalidate
591
+ # the query cache using +ActiveRecord::Base.clear_query_cache+.
596
592
  def raw_connection
597
593
  disable_lazy_transactions!
598
594
  @connection
@@ -661,15 +657,6 @@ module ActiveRecord
661
657
  migration_context.current_version
662
658
  end
663
659
 
664
- def field_ordered_value(column, values) # :nodoc:
665
- node = Arel::Nodes::Case.new(column)
666
- values.each.with_index(1) do |value, order|
667
- node.when(value).then(order)
668
- end
669
-
670
- Arel::Nodes::Ascending.new(node.else(values.length + 1))
671
- end
672
-
673
660
  class << self
674
661
  private
675
662
  def initialize_type_map(m)