activerecord 8.0.2 → 8.0.5.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +288 -1
- data/README.rdoc +1 -1
- data/lib/active_record/associations/belongs_to_association.rb +11 -1
- data/lib/active_record/associations/collection_association.rb +3 -3
- data/lib/active_record/associations/join_dependency.rb +2 -2
- data/lib/active_record/associations/preloader/batch.rb +7 -1
- data/lib/active_record/attribute_methods/query.rb +34 -0
- data/lib/active_record/attribute_methods/serialization.rb +1 -1
- data/lib/active_record/attribute_methods.rb +1 -1
- data/lib/active_record/attributes.rb +35 -24
- data/lib/active_record/autosave_association.rb +2 -2
- data/lib/active_record/base.rb +2 -2
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +10 -6
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +17 -6
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +7 -4
- data/lib/active_record/connection_adapters/abstract_adapter.rb +39 -32
- data/lib/active_record/connection_adapters/postgresql/column.rb +4 -2
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +9 -2
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -2
- data/lib/active_record/connection_adapters/sqlite3/column.rb +8 -2
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +2 -2
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +15 -3
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +5 -5
- data/lib/active_record/connection_handling.rb +13 -9
- data/lib/active_record/core.rb +8 -6
- data/lib/active_record/database_configurations/hash_config.rb +8 -2
- data/lib/active_record/delegated_type.rb +1 -1
- data/lib/active_record/encryption/encryptable_record.rb +1 -1
- data/lib/active_record/encryption/encrypted_attribute_type.rb +1 -1
- data/lib/active_record/encryption/encryptor.rb +27 -25
- data/lib/active_record/enum.rb +13 -12
- data/lib/active_record/errors.rb +3 -3
- data/lib/active_record/fixture_set/table_row.rb +19 -2
- data/lib/active_record/future_result.rb +2 -0
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/insert_all.rb +2 -2
- data/lib/active_record/migration/command_recorder.rb +1 -1
- data/lib/active_record/migration.rb +5 -5
- data/lib/active_record/query_logs.rb +4 -0
- data/lib/active_record/querying.rb +4 -4
- data/lib/active_record/railtie.rb +2 -2
- data/lib/active_record/railties/databases.rake +8 -16
- data/lib/active_record/relation/calculations.rb +15 -16
- data/lib/active_record/relation/finder_methods.rb +15 -14
- data/lib/active_record/relation/predicate_builder/array_handler.rb +3 -1
- data/lib/active_record/relation/query_methods.rb +6 -5
- data/lib/active_record/relation/spawn_methods.rb +6 -6
- data/lib/active_record/relation/where_clause.rb +9 -3
- data/lib/active_record/relation.rb +15 -5
- data/lib/active_record/secure_token.rb +3 -3
- data/lib/active_record/signed_id.rb +3 -3
- data/lib/active_record/tasks/database_tasks.rb +22 -14
- data/lib/active_record/tasks/postgresql_database_tasks.rb +9 -1
- data/lib/active_record/test_databases.rb +1 -1
- data/lib/active_record/transactions.rb +3 -1
- data/lib/active_record/type/serialized.rb +5 -0
- data/lib/active_record.rb +3 -2
- data/lib/arel/crud.rb +2 -0
- data/lib/arel/delete_manager.rb +5 -0
- data/lib/arel/nodes/delete_statement.rb +4 -2
- data/lib/arel/nodes/update_statement.rb +4 -2
- data/lib/arel/predications.rb +1 -3
- data/lib/arel/select_manager.rb +6 -2
- data/lib/arel/update_manager.rb +5 -0
- data/lib/arel/visitors/dot.rb +2 -0
- data/lib/arel/visitors/to_sql.rb +2 -0
- metadata +10 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 989c36bdf6a5515324bab861c321c4baf4caa37eb1da6cb4a698a9a3652d86a9
|
|
4
|
+
data.tar.gz: af52d060fe311c35581ce05dad614bb02cc254ea262bbe2824cddc92bffe61e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8fe1285a44378c0745f2df6594bd60c77deb118925f8ed8517fb687ea4424897a8aa08eafa589e8bcd04d0bd22b198cac77b0d55bb408cbb06da04b72d24bacd
|
|
7
|
+
data.tar.gz: 1f22bdb1bf323090bdba8c0fc03cdf3971e6d084e995b411f018933d429b64c61449198bc10c8c6e86e42c28850014a86135f58ce242bfef77501281821784f7
|
data/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,295 @@
|
|
|
1
|
-
## Rails 8.0.2 (
|
|
1
|
+
## Rails 8.0.5.2 (November 03, 2026) ##
|
|
2
|
+
|
|
3
|
+
* No changes.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Rails 8.0.5.1 (July 29, 2026) ##
|
|
7
|
+
|
|
8
|
+
* No changes.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Rails 8.0.5 (March 24, 2026) ##
|
|
12
|
+
|
|
13
|
+
* Fix `insert_all` and `upsert_all` log message when called on anonymous classes.
|
|
14
|
+
|
|
15
|
+
*Gabriel Sobrinho*
|
|
16
|
+
|
|
17
|
+
* Respect `ActiveRecord::SchemaDumper.ignore_tables` when dumping SQLite virtual tables.
|
|
18
|
+
|
|
19
|
+
*Hans Schnedlitz*
|
|
20
|
+
|
|
21
|
+
* Restore previous instrumenter after `execute_or_skip`
|
|
22
|
+
|
|
23
|
+
`FutureResult#execute_or_skip` replaces the thread's instrumenter with an
|
|
24
|
+
`EventBuffer` to collect events published during async query execution.
|
|
25
|
+
If the global async executor is saturated and the `caller_runs` fallback
|
|
26
|
+
executes the task on the calling thread, we need to make sure the previous
|
|
27
|
+
instrumenter is restored or the stale `EventBuffer` would stay in place and
|
|
28
|
+
permanently swallow all subsequent `sql.active_record` notifications on
|
|
29
|
+
that thread.
|
|
30
|
+
|
|
31
|
+
*Rosa Gutierrez*
|
|
32
|
+
|
|
33
|
+
* Fix Ruby 4.0 delegator warning when calling inspect on ActiveRecord::Type::Serialized.
|
|
34
|
+
|
|
35
|
+
*Hammad Khan*
|
|
36
|
+
|
|
37
|
+
* Fix support for table names containing hyphens.
|
|
38
|
+
|
|
39
|
+
*Evgeniy Demin*
|
|
40
|
+
|
|
41
|
+
* Fix column deduplication for SQLite3 and PostgreSQL virtual (generated) columns.
|
|
42
|
+
|
|
43
|
+
`Column#==` and `Column#hash` now account for `virtual?` so that the
|
|
44
|
+
`Deduplicable` registry does not treat a generated column and a regular
|
|
45
|
+
column with the same name and type as identical. Previously, if a
|
|
46
|
+
generated column was registered first, a regular column on a different
|
|
47
|
+
table could be deduplicated to the generated instance, silently
|
|
48
|
+
excluding it from INSERT/UPDATE statements.
|
|
49
|
+
|
|
50
|
+
*Jay Huber*
|
|
51
|
+
|
|
52
|
+
* Fix merging relations with arel equality predicates with null relations.
|
|
53
|
+
|
|
54
|
+
*fatkodima*
|
|
55
|
+
|
|
56
|
+
* Fix SQLite3 schema dump for non-autoincrement integer primary keys.
|
|
57
|
+
|
|
58
|
+
Previously, `schema.rb` should incorrectly restore that table with an auto incrementing
|
|
59
|
+
primary key.
|
|
60
|
+
|
|
61
|
+
*Chris Hasiński*
|
|
62
|
+
|
|
63
|
+
* Fix PostgreSQL `schema_search_path` not being reapplied after `reset!` or `reconnect!`.
|
|
64
|
+
|
|
65
|
+
The `schema_search_path` configured in `database.yml` is now correctly
|
|
66
|
+
reapplied instead of falling back to PostgreSQL defaults.
|
|
67
|
+
|
|
68
|
+
*Tobias Egli*
|
|
69
|
+
|
|
70
|
+
* Ensure batched preloaded associations accounts for klass when grouping to avoid issues with STI.
|
|
71
|
+
|
|
72
|
+
*zzak*, *Stjepan Hadjic*
|
|
73
|
+
|
|
74
|
+
* Fix `ActiveRecord::SoleRecordExceeded#record` to return the relation.
|
|
75
|
+
|
|
76
|
+
This was the case until Rails 7.2, but starting from 8.0 it
|
|
77
|
+
started mistakenly returning the model class.
|
|
78
|
+
|
|
79
|
+
*Jean Boussier*
|
|
80
|
+
|
|
81
|
+
* Improve PostgreSQLAdapter resilience to Timeout.timeout.
|
|
82
|
+
|
|
83
|
+
Better handle asynchronous exceptions being thrown inside
|
|
84
|
+
the `reconnect!` method.
|
|
85
|
+
|
|
86
|
+
This may fixes some deep errors such as:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
undefined method `key?' for nil:NilClass (NoMethodError)
|
|
90
|
+
if !type_map.key?(oid)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
*Jean Boussier*
|
|
94
|
+
|
|
95
|
+
* Fix `eager_load` when loading `has_many` assocations with composite primary keys.
|
|
96
|
+
|
|
97
|
+
This would result in some records being loaded multiple times.
|
|
98
|
+
|
|
99
|
+
*Martin-Alexander*
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
## Rails 8.0.4.1 (March 23, 2026) ##
|
|
2
103
|
|
|
3
104
|
* No changes.
|
|
4
105
|
|
|
5
106
|
|
|
107
|
+
## Rails 8.0.4 (October 28, 2025) ##
|
|
108
|
+
|
|
109
|
+
* Fix SQLite3 data loss during table alterations with CASCADE foreign keys.
|
|
110
|
+
|
|
111
|
+
When altering a table in SQLite3 that is referenced by child tables with
|
|
112
|
+
`ON DELETE CASCADE` foreign keys, ActiveRecord would silently delete all
|
|
113
|
+
data from the child tables. This occurred because SQLite requires table
|
|
114
|
+
recreation for schema changes, and during this process the original table
|
|
115
|
+
is temporarily dropped, triggering CASCADE deletes on child tables.
|
|
116
|
+
|
|
117
|
+
The root cause was incorrect ordering of operations. The original code
|
|
118
|
+
wrapped `disable_referential_integrity` inside a transaction, but
|
|
119
|
+
`PRAGMA foreign_keys` cannot be modified inside a transaction in SQLite -
|
|
120
|
+
attempting to do so simply has no effect. This meant foreign keys remained
|
|
121
|
+
enabled during table recreation, causing CASCADE deletes to fire.
|
|
122
|
+
|
|
123
|
+
The fix reverses the order to follow the official SQLite 12-step ALTER TABLE
|
|
124
|
+
procedure: `disable_referential_integrity` now wraps the transaction instead
|
|
125
|
+
of being wrapped by it. This ensures foreign keys are properly disabled
|
|
126
|
+
before the transaction starts and re-enabled after it commits, preventing
|
|
127
|
+
CASCADE deletes while maintaining data integrity through atomic transactions.
|
|
128
|
+
|
|
129
|
+
*Ruy Rocha*
|
|
130
|
+
|
|
131
|
+
* Add support for bound SQL literals in CTEs.
|
|
132
|
+
|
|
133
|
+
*Nicolas Bachschmidt*
|
|
134
|
+
|
|
135
|
+
* Fix `belongs_to` associations not to clear the entire composite primary key.
|
|
136
|
+
|
|
137
|
+
When clearing a `belongs_to` association that references a model with composite primary key,
|
|
138
|
+
only the optional part of the key should be cleared.
|
|
139
|
+
|
|
140
|
+
*zzak*
|
|
141
|
+
|
|
142
|
+
* Fix invalid records being autosaved when distantly associated records are marked for deletion.
|
|
143
|
+
|
|
144
|
+
*Ian Terrell*, *axlekb AB*
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
## Rails 8.0.3 (September 22, 2025) ##
|
|
148
|
+
|
|
149
|
+
* Fix query cache for pinned connections in multi threaded transactional tests
|
|
150
|
+
|
|
151
|
+
When a pinned connection is used across separate threads, they now use a separate cache store
|
|
152
|
+
for each thread.
|
|
153
|
+
|
|
154
|
+
This improve accuracy of system tests, and any test using multiple threads.
|
|
155
|
+
|
|
156
|
+
*Heinrich Lee Yu*, *Jean Boussier*
|
|
157
|
+
|
|
158
|
+
* Don't add `id_value` attribute alias when attribute/column with that name already exists.
|
|
159
|
+
|
|
160
|
+
*Rob Lewis*
|
|
161
|
+
|
|
162
|
+
* Fix false positive change detection involving STI and polymorphic has one relationships.
|
|
163
|
+
|
|
164
|
+
Polymorphic `has_one` relationships would always be considered changed when defined in a STI child
|
|
165
|
+
class, causing nedless extra autosaves.
|
|
166
|
+
|
|
167
|
+
*David Fritsch*
|
|
168
|
+
|
|
169
|
+
* Skip calling `PG::Connection#cancel` in `cancel_any_running_query`
|
|
170
|
+
when using libpq >= 18 with pg < 1.6.0, due to incompatibility.
|
|
171
|
+
Rollback still runs, but may take longer.
|
|
172
|
+
|
|
173
|
+
*Yasuo Honda*, *Lars Kanis*
|
|
174
|
+
|
|
175
|
+
* Fix stale association detection for polymorphic `belongs_to`.
|
|
176
|
+
|
|
177
|
+
*Florent Beaurain*, *Thomas Crambert*
|
|
178
|
+
|
|
179
|
+
* Fix removal of PostgreSQL version comments in `structure.sql` for latest PostgreSQL versions which include `\restrict`
|
|
180
|
+
|
|
181
|
+
*Brendan Weibrecht*
|
|
182
|
+
|
|
183
|
+
* Allow setting `schema_format` in database configuration.
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
primary:
|
|
187
|
+
schema_format: ruby
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Useful in multi-database setups to have different formats per-database.
|
|
191
|
+
|
|
192
|
+
*T S Vallender*
|
|
193
|
+
|
|
194
|
+
* Use ntuples to populate row_count instead of count for Postgres
|
|
195
|
+
|
|
196
|
+
*Jonathan Calvert*
|
|
197
|
+
|
|
198
|
+
* Fix `#merge` with `#or` or `#and` and a mixture of attributes and SQL strings resulting in an incorrect query.
|
|
199
|
+
|
|
200
|
+
```ruby
|
|
201
|
+
base = Comment.joins(:post).where(user_id: 1).where("recent = 1")
|
|
202
|
+
puts base.merge(base.where(draft: true).or(Post.where(archived: true))).to_sql
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Before:
|
|
206
|
+
|
|
207
|
+
```SQL
|
|
208
|
+
SELECT "comments".* FROM "comments"
|
|
209
|
+
INNER JOIN "posts" ON "posts"."id" = "comments"."post_id"
|
|
210
|
+
WHERE (recent = 1)
|
|
211
|
+
AND (
|
|
212
|
+
"comments"."user_id" = 1
|
|
213
|
+
AND (recent = 1)
|
|
214
|
+
AND "comments"."draft" = 1
|
|
215
|
+
OR "posts"."archived" = 1
|
|
216
|
+
)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
After:
|
|
220
|
+
|
|
221
|
+
```SQL
|
|
222
|
+
SELECT "comments".* FROM "comments"
|
|
223
|
+
INNER JOIN "posts" ON "posts"."id" = "comments"."post_id"
|
|
224
|
+
WHERE "comments"."user_id" = 1
|
|
225
|
+
AND (recent = 1)
|
|
226
|
+
AND (
|
|
227
|
+
"comments"."user_id" = 1
|
|
228
|
+
AND (recent = 1)
|
|
229
|
+
AND "comments"."draft" = 1
|
|
230
|
+
OR "posts"."archived" = 1
|
|
231
|
+
)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
*Joshua Young*
|
|
235
|
+
|
|
236
|
+
* Fix inline `has_and_belongs_to_many` fixtures for tables with composite primary keys.
|
|
237
|
+
|
|
238
|
+
*fatkodima*
|
|
239
|
+
|
|
240
|
+
* Fix migration log message for down operations.
|
|
241
|
+
|
|
242
|
+
*Bernardo Barreto*
|
|
243
|
+
|
|
244
|
+
* Prepend `extra_flags` in postgres' `structure_load`
|
|
245
|
+
|
|
246
|
+
When specifying `structure_load_flags` with a postgres adapter, the flags
|
|
247
|
+
were appended to the default flags, instead of prepended.
|
|
248
|
+
This caused issues with flags not being taken into account by postgres.
|
|
249
|
+
|
|
250
|
+
*Alice Loeser*
|
|
251
|
+
|
|
252
|
+
* Fix `annotate` comments to propagate to `update_all`/`delete_all`.
|
|
253
|
+
|
|
254
|
+
*fatkodima*
|
|
255
|
+
|
|
256
|
+
* Fix checking whether an unpersisted record is `include?`d in a strictly
|
|
257
|
+
loaded `has_and_belongs_to_many` association.
|
|
258
|
+
|
|
259
|
+
*Hartley McGuire*
|
|
260
|
+
|
|
261
|
+
* `create_or_find_by` will now correctly rollback a transaction.
|
|
262
|
+
|
|
263
|
+
When using `create_or_find_by`, raising a ActiveRecord::Rollback error
|
|
264
|
+
in a `after_save` callback had no effect, the transaction was committed
|
|
265
|
+
and a record created.
|
|
266
|
+
|
|
267
|
+
*Edouard Chin*
|
|
268
|
+
|
|
269
|
+
* Gracefully handle `Timeout.timeout` firing during connection configuration.
|
|
270
|
+
|
|
271
|
+
Use of `Timeout.timeout` could result in improperly initialized database connection.
|
|
272
|
+
|
|
273
|
+
This could lead to a partially configured connection being used, resulting in various exceptions,
|
|
274
|
+
the most common being with the PostgreSQLAdapter raising `undefined method 'key?' for nil`
|
|
275
|
+
or `TypeError: wrong argument type nil (expected PG::TypeMap)`.
|
|
276
|
+
|
|
277
|
+
*Jean Boussier*
|
|
278
|
+
|
|
279
|
+
* Fix stale state for composite foreign keys in belongs_to associations.
|
|
280
|
+
|
|
281
|
+
*Varun Sharma*
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
## Rails 8.0.2.1 (August 13, 2025) ##
|
|
285
|
+
|
|
286
|
+
* Call inspect on ids in RecordNotFound error
|
|
287
|
+
|
|
288
|
+
[CVE-2025-55193]
|
|
289
|
+
|
|
290
|
+
*Gannon McGibbon*, *John Hawthorn*
|
|
291
|
+
|
|
292
|
+
|
|
6
293
|
## Rails 8.0.2 (March 12, 2025) ##
|
|
7
294
|
|
|
8
295
|
* Fix inverting `rename_enum_value` when `:from`/`:to` are provided.
|
data/README.rdoc
CHANGED
|
@@ -214,6 +214,6 @@ Bug reports for the Ruby on \Rails project can be filed here:
|
|
|
214
214
|
|
|
215
215
|
* https://github.com/rails/rails/issues
|
|
216
216
|
|
|
217
|
-
Feature requests should be discussed on the
|
|
217
|
+
Feature requests should be discussed on the rubyonrails-core forum here:
|
|
218
218
|
|
|
219
219
|
* https://discuss.rubyonrails.org/c/rubyonrails-core
|
|
@@ -135,7 +135,9 @@ module ActiveRecord
|
|
|
135
135
|
target_key_values = record ? Array(primary_key(record.class)).map { |key| record._read_attribute(key) } : []
|
|
136
136
|
|
|
137
137
|
if force || reflection_fk.map { |fk| owner._read_attribute(fk) } != target_key_values
|
|
138
|
+
owner_pk = Array(owner.class.primary_key)
|
|
138
139
|
reflection_fk.each_with_index do |key, index|
|
|
140
|
+
next if record.nil? && owner_pk.include?(key)
|
|
139
141
|
owner[key] = target_key_values[index]
|
|
140
142
|
end
|
|
141
143
|
end
|
|
@@ -162,7 +164,15 @@ module ActiveRecord
|
|
|
162
164
|
end
|
|
163
165
|
|
|
164
166
|
def stale_state
|
|
165
|
-
|
|
167
|
+
foreign_key = reflection.foreign_key
|
|
168
|
+
if foreign_key.is_a?(Array)
|
|
169
|
+
attributes = foreign_key.map do |fk|
|
|
170
|
+
owner._read_attribute(fk) { |n| owner.send(:missing_attribute, n, caller) }
|
|
171
|
+
end
|
|
172
|
+
attributes if attributes.any?
|
|
173
|
+
else
|
|
174
|
+
owner._read_attribute(foreign_key) { |n| owner.send(:missing_attribute, n, caller) }
|
|
175
|
+
end
|
|
166
176
|
end
|
|
167
177
|
end
|
|
168
178
|
end
|
|
@@ -259,10 +259,10 @@ module ActiveRecord
|
|
|
259
259
|
klass = reflection.klass
|
|
260
260
|
return false unless record.is_a?(klass)
|
|
261
261
|
|
|
262
|
-
if
|
|
263
|
-
include_in_memory?(record)
|
|
264
|
-
elsif loaded?
|
|
262
|
+
if loaded?
|
|
265
263
|
target.include?(record)
|
|
264
|
+
elsif record.new_record?
|
|
265
|
+
include_in_memory?(record)
|
|
266
266
|
else
|
|
267
267
|
record_id = klass.composite_primary_key? ? klass.primary_key.zip(record.id).to_h : record.id
|
|
268
268
|
scope.exists?(record_id)
|
|
@@ -103,7 +103,7 @@ module ActiveRecord
|
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def instantiate(result_set, strict_loading_value, &block)
|
|
106
|
-
primary_key = aliases.column_alias(join_root,
|
|
106
|
+
primary_key = Array(join_root.primary_key).map { |column| aliases.column_alias(join_root, column) }
|
|
107
107
|
|
|
108
108
|
seen = Hash.new { |i, parent|
|
|
109
109
|
i[parent] = Hash.new { |j, child_class|
|
|
@@ -141,7 +141,7 @@ module ActiveRecord
|
|
|
141
141
|
|
|
142
142
|
message_bus.instrument("instantiation.active_record", payload) do
|
|
143
143
|
result_set.each { |row_hash|
|
|
144
|
-
parent_key = primary_key ? row_hash
|
|
144
|
+
parent_key = primary_key.empty? ? row_hash : row_hash.values_at(*primary_key)
|
|
145
145
|
parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases, column_types, &block)
|
|
146
146
|
construct(parent, join_root, row_hash, seen, model_cache, strict_loading_value)
|
|
147
147
|
}
|
|
@@ -38,7 +38,13 @@ module ActiveRecord
|
|
|
38
38
|
attr_reader :loaders
|
|
39
39
|
|
|
40
40
|
def group_and_load_similar(loaders)
|
|
41
|
-
loaders.grep_v(ThroughAssociation)
|
|
41
|
+
non_through = loaders.grep_v(ThroughAssociation)
|
|
42
|
+
|
|
43
|
+
grouped = non_through.group_by do |loader|
|
|
44
|
+
[loader.loader_query, loader.klass]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
grouped.each do |(query, _klass), similar_loaders|
|
|
42
48
|
query.load_records_in_batch(similar_loaders)
|
|
43
49
|
end
|
|
44
50
|
end
|
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
module ActiveRecord
|
|
4
4
|
module AttributeMethods
|
|
5
5
|
# = Active Record Attribute Methods \Query
|
|
6
|
+
#
|
|
7
|
+
# Adds query methods for attributes that return either +true+ or +false+
|
|
8
|
+
# depending on the attribute type and value.
|
|
9
|
+
#
|
|
10
|
+
# For Boolean attributes this will return +true+ if the value is present
|
|
11
|
+
# and return +false+ otherwise:
|
|
12
|
+
#
|
|
13
|
+
# class Product < ActiveRecord::Base
|
|
14
|
+
# end
|
|
15
|
+
#
|
|
16
|
+
# product = Product.new(archived: false)
|
|
17
|
+
# product.archived? # => false
|
|
18
|
+
# product.archived = true
|
|
19
|
+
# product.archived? # => true
|
|
20
|
+
#
|
|
21
|
+
# For Numeric attributes this will return +true+ if the value is a non-zero
|
|
22
|
+
# number and return +false+ otherwise:
|
|
23
|
+
#
|
|
24
|
+
# product.inventory_count = 0
|
|
25
|
+
# product.inventory_count? # => false
|
|
26
|
+
# product.inventory_count = 1
|
|
27
|
+
# product.inventory_count? # => true
|
|
28
|
+
#
|
|
29
|
+
# For other attributes it will return +true+ if the value is present
|
|
30
|
+
# and return +false+ otherwise:
|
|
31
|
+
#
|
|
32
|
+
# product.name = nil
|
|
33
|
+
# product.name? # => false
|
|
34
|
+
# product.name = " "
|
|
35
|
+
# product.name? # => false
|
|
36
|
+
# product.name = "Orange"
|
|
37
|
+
# product.name? # => true
|
|
6
38
|
module Query
|
|
7
39
|
extend ActiveSupport::Concern
|
|
8
40
|
|
|
@@ -10,6 +42,8 @@ module ActiveRecord
|
|
|
10
42
|
attribute_method_suffix "?", parameters: false
|
|
11
43
|
end
|
|
12
44
|
|
|
45
|
+
# Returns +true+ or +false+ for the attribute identified by +attr_name+,
|
|
46
|
+
# depending on the attribute type and value.
|
|
13
47
|
def query_attribute(attr_name)
|
|
14
48
|
value = self.public_send(attr_name)
|
|
15
49
|
|
|
@@ -113,7 +113,7 @@ module ActiveRecord
|
|
|
113
113
|
unless abstract_class?
|
|
114
114
|
load_schema
|
|
115
115
|
super(attribute_names)
|
|
116
|
-
alias_attribute :id_value, :id if _has_attribute?("id")
|
|
116
|
+
alias_attribute :id_value, :id if _has_attribute?("id") && !_has_attribute?("id_value")
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
generate_alias_attributes
|
|
@@ -21,28 +21,34 @@ module ActiveRecord
|
|
|
21
21
|
# your domain objects across much of Active Record, without having to
|
|
22
22
|
# rely on implementation details or monkey patching.
|
|
23
23
|
#
|
|
24
|
-
#
|
|
25
|
-
# column which this will persist to.
|
|
24
|
+
# ==== Parameters
|
|
26
25
|
#
|
|
27
|
-
# +
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
# Otherwise, the type will be ActiveModel::Type::Value.
|
|
31
|
-
# See the examples below for more information about providing custom type objects.
|
|
26
|
+
# [+name+]
|
|
27
|
+
# The name of the methods to define attribute methods for, and the
|
|
28
|
+
# column which this will persist to.
|
|
32
29
|
#
|
|
33
|
-
#
|
|
30
|
+
# [+cast_type+]
|
|
31
|
+
# A symbol such as +:string+ or +:integer+, or a type object to be used
|
|
32
|
+
# for this attribute. If this parameter is not passed, the previously
|
|
33
|
+
# defined type (if any) will be used. Otherwise, the type will be
|
|
34
|
+
# ActiveModel::Type::Value. See the examples below for more information
|
|
35
|
+
# about providing custom type objects.
|
|
34
36
|
#
|
|
35
|
-
#
|
|
37
|
+
# ==== Options
|
|
36
38
|
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
39
|
+
# [+:default+]
|
|
40
|
+
# The default value to use when no value is provided. If this option is
|
|
41
|
+
# not passed, the previously defined default value (if any) on the
|
|
42
|
+
# superclass or in the schema will be used. Otherwise, the default will
|
|
43
|
+
# be +nil+.
|
|
40
44
|
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
45
|
+
# [+:array+]
|
|
46
|
+
# (PostgreSQL only) Specifies that the type should be an array. See the
|
|
47
|
+
# examples below.
|
|
43
48
|
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
49
|
+
# [+:range+]
|
|
50
|
+
# (PostgreSQL only) Specifies that the type should be a range. See the
|
|
51
|
+
# examples below.
|
|
46
52
|
#
|
|
47
53
|
# When using a symbol for +cast_type+, extra options are forwarded to the
|
|
48
54
|
# constructor of the type object.
|
|
@@ -217,17 +223,22 @@ module ActiveRecord
|
|
|
217
223
|
# is provided so it can be used by plugin authors, application code
|
|
218
224
|
# should probably use ClassMethods#attribute.
|
|
219
225
|
#
|
|
220
|
-
#
|
|
226
|
+
# ==== Parameters
|
|
227
|
+
#
|
|
228
|
+
# [+name+]
|
|
229
|
+
# The name of the attribute being defined. Expected to be a +String+.
|
|
221
230
|
#
|
|
222
|
-
# +cast_type+
|
|
231
|
+
# [+cast_type+]
|
|
232
|
+
# The type object to use for this attribute.
|
|
223
233
|
#
|
|
224
|
-
# +default+
|
|
225
|
-
#
|
|
226
|
-
#
|
|
227
|
-
# will be
|
|
234
|
+
# [+default+]
|
|
235
|
+
# The default value to use when no value is provided. If this option
|
|
236
|
+
# is not passed, the previous default value (if any) will be used.
|
|
237
|
+
# Otherwise, the default will be +nil+. A proc can also be passed, and
|
|
238
|
+
# will be called once each time a new value is needed.
|
|
228
239
|
#
|
|
229
|
-
# +user_provided_default+
|
|
230
|
-
# +cast+ or +deserialize+.
|
|
240
|
+
# [+user_provided_default+]
|
|
241
|
+
# Whether the default value should be cast using +cast+ or +deserialize+.
|
|
231
242
|
def define_attribute(
|
|
232
243
|
name,
|
|
233
244
|
cast_type,
|
|
@@ -374,7 +374,7 @@ module ActiveRecord
|
|
|
374
374
|
context = validation_context if custom_validation_context?
|
|
375
375
|
return true if record.valid?(context)
|
|
376
376
|
|
|
377
|
-
if
|
|
377
|
+
if context || record.changed_for_autosave?
|
|
378
378
|
associated_errors = record.errors.objects
|
|
379
379
|
else
|
|
380
380
|
# If there are existing invalid records in the DB, we should still be able to reference them.
|
|
@@ -527,7 +527,7 @@ module ActiveRecord
|
|
|
527
527
|
return false unless reflection.inverse_of&.polymorphic?
|
|
528
528
|
|
|
529
529
|
class_name = record._read_attribute(reflection.inverse_of.foreign_type)
|
|
530
|
-
reflection.active_record !=
|
|
530
|
+
reflection.active_record.polymorphic_name != class_name
|
|
531
531
|
end
|
|
532
532
|
|
|
533
533
|
# Saves the associated record if it's new or <tt>:autosave</tt> is enabled.
|
data/lib/active_record/base.rb
CHANGED
|
@@ -256,13 +256,13 @@ module ActiveRecord # :nodoc:
|
|
|
256
256
|
# * AssociationTypeMismatch - The object assigned to the association wasn't of the type
|
|
257
257
|
# specified in the association definition.
|
|
258
258
|
# * AttributeAssignmentError - An error occurred while doing a mass assignment through the
|
|
259
|
-
# {ActiveRecord::Base#attributes=}[rdoc-ref:AttributeAssignment#attributes=] method.
|
|
259
|
+
# {ActiveRecord::Base#attributes=}[rdoc-ref:ActiveModel::AttributeAssignment#attributes=] method.
|
|
260
260
|
# You can inspect the +attribute+ property of the exception object to determine which attribute
|
|
261
261
|
# triggered the error.
|
|
262
262
|
# * ConnectionNotEstablished - No connection has been established.
|
|
263
263
|
# Use {ActiveRecord::Base.establish_connection}[rdoc-ref:ConnectionHandling#establish_connection] before querying.
|
|
264
264
|
# * MultiparameterAssignmentErrors - Collection of errors that occurred during a mass assignment using the
|
|
265
|
-
# {ActiveRecord::Base#attributes=}[rdoc-ref:AttributeAssignment#attributes=] method.
|
|
265
|
+
# {ActiveRecord::Base#attributes=}[rdoc-ref:ActiveModel::AttributeAssignment#attributes=] method.
|
|
266
266
|
# The +errors+ property of this exception contains an array of
|
|
267
267
|
# AttributeAssignmentError
|
|
268
268
|
# objects that should be inspected to determine which attributes triggered the errors.
|
|
@@ -168,7 +168,7 @@ module ActiveRecord
|
|
|
168
168
|
end
|
|
169
169
|
end
|
|
170
170
|
|
|
171
|
-
# Clears
|
|
171
|
+
# Clears reloadable connection caches in all connection pools.
|
|
172
172
|
#
|
|
173
173
|
# See ConnectionPool#clear_reloadable_connections! for details.
|
|
174
174
|
def clear_reloadable_connections!(role = nil)
|
|
@@ -36,6 +36,7 @@ module ActiveRecord
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def schema_cache; end
|
|
39
|
+
def query_cache; end
|
|
39
40
|
def connection_descriptor; end
|
|
40
41
|
def checkin(_); end
|
|
41
42
|
def remove(_); end
|
|
@@ -119,12 +120,12 @@ module ActiveRecord
|
|
|
119
120
|
class ConnectionPool
|
|
120
121
|
# Prior to 3.3.5, WeakKeyMap had a use after free bug
|
|
121
122
|
# https://bugs.ruby-lang.org/issues/20688
|
|
122
|
-
if ObjectSpace.const_defined?(:WeakKeyMap) && RUBY_VERSION >= "3.3.5"
|
|
123
|
+
if ObjectSpace.const_defined?(:WeakKeyMap) && Gem::Version.new(RUBY_VERSION) >= "3.3.5"
|
|
123
124
|
WeakThreadKeyMap = ObjectSpace::WeakKeyMap
|
|
124
125
|
else
|
|
125
126
|
class WeakThreadKeyMap # :nodoc:
|
|
126
127
|
# FIXME: On 3.3 we could use ObjectSpace::WeakKeyMap
|
|
127
|
-
# but it currently
|
|
128
|
+
# but it currently causes GC crashes: https://github.com/byroot/rails/pull/3
|
|
128
129
|
def initialize
|
|
129
130
|
@map = {}
|
|
130
131
|
end
|
|
@@ -314,8 +315,9 @@ module ActiveRecord
|
|
|
314
315
|
# held in a cache keyed by a thread.
|
|
315
316
|
def lease_connection
|
|
316
317
|
lease = connection_lease
|
|
317
|
-
lease.sticky = true
|
|
318
318
|
lease.connection ||= checkout
|
|
319
|
+
lease.sticky = true
|
|
320
|
+
lease.connection
|
|
319
321
|
end
|
|
320
322
|
|
|
321
323
|
def permanent_lease? # :nodoc:
|
|
@@ -333,6 +335,7 @@ module ActiveRecord
|
|
|
333
335
|
end
|
|
334
336
|
|
|
335
337
|
@pinned_connection.lock_thread = ActiveSupport::IsolatedExecutionState.context if lock_thread
|
|
338
|
+
@pinned_connection.pinned = true
|
|
336
339
|
@pinned_connection.verify! # eagerly validate the connection
|
|
337
340
|
@pinned_connection.begin_transaction joinable: false, _lazy: false
|
|
338
341
|
end
|
|
@@ -355,6 +358,7 @@ module ActiveRecord
|
|
|
355
358
|
end
|
|
356
359
|
|
|
357
360
|
if @pinned_connection.nil?
|
|
361
|
+
connection.pinned = false
|
|
358
362
|
connection.steal!
|
|
359
363
|
connection.lock_thread = nil
|
|
360
364
|
checkin(connection)
|
|
@@ -459,7 +463,7 @@ module ActiveRecord
|
|
|
459
463
|
end
|
|
460
464
|
conn.disconnect!
|
|
461
465
|
end
|
|
462
|
-
@connections = []
|
|
466
|
+
@connections = @pinned_connection ? [@pinned_connection] : []
|
|
463
467
|
@leases.clear
|
|
464
468
|
@available.clear
|
|
465
469
|
end
|
|
@@ -495,7 +499,7 @@ module ActiveRecord
|
|
|
495
499
|
@connections.nil?
|
|
496
500
|
end
|
|
497
501
|
|
|
498
|
-
# Clears
|
|
502
|
+
# Clears reloadable connections from the pool and re-connects connections that
|
|
499
503
|
# require reloading.
|
|
500
504
|
#
|
|
501
505
|
# Raises:
|
|
@@ -518,7 +522,7 @@ module ActiveRecord
|
|
|
518
522
|
end
|
|
519
523
|
end
|
|
520
524
|
|
|
521
|
-
# Clears
|
|
525
|
+
# Clears reloadable connections from the pool and re-connects connections that
|
|
522
526
|
# require reloading.
|
|
523
527
|
#
|
|
524
528
|
# The pool first tries to gain ownership of all connections. If unable to
|