activerecord 6.1.7.8 → 7.0.0.alpha1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +726 -1394
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_record/aggregations.rb +1 -1
- data/lib/active_record/association_relation.rb +0 -10
- data/lib/active_record/associations/association.rb +31 -9
- data/lib/active_record/associations/association_scope.rb +1 -3
- data/lib/active_record/associations/belongs_to_association.rb +15 -4
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +10 -2
- data/lib/active_record/associations/builder/association.rb +8 -2
- data/lib/active_record/associations/builder/belongs_to.rb +19 -6
- data/lib/active_record/associations/builder/collection_association.rb +1 -1
- data/lib/active_record/associations/builder/has_many.rb +3 -2
- data/lib/active_record/associations/builder/has_one.rb +2 -1
- data/lib/active_record/associations/builder/singular_association.rb +2 -2
- data/lib/active_record/associations/collection_association.rb +14 -23
- data/lib/active_record/associations/collection_proxy.rb +8 -3
- data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
- data/lib/active_record/associations/has_many_association.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +2 -1
- data/lib/active_record/associations/has_one_association.rb +10 -7
- data/lib/active_record/associations/has_one_through_association.rb +1 -1
- data/lib/active_record/associations/preloader/association.rb +161 -47
- data/lib/active_record/associations/preloader/batch.rb +51 -0
- data/lib/active_record/associations/preloader/branch.rb +147 -0
- data/lib/active_record/associations/preloader/through_association.rb +37 -11
- data/lib/active_record/associations/preloader.rb +46 -110
- data/lib/active_record/associations/singular_association.rb +8 -2
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/associations.rb +76 -81
- data/lib/active_record/asynchronous_queries_tracker.rb +57 -0
- data/lib/active_record/attribute_assignment.rb +1 -1
- data/lib/active_record/attribute_methods/before_type_cast.rb +7 -2
- data/lib/active_record/attribute_methods/dirty.rb +41 -16
- data/lib/active_record/attribute_methods/primary_key.rb +2 -2
- data/lib/active_record/attribute_methods/query.rb +2 -2
- data/lib/active_record/attribute_methods/read.rb +7 -5
- data/lib/active_record/attribute_methods/serialization.rb +66 -12
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +4 -3
- data/lib/active_record/attribute_methods/write.rb +7 -10
- data/lib/active_record/attribute_methods.rb +6 -9
- data/lib/active_record/attributes.rb +24 -35
- data/lib/active_record/autosave_association.rb +3 -18
- data/lib/active_record/base.rb +19 -1
- data/lib/active_record/callbacks.rb +2 -2
- data/lib/active_record/coders/yaml_column.rb +2 -14
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +312 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +209 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +76 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +31 -558
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +45 -21
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +24 -12
- data/lib/active_record/connection_adapters/abstract/quoting.rb +12 -14
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +4 -17
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +30 -13
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +60 -16
- data/lib/active_record/connection_adapters/abstract/transaction.rb +3 -3
- data/lib/active_record/connection_adapters/abstract_adapter.rb +112 -66
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +96 -81
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +33 -23
- data/lib/active_record/connection_adapters/mysql/quoting.rb +16 -1
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +1 -1
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -6
- data/lib/active_record/connection_adapters/pool_config.rb +1 -3
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +19 -14
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +8 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +5 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +53 -14
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/timestamp.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +28 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +18 -6
- data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +6 -32
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +32 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +5 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +12 -12
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +159 -102
- data/lib/active_record/connection_adapters/schema_cache.rb +36 -37
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +23 -19
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +4 -2
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +61 -30
- data/lib/active_record/connection_adapters.rb +6 -5
- data/lib/active_record/connection_handling.rb +20 -38
- data/lib/active_record/core.rb +111 -125
- data/lib/active_record/database_configurations/connection_url_resolver.rb +0 -1
- data/lib/active_record/database_configurations/database_config.rb +12 -0
- data/lib/active_record/database_configurations/hash_config.rb +27 -1
- data/lib/active_record/database_configurations/url_config.rb +2 -2
- data/lib/active_record/database_configurations.rb +17 -9
- data/lib/active_record/delegated_type.rb +33 -11
- data/lib/active_record/destroy_association_async_job.rb +1 -1
- data/lib/active_record/disable_joins_association_relation.rb +39 -0
- data/lib/active_record/dynamic_matchers.rb +1 -1
- data/lib/active_record/encryption/cipher/aes256_gcm.rb +98 -0
- data/lib/active_record/encryption/cipher.rb +53 -0
- data/lib/active_record/encryption/config.rb +44 -0
- data/lib/active_record/encryption/configurable.rb +61 -0
- data/lib/active_record/encryption/context.rb +35 -0
- data/lib/active_record/encryption/contexts.rb +72 -0
- data/lib/active_record/encryption/derived_secret_key_provider.rb +12 -0
- data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
- data/lib/active_record/encryption/encryptable_record.rb +208 -0
- data/lib/active_record/encryption/encrypted_attribute_type.rb +140 -0
- data/lib/active_record/encryption/encrypted_fixtures.rb +38 -0
- data/lib/active_record/encryption/encrypting_only_encryptor.rb +12 -0
- data/lib/active_record/encryption/encryptor.rb +155 -0
- data/lib/active_record/encryption/envelope_encryption_key_provider.rb +55 -0
- data/lib/active_record/encryption/errors.rb +15 -0
- data/lib/active_record/encryption/extended_deterministic_queries.rb +160 -0
- data/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb +29 -0
- data/lib/active_record/encryption/key.rb +28 -0
- data/lib/active_record/encryption/key_generator.rb +42 -0
- data/lib/active_record/encryption/key_provider.rb +46 -0
- data/lib/active_record/encryption/message.rb +33 -0
- data/lib/active_record/encryption/message_serializer.rb +80 -0
- data/lib/active_record/encryption/null_encryptor.rb +21 -0
- data/lib/active_record/encryption/properties.rb +76 -0
- data/lib/active_record/encryption/read_only_null_encryptor.rb +24 -0
- data/lib/active_record/encryption/scheme.rb +99 -0
- data/lib/active_record/encryption.rb +55 -0
- data/lib/active_record/enum.rb +41 -41
- data/lib/active_record/errors.rb +66 -3
- data/lib/active_record/fixture_set/file.rb +15 -1
- data/lib/active_record/fixture_set/table_row.rb +40 -5
- data/lib/active_record/fixture_set/table_rows.rb +4 -4
- data/lib/active_record/fixtures.rb +16 -11
- data/lib/active_record/future_result.rb +139 -0
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +55 -17
- data/lib/active_record/insert_all.rb +34 -5
- data/lib/active_record/integration.rb +1 -1
- data/lib/active_record/internal_metadata.rb +1 -5
- data/lib/active_record/locking/optimistic.rb +10 -9
- data/lib/active_record/log_subscriber.rb +6 -2
- data/lib/active_record/middleware/database_selector/resolver.rb +6 -10
- data/lib/active_record/middleware/database_selector.rb +8 -3
- data/lib/active_record/migration/command_recorder.rb +4 -4
- data/lib/active_record/migration/compatibility.rb +89 -10
- data/lib/active_record/migration/join_table.rb +1 -1
- data/lib/active_record/migration.rb +109 -79
- data/lib/active_record/model_schema.rb +45 -31
- data/lib/active_record/nested_attributes.rb +3 -3
- data/lib/active_record/no_touching.rb +2 -2
- data/lib/active_record/null_relation.rb +2 -6
- data/lib/active_record/persistence.rb +134 -45
- data/lib/active_record/query_cache.rb +2 -2
- data/lib/active_record/query_logs.rb +203 -0
- data/lib/active_record/querying.rb +15 -5
- data/lib/active_record/railtie.rb +117 -17
- data/lib/active_record/railties/controller_runtime.rb +1 -1
- data/lib/active_record/railties/databases.rake +72 -48
- data/lib/active_record/readonly_attributes.rb +11 -0
- data/lib/active_record/reflection.rb +45 -44
- data/lib/active_record/relation/batches/batch_enumerator.rb +19 -5
- data/lib/active_record/relation/batches.rb +3 -3
- data/lib/active_record/relation/calculations.rb +39 -26
- data/lib/active_record/relation/delegation.rb +6 -6
- data/lib/active_record/relation/finder_methods.rb +31 -22
- data/lib/active_record/relation/merger.rb +20 -13
- data/lib/active_record/relation/predicate_builder.rb +1 -6
- data/lib/active_record/relation/query_attribute.rb +5 -11
- data/lib/active_record/relation/query_methods.rb +230 -49
- data/lib/active_record/relation/record_fetch_warning.rb +2 -2
- data/lib/active_record/relation/spawn_methods.rb +2 -2
- data/lib/active_record/relation/where_clause.rb +8 -4
- data/lib/active_record/relation.rb +166 -77
- data/lib/active_record/result.rb +17 -2
- data/lib/active_record/runtime_registry.rb +2 -4
- data/lib/active_record/sanitization.rb +11 -7
- data/lib/active_record/schema_dumper.rb +3 -3
- data/lib/active_record/schema_migration.rb +0 -4
- data/lib/active_record/scoping/default.rb +61 -12
- data/lib/active_record/scoping/named.rb +3 -11
- data/lib/active_record/scoping.rb +40 -22
- data/lib/active_record/serialization.rb +1 -1
- data/lib/active_record/signed_id.rb +1 -1
- data/lib/active_record/store.rb +1 -6
- data/lib/active_record/tasks/database_tasks.rb +106 -22
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -1
- data/lib/active_record/tasks/postgresql_database_tasks.rb +14 -11
- data/lib/active_record/test_databases.rb +1 -1
- data/lib/active_record/test_fixtures.rb +9 -13
- data/lib/active_record/timestamp.rb +3 -4
- data/lib/active_record/transactions.rb +9 -14
- data/lib/active_record/translation.rb +2 -2
- data/lib/active_record/type/adapter_specific_registry.rb +32 -7
- data/lib/active_record/type/hash_lookup_type_map.rb +34 -1
- data/lib/active_record/type/internal/timezone.rb +2 -2
- data/lib/active_record/type/serialized.rb +1 -1
- data/lib/active_record/type/type_map.rb +17 -20
- data/lib/active_record/type.rb +1 -2
- data/lib/active_record/validations/associated.rb +1 -1
- data/lib/active_record.rb +170 -2
- data/lib/arel/attributes/attribute.rb +0 -8
- data/lib/arel/crud.rb +18 -22
- data/lib/arel/delete_manager.rb +2 -4
- data/lib/arel/insert_manager.rb +2 -3
- data/lib/arel/nodes/casted.rb +1 -1
- data/lib/arel/nodes/delete_statement.rb +8 -13
- data/lib/arel/nodes/insert_statement.rb +2 -2
- data/lib/arel/nodes/select_core.rb +2 -2
- data/lib/arel/nodes/select_statement.rb +2 -2
- data/lib/arel/nodes/update_statement.rb +3 -2
- data/lib/arel/predications.rb +1 -1
- data/lib/arel/select_manager.rb +10 -4
- data/lib/arel/table.rb +0 -1
- data/lib/arel/tree_manager.rb +0 -12
- data/lib/arel/update_manager.rb +2 -4
- data/lib/arel/visitors/dot.rb +80 -90
- data/lib/arel/visitors/mysql.rb +6 -1
- data/lib/arel/visitors/postgresql.rb +0 -10
- data/lib/arel/visitors/to_sql.rb +43 -2
- data/lib/arel.rb +1 -1
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/templates/module.rb.tt +2 -2
- metadata +55 -17
data/CHANGELOG.md
CHANGED
@@ -1,1832 +1,1164 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 7.0.0.alpha1 (September 15, 2021) ##
|
2
2
|
|
3
|
-
*
|
3
|
+
* Remove warning when overwriting existing scopes
|
4
4
|
|
5
|
+
Removes the following unnecessary warning message that appeared when overwriting existing scopes
|
5
6
|
|
6
|
-
## Rails 6.1.7.7 (February 21, 2024) ##
|
7
|
-
|
8
|
-
* No changes.
|
9
|
-
|
10
|
-
|
11
|
-
## Rails 6.1.7.6 (August 22, 2023) ##
|
12
|
-
|
13
|
-
* No changes.
|
14
|
-
|
15
|
-
|
16
|
-
## Rails 6.1.7.5 (August 22, 2023) ##
|
17
|
-
|
18
|
-
* No changes.
|
19
|
-
|
20
|
-
|
21
|
-
## Rails 6.1.7.4 (June 26, 2023) ##
|
22
|
-
|
23
|
-
* No changes.
|
24
|
-
|
25
|
-
|
26
|
-
## Rails 6.1.7.3 (March 13, 2023) ##
|
27
|
-
|
28
|
-
* No changes.
|
29
|
-
|
30
|
-
|
31
|
-
## Rails 6.1.7.2 (January 24, 2023) ##
|
32
|
-
|
33
|
-
* No changes.
|
34
|
-
|
35
|
-
|
36
|
-
## Rails 6.1.7.1 (January 17, 2023) ##
|
37
|
-
|
38
|
-
* Make sanitize_as_sql_comment more strict
|
39
|
-
|
40
|
-
Though this method was likely never meant to take user input, it was
|
41
|
-
attempting sanitization. That sanitization could be bypassed with
|
42
|
-
carefully crafted input.
|
43
|
-
|
44
|
-
This commit makes the sanitization more robust by replacing any
|
45
|
-
occurrances of "/*" or "*/" with "/ *" or "* /". It also performs a
|
46
|
-
first pass to remove one surrounding comment to avoid compatibility
|
47
|
-
issues for users relying on the existing removal.
|
48
|
-
|
49
|
-
This also clarifies in the documentation of annotate that it should not
|
50
|
-
be provided user input.
|
51
|
-
|
52
|
-
[CVE-2023-22794]
|
53
|
-
|
54
|
-
* Added integer width check to PostgreSQL::Quoting
|
55
|
-
|
56
|
-
Given a value outside the range for a 64bit signed integer type
|
57
|
-
PostgreSQL will treat the column type as numeric. Comparing
|
58
|
-
integer values against numeric values can result in a slow
|
59
|
-
sequential scan.
|
60
|
-
|
61
|
-
This behavior is configurable via
|
62
|
-
ActiveRecord::Base.raise_int_wider_than_64bit which defaults to true.
|
63
|
-
|
64
|
-
[CVE-2022-44566]
|
65
|
-
|
66
|
-
## Rails 6.1.7 (September 09, 2022) ##
|
67
|
-
|
68
|
-
* Symbol is allowed by default for YAML columns
|
69
|
-
|
70
|
-
*Étienne Barrié*
|
71
|
-
|
72
|
-
* Fix `ActiveRecord::Store` to serialize as a regular Hash
|
73
|
-
|
74
|
-
Previously it would serialize as an `ActiveSupport::HashWithIndifferentAccess`
|
75
|
-
which is wasteful and cause problem with YAML safe_load.
|
76
|
-
|
77
|
-
*Jean Boussier*
|
78
|
-
|
79
|
-
* Fix PG.connect keyword arguments deprecation warning on ruby 2.7
|
80
|
-
|
81
|
-
Fixes #44307.
|
82
|
-
|
83
|
-
*Nikita Vasilevsky*
|
84
|
-
|
85
|
-
## Rails 6.1.6.1 (July 12, 2022) ##
|
86
|
-
|
87
|
-
* Change ActiveRecord::Coders::YAMLColumn default to safe_load
|
88
|
-
|
89
|
-
This adds two new configuration options The configuration options are as
|
90
|
-
follows:
|
91
|
-
|
92
|
-
* `config.active_storage.use_yaml_unsafe_load`
|
93
|
-
|
94
|
-
When set to true, this configuration option tells Rails to use the old
|
95
|
-
"unsafe" YAML loading strategy, maintaining the existing behavior but leaving
|
96
|
-
the possible escalation vulnerability in place. Setting this option to true
|
97
|
-
is *not* recommended, but can aid in upgrading.
|
98
|
-
|
99
|
-
* `config.active_record.yaml_column_permitted_classes`
|
100
|
-
|
101
|
-
The "safe YAML" loading method does not allow all classes to be deserialized
|
102
|
-
by default. This option allows you to specify classes deemed "safe" in your
|
103
|
-
application. For example, if your application uses Symbol and Time in
|
104
|
-
serialized data, you can add Symbol and Time to the allowed list as follows:
|
105
|
-
|
106
7
|
```
|
107
|
-
|
8
|
+
Creating scope :my_scope_name. Overwriting existing method "MyClass.my_scope_name" when overwriting existing scopes
|
108
9
|
```
|
109
10
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
## Rails 6.1.6 (May 09, 2022) ##
|
114
|
-
|
115
|
-
* No changes.
|
116
|
-
|
117
|
-
|
118
|
-
## Rails 6.1.5.1 (April 26, 2022) ##
|
119
|
-
|
120
|
-
* No changes.
|
121
|
-
|
11
|
+
*Weston Ganger*
|
122
12
|
|
123
|
-
|
13
|
+
* Use full precision for `updated_at` in `insert_all`/`upsert_all`
|
124
14
|
|
125
|
-
|
15
|
+
`CURRENT_TIMESTAMP` provides differing precision depending on the database,
|
16
|
+
and not all databases support explicitly specifying additional precision.
|
126
17
|
|
127
|
-
|
128
|
-
|
129
|
-
This was later identified as a bug (https://bugs.ruby-lang.org/issues/15926) and only
|
130
|
-
fixed in Ruby 2.7.
|
18
|
+
Instead, we delegate to the new `connection.high_precision_current_timestamp`
|
19
|
+
for the SQL to produce a high precision timestamp on the current database.
|
131
20
|
|
132
|
-
|
133
|
-
`ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` method, which internally
|
134
|
-
calls the `String#-@` method, could also modify an input string argument in Ruby 2.6 --
|
135
|
-
changing a tainted, unfrozen string into a tainted, frozen string.
|
21
|
+
Fixes #42992
|
136
22
|
|
137
|
-
|
23
|
+
*Sam Bostock*
|
138
24
|
|
139
|
-
|
25
|
+
* Add ssl support for postgresql database tasks
|
140
26
|
|
141
|
-
|
142
|
-
|
27
|
+
Add `PGSSLMODE`, `PGSSLCERT`, `PGSSLKEY` and `PGSSLROOTCERT` to pg_env from database config
|
28
|
+
when running postgresql database tasks.
|
143
29
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
*Marcelo Lauxen*
|
148
|
-
|
149
|
-
* Fix dbconsole for 3-tier config.
|
150
|
-
|
151
|
-
*Eileen M. Uchitelle*
|
152
|
-
|
153
|
-
* Better handle SQL queries with invalid encoding.
|
30
|
+
```yaml
|
31
|
+
# config/database.yml
|
154
32
|
|
155
|
-
|
156
|
-
|
33
|
+
production:
|
34
|
+
sslmode: verify-full
|
35
|
+
sslcert: client.crt
|
36
|
+
sslkey: client.key
|
37
|
+
sslrootcert: ca.crt
|
157
38
|
```
|
158
39
|
|
159
|
-
|
160
|
-
responsible to detect write queries.
|
161
|
-
|
162
|
-
The query is now properly passed to the database connection, which might or might
|
163
|
-
not be able to handle it, but will either succeed or failed in a more correct way.
|
164
|
-
|
165
|
-
*Jean Boussier*
|
166
|
-
|
167
|
-
* Ignore persisted in-memory records when merging target lists.
|
168
|
-
|
169
|
-
*Kevin Sjöberg*
|
170
|
-
|
171
|
-
* Fix regression bug that caused ignoring additional conditions for preloading
|
172
|
-
`has_many` through relations.
|
173
|
-
|
174
|
-
Fixes #43132
|
175
|
-
|
176
|
-
*Alexander Pauly*
|
177
|
-
|
178
|
-
* Fix `ActiveRecord::InternalMetadata` to not be broken by
|
179
|
-
`config.active_record.record_timestamps = false`
|
180
|
-
|
181
|
-
Since the model always create the timestamp columns, it has to set them, otherwise it breaks
|
182
|
-
various DB management tasks.
|
183
|
-
|
184
|
-
Fixes #42983
|
185
|
-
|
186
|
-
*Jean Boussier*
|
187
|
-
|
188
|
-
* Fix duplicate active record objects on `inverse_of`.
|
189
|
-
|
190
|
-
*Justin Carvalho*
|
191
|
-
|
192
|
-
* Fix duplicate objects stored in has many association after save.
|
193
|
-
|
194
|
-
Fixes #42549.
|
195
|
-
|
196
|
-
*Alex Ghiculescu*
|
197
|
-
|
198
|
-
* Fix performance regression in `CollectionAssocation#build`.
|
199
|
-
|
200
|
-
*Alex Ghiculescu*
|
201
|
-
|
202
|
-
* Fix retrieving default value for text column for MariaDB.
|
203
|
-
|
204
|
-
*fatkodima*
|
205
|
-
|
206
|
-
|
207
|
-
## Rails 6.1.4.7 (March 08, 2022) ##
|
208
|
-
|
209
|
-
* No changes.
|
210
|
-
|
211
|
-
|
212
|
-
## Rails 6.1.4.6 (February 11, 2022) ##
|
213
|
-
|
214
|
-
* No changes.
|
215
|
-
|
216
|
-
|
217
|
-
## Rails 6.1.4.5 (February 11, 2022) ##
|
218
|
-
|
219
|
-
* No changes.
|
220
|
-
|
221
|
-
|
222
|
-
## Rails 6.1.4.4 (December 15, 2021) ##
|
223
|
-
|
224
|
-
* No changes.
|
225
|
-
|
226
|
-
|
227
|
-
## Rails 6.1.4.3 (December 14, 2021) ##
|
228
|
-
|
229
|
-
* No changes.
|
230
|
-
|
231
|
-
|
232
|
-
## Rails 6.1.4.2 (December 14, 2021) ##
|
233
|
-
|
234
|
-
* No changes.
|
235
|
-
|
236
|
-
|
237
|
-
## Rails 6.1.4.1 (August 19, 2021) ##
|
238
|
-
|
239
|
-
* No changes.
|
240
|
-
|
241
|
-
|
242
|
-
## Rails 6.1.4 (June 24, 2021) ##
|
243
|
-
|
244
|
-
* Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
|
245
|
-
|
246
|
-
*Jamie McCarthy*
|
247
|
-
|
248
|
-
* Raise an error if `pool_config` is `nil` in `set_pool_config`.
|
249
|
-
|
250
|
-
*Eileen M. Uchitelle*
|
251
|
-
|
252
|
-
* Fix compatibility with `psych >= 4`.
|
253
|
-
|
254
|
-
Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load`. To preserve compatibility
|
255
|
-
Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
|
256
|
-
|
257
|
-
*Jean Boussier*
|
258
|
-
|
259
|
-
* Support using replicas when using `rails dbconsole`.
|
260
|
-
|
261
|
-
*Christopher Thornton*
|
262
|
-
|
263
|
-
* Restore connection pools after transactional tests.
|
264
|
-
|
265
|
-
*Eugene Kenny*
|
266
|
-
|
267
|
-
* Change `upsert_all` to fails cleanly for MySQL when `:unique_by` is used.
|
268
|
-
|
269
|
-
*Bastian Bartmann*
|
270
|
-
|
271
|
-
* Fix user-defined `self.default_scope` to respect table alias.
|
272
|
-
|
273
|
-
*Ryuta Kamizono*
|
274
|
-
|
275
|
-
* Clear `@cache_keys` cache after `update_all`, `delete_all`, `destroy_all`.
|
276
|
-
|
277
|
-
*Ryuta Kamizono*
|
278
|
-
|
279
|
-
* Changed Arel predications `contains` and `overlaps` to use
|
280
|
-
`quoted_node` so that PostgreSQL arrays are quoted properly.
|
281
|
-
|
282
|
-
*Bradley Priest*
|
283
|
-
|
284
|
-
* Fix `merge` when the `where` clauses have string contents.
|
285
|
-
|
286
|
-
*Ryuta Kamizono*
|
287
|
-
|
288
|
-
* Fix rollback of parent destruction with nested `dependent: :destroy`.
|
289
|
-
|
290
|
-
*Jacopo Beschi*
|
291
|
-
|
292
|
-
* Fix binds logging for `"WHERE ... IN ..."` statements.
|
293
|
-
|
294
|
-
*Ricardo Díaz*
|
295
|
-
|
296
|
-
* Handle `false` in relation strict loading checks.
|
297
|
-
|
298
|
-
Previously when a model had strict loading set to true and then had a
|
299
|
-
relation set `strict_loading` to false the false wasn't considered when
|
300
|
-
deciding whether to raise/warn about strict loading.
|
40
|
+
Environment variables
|
301
41
|
|
302
42
|
```
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
end
|
43
|
+
PGSSLMODE=verify-full
|
44
|
+
PGSSLCERT=client.crt
|
45
|
+
PGSSLKEY=client.key
|
46
|
+
PGSSLROOTCERT=ca.crt
|
308
47
|
```
|
309
48
|
|
310
|
-
|
311
|
-
`strict_loading` was set to false. This is a bug affecting more than
|
312
|
-
Active Storage which is why I made this PR superseding #41461. We need
|
313
|
-
to fix this for all applications since the behavior is a little
|
314
|
-
surprising. I took the test from #41461 and the code suggestion from #41453
|
315
|
-
with some additions.
|
49
|
+
Fixes #42994
|
316
50
|
|
317
|
-
*
|
51
|
+
*Michael Bayucot*
|
318
52
|
|
319
|
-
*
|
53
|
+
* Avoid scoping update callbacks in `ActiveRecord::Relation#update!`.
|
320
54
|
|
321
|
-
|
322
|
-
|
323
|
-
* Fix aggregate attribute on Enum types.
|
324
|
-
|
325
|
-
*Ryuta Kamizono*
|
55
|
+
Making it consistent with how scoping is applied only to the query in `ActiveRecord::Relation#update`
|
56
|
+
and not also to the callbacks from the update itself.
|
326
57
|
|
327
|
-
*
|
328
|
-
|
329
|
-
*eltongo*
|
330
|
-
|
331
|
-
* Fix where clause on enum attribute when providing array of strings.
|
332
|
-
|
333
|
-
*Ryuta Kamizono*
|
334
|
-
|
335
|
-
* Fix `unprepared_statement` to work it when nesting.
|
336
|
-
|
337
|
-
*Ryuta Kamizono*
|
338
|
-
|
339
|
-
|
340
|
-
## Rails 6.1.3.2 (May 05, 2021) ##
|
341
|
-
|
342
|
-
* No changes.
|
343
|
-
|
344
|
-
|
345
|
-
## Rails 6.1.3.1 (March 26, 2021) ##
|
346
|
-
|
347
|
-
* No changes.
|
348
|
-
|
349
|
-
|
350
|
-
## Rails 6.1.3 (February 17, 2021) ##
|
351
|
-
|
352
|
-
* Fix the MySQL adapter to always set the right collation and charset
|
353
|
-
to the connection session.
|
354
|
-
|
355
|
-
*Rafael Mendonça França*
|
356
|
-
|
357
|
-
* Fix MySQL adapter handling of time objects when prepared statements
|
358
|
-
are enabled.
|
58
|
+
*Dylan Thacker-Smith*
|
359
59
|
|
360
|
-
|
60
|
+
* Fix 2 cases that inferred polymorphic class from the association's `foreign_type`
|
61
|
+
using `String#constantize` instead of the model's `polymorphic_class_for`.
|
361
62
|
|
362
|
-
|
363
|
-
|
63
|
+
When updating a polymorphic association, the old `foreign_type` was not inferred correctly when:
|
64
|
+
1. `touch`ing the previously associated record
|
65
|
+
2. updating the previously associated record's `counter_cache`
|
364
66
|
|
365
|
-
*
|
67
|
+
*Jimmy Bourassa*
|
366
68
|
|
367
|
-
*
|
368
|
-
with a having clause
|
69
|
+
* Add config option for ignoring tables when dumping the schema cache.
|
369
70
|
|
370
|
-
|
371
|
-
references an aliased select value would generate an error when
|
372
|
-
#include? was called, due to an optimisation that would generate
|
373
|
-
call #exists? on the relation instead, which effectively alters
|
374
|
-
the select values of the query (and thus removes the aliased select
|
375
|
-
values), but leaves the having clause intact. Because the having
|
376
|
-
clause is then referencing an aliased column that is no longer
|
377
|
-
present in the simplified query, an ActiveRecord::InvalidStatement
|
378
|
-
error was raised.
|
71
|
+
Applications can now be configured to ignore certain tables when dumping the schema cache.
|
379
72
|
|
380
|
-
|
73
|
+
The configuration option can table an array of tables:
|
381
74
|
|
382
75
|
```ruby
|
383
|
-
|
384
|
-
.joins(:posts)
|
385
|
-
.group(:id)
|
386
|
-
.having('total_posts > 2')
|
387
|
-
.include?(Author.first)
|
76
|
+
config.active_record.schema_cache_ignored_tables = ["ignored_table", "another_ignored_table"]
|
388
77
|
```
|
389
78
|
|
390
|
-
|
391
|
-
simplified #exists? query, which simply checks for the presence of
|
392
|
-
a having clause.
|
393
|
-
|
394
|
-
Fixes #41417
|
395
|
-
|
396
|
-
*Michael Smart*
|
397
|
-
|
398
|
-
* Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
|
399
|
-
without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
|
400
|
-
up in perpetual crash state for being inconsistent with Postgres.
|
401
|
-
|
402
|
-
*wbharding*, *Martin Tepper*
|
403
|
-
|
404
|
-
|
405
|
-
## Rails 6.1.2.1 (February 10, 2021) ##
|
406
|
-
|
407
|
-
* Fix possible DoS vector in PostgreSQL money type
|
408
|
-
|
409
|
-
Carefully crafted input can cause a DoS via the regular expressions used
|
410
|
-
for validating the money format in the PostgreSQL adapter. This patch
|
411
|
-
fixes the regexp.
|
412
|
-
|
413
|
-
Thanks to @dee-see from Hackerone for this patch!
|
414
|
-
|
415
|
-
[CVE-2021-22880]
|
416
|
-
|
417
|
-
*Aaron Patterson*
|
418
|
-
|
419
|
-
|
420
|
-
## Rails 6.1.2 (February 09, 2021) ##
|
421
|
-
|
422
|
-
* Fix timestamp type for sqlite3.
|
423
|
-
|
424
|
-
*Eileen M. Uchitelle*
|
425
|
-
|
426
|
-
* Make destroy async transactional.
|
427
|
-
|
428
|
-
An active record rollback could occur while enqueuing a job. In this
|
429
|
-
case the job would enqueue even though the database deletion
|
430
|
-
rolledback putting things in a funky state.
|
431
|
-
|
432
|
-
Now the jobs are only enqueued until after the db transaction has been committed.
|
433
|
-
|
434
|
-
*Cory Gwin*
|
79
|
+
Or a regex:
|
435
80
|
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
* Connection specification now passes the "url" key as a configuration for the
|
441
|
-
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
|
442
|
-
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
|
443
|
-
are assumed to be adapter specification urls.
|
444
|
-
|
445
|
-
Fixes #41137.
|
446
|
-
|
447
|
-
*Jonathan Bracy*
|
448
|
-
|
449
|
-
* Fix granular connection swapping when there are multiple abstract classes.
|
81
|
+
```ruby
|
82
|
+
config.active_record.schema_cache_ignored_tables = [/^_/]
|
83
|
+
```
|
450
84
|
|
451
85
|
*Eileen M. Uchitelle*
|
452
86
|
|
453
|
-
*
|
454
|
-
|
455
|
-
*Ryuta Kamizono*
|
456
|
-
|
457
|
-
* Add support for `rails console --sandbox` for multiple database applications.
|
458
|
-
|
459
|
-
*alpaca-tc*
|
87
|
+
* Make schema cache methods return consistent results.
|
460
88
|
|
461
|
-
|
89
|
+
Previously the schema cache methods `primary_keys`, `columns`, `columns_hash`, and `indexes`
|
90
|
+
would behave differently than one another when a table didn't exist and differently across
|
91
|
+
database adapters. This change unifies the behavior so each method behaves the same regardless
|
92
|
+
of adapter.
|
462
93
|
|
463
|
-
|
94
|
+
The behavior now is:
|
464
95
|
|
465
|
-
|
96
|
+
`columns`: (unchanged) raises a db error if the table does not exist
|
97
|
+
`columns_hash`: (unchanged) raises a db error if the table does not exist
|
98
|
+
`primary_keys`: (unchanged) returns `nil` if the table does not exist
|
99
|
+
`indexes`: (changed for mysql2) returns `[]` if the table does not exist
|
466
100
|
|
467
101
|
*Eileen M. Uchitelle*
|
468
102
|
|
103
|
+
* Reestablish connection to previous database after after running `db:schema:load:name`
|
469
104
|
|
470
|
-
|
471
|
-
|
472
|
-
* Fix fixtures loading when strict loading is enabled for the association.
|
473
|
-
|
474
|
-
*Alex Ghiculescu*
|
475
|
-
|
476
|
-
* Fix `where` with custom primary key for belongs_to association.
|
477
|
-
|
478
|
-
*Ryuta Kamizono*
|
479
|
-
|
480
|
-
* Fix `where` with aliased associations.
|
481
|
-
|
482
|
-
*Ryuta Kamizono*
|
483
|
-
|
484
|
-
* Fix `composed_of` with symbol mapping.
|
485
|
-
|
486
|
-
*Ryuta Kamizono*
|
487
|
-
|
488
|
-
* Don't skip money's type cast for pluck and calculations.
|
489
|
-
|
490
|
-
*Ryuta Kamizono*
|
491
|
-
|
492
|
-
* Fix `where` on polymorphic association with non Active Record object.
|
493
|
-
|
494
|
-
*Ryuta Kamizono*
|
495
|
-
|
496
|
-
* Make sure `db:prepare` works even the schema file doesn't exist.
|
497
|
-
|
498
|
-
*Rafael Mendonça França*
|
105
|
+
After running `db:schema:load:name` the previous connection is restored.
|
499
106
|
|
500
|
-
*
|
501
|
-
|
502
|
-
*Ryuta Kamizono*
|
503
|
-
|
504
|
-
* Handle STI models for `has_many dependent: :destroy_async`.
|
505
|
-
|
506
|
-
*Muhammad Usman*
|
507
|
-
|
508
|
-
* Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
|
509
|
-
|
510
|
-
Previously, passing `false` would trigger the option validation logic
|
511
|
-
to throw an error saying :polymorphic would not be a valid option.
|
512
|
-
|
513
|
-
*glaszig*
|
107
|
+
*Jacopo Beschi*
|
514
108
|
|
515
|
-
*
|
109
|
+
* Add database config option `database_tasks`
|
516
110
|
|
517
|
-
|
111
|
+
If you would like to connect to an external database without any database
|
112
|
+
management tasks such as schema management, migrations, seeds, etc. you can set
|
113
|
+
the per database config option `database_tasks: false`
|
518
114
|
|
519
|
-
|
520
|
-
|
521
|
-
automatically.
|
115
|
+
```yaml
|
116
|
+
# config/database.yml
|
522
117
|
|
523
|
-
|
524
|
-
|
118
|
+
production:
|
119
|
+
primary:
|
120
|
+
database: my_database
|
121
|
+
adapter: mysql2
|
122
|
+
animals:
|
123
|
+
database: my_animals_database
|
124
|
+
adapter: mysql2
|
125
|
+
database_tasks: false
|
525
126
|
```
|
526
127
|
|
527
|
-
*
|
528
|
-
|
529
|
-
|
530
|
-
## Rails 6.1.0 (December 09, 2020) ##
|
531
|
-
|
532
|
-
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
533
|
-
|
534
|
-
Fixes #39065.
|
535
|
-
|
536
|
-
*Alex Ghiculescu*
|
537
|
-
|
538
|
-
* Change `attribute_for_inspect` to take `filter_attributes` in consideration.
|
128
|
+
*Weston Ganger*
|
539
129
|
|
540
|
-
|
130
|
+
* Fix `ActiveRecord::InternalMetadata` to not be broken by `config.active_record.record_timestamps = false`
|
541
131
|
|
542
|
-
|
132
|
+
Since the model always create the timestamp columns, it has to set them, otherwise it breaks
|
133
|
+
various DB management tasks.
|
543
134
|
|
544
|
-
Fixes #
|
135
|
+
Fixes #42983
|
545
136
|
|
546
|
-
|
137
|
+
* Add `ActiveRecord::QueryLogs`.
|
547
138
|
|
548
|
-
|
139
|
+
Configurable tags can be automatically added to all SQL queries generated by Active Record.
|
549
140
|
|
550
141
|
```ruby
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
@author = author
|
142
|
+
# config/application.rb
|
143
|
+
module MyApp
|
144
|
+
class Application < Rails::Application
|
145
|
+
config.active_record.query_log_tags_enabled = true
|
556
146
|
end
|
557
147
|
end
|
558
|
-
|
559
|
-
Post.where(author: AdminAuthor.new(author))
|
560
148
|
```
|
561
149
|
|
562
|
-
|
563
|
-
|
564
|
-
* Add `connected_to_many` API.
|
565
|
-
|
566
|
-
This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
|
567
|
-
|
568
|
-
Before:
|
569
|
-
|
570
|
-
AnimalsRecord.connected_to(role: :reading) do
|
571
|
-
MealsRecord.connected_to(role: :reading) do
|
572
|
-
Dog.first # read from animals replica
|
573
|
-
Dinner.first # read from meals replica
|
574
|
-
Person.first # read from primary writer
|
575
|
-
end
|
576
|
-
end
|
577
|
-
|
578
|
-
After:
|
579
|
-
|
580
|
-
ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
|
581
|
-
Dog.first # read from animals replica
|
582
|
-
Dinner.first # read from meals replica
|
583
|
-
Person.first # read from primary writer
|
584
|
-
end
|
585
|
-
|
586
|
-
*Eileen M. Uchitelle*, *John Crepezzi*
|
587
|
-
|
588
|
-
* Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
|
589
|
-
|
590
|
-
Some applications may not want to raise an error in production if using `strict_loading`. This would allow an application to set strict loading to log for the production environment while still raising in development and test environments.
|
591
|
-
|
592
|
-
Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
|
593
|
-
|
594
|
-
*Eileen M. Uchitelle*
|
595
|
-
|
596
|
-
* Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
|
597
|
-
|
598
|
-
Fixes #34255.
|
599
|
-
|
600
|
-
*Steven Weber*
|
601
|
-
|
602
|
-
* Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
|
603
|
-
|
604
|
-
Because the default behaviour when adding an index with multiple columns is to use all column names in the index name, this could frequently lead to overly long index names for polymorphic references which would fail the migration if it exceeded the database limit.
|
605
|
-
|
606
|
-
This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
|
607
|
-
|
608
|
-
Fixes #38655.
|
609
|
-
|
610
|
-
*Luke Redpath*
|
611
|
-
|
612
|
-
* MySQL: Uniqueness validator now respects default database collation,
|
613
|
-
no longer enforce case sensitive comparison by default.
|
614
|
-
|
615
|
-
*Ryuta Kamizono*
|
616
|
-
|
617
|
-
* Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
|
618
|
-
|
619
|
-
`column_name_length`
|
620
|
-
`table_name_length`
|
621
|
-
`columns_per_table`
|
622
|
-
`indexes_per_table`
|
623
|
-
`columns_per_multicolumn_index`
|
624
|
-
`sql_query_length`
|
625
|
-
`joins_per_query`
|
626
|
-
|
627
|
-
*Rafael Mendonça França*
|
628
|
-
|
629
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?`.
|
630
|
-
|
631
|
-
*Rafael Mendonça França*
|
632
|
-
|
633
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
|
634
|
-
|
635
|
-
*Rafael Mendonça França*
|
636
|
-
|
637
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
|
638
|
-
|
639
|
-
*Rafael Mendonça França*
|
640
|
-
|
641
|
-
* Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
|
642
|
-
|
643
|
-
*Rafael Mendonça França*
|
644
|
-
|
645
|
-
* Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
|
646
|
-
|
647
|
-
*Rafael Mendonça França*
|
648
|
-
|
649
|
-
* Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
|
650
|
-
|
651
|
-
*Rafael Mendonça França*
|
652
|
-
|
653
|
-
* `relation.create` does no longer leak scope to class level querying methods
|
654
|
-
in initialization block and callbacks.
|
655
|
-
|
656
|
-
Before:
|
657
|
-
|
658
|
-
User.where(name: "John").create do |john|
|
659
|
-
User.find_by(name: "David") # => nil
|
660
|
-
end
|
661
|
-
|
662
|
-
After:
|
663
|
-
|
664
|
-
User.where(name: "John").create do |john|
|
665
|
-
User.find_by(name: "David") # => #<User name: "David", ...>
|
666
|
-
end
|
667
|
-
|
668
|
-
*Ryuta Kamizono*
|
669
|
-
|
670
|
-
* Named scope chain does no longer leak scope to class level querying methods.
|
671
|
-
|
672
|
-
class User < ActiveRecord::Base
|
673
|
-
scope :david, -> { User.where(name: "David") }
|
674
|
-
end
|
675
|
-
|
676
|
-
Before:
|
677
|
-
|
678
|
-
User.where(name: "John").david
|
679
|
-
# SELECT * FROM users WHERE name = 'John' AND name = 'David'
|
680
|
-
|
681
|
-
After:
|
682
|
-
|
683
|
-
User.where(name: "John").david
|
684
|
-
# SELECT * FROM users WHERE name = 'David'
|
685
|
-
|
686
|
-
*Ryuta Kamizono*
|
687
|
-
|
688
|
-
* Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
|
689
|
-
|
690
|
-
`fetch`
|
691
|
-
`each`
|
692
|
-
`first`
|
693
|
-
`values`
|
694
|
-
`[]=`
|
695
|
-
|
696
|
-
*Rafael Mendonça França*
|
697
|
-
|
698
|
-
* `where.not` now generates NAND predicates instead of NOR.
|
699
|
-
|
700
|
-
Before:
|
701
|
-
|
702
|
-
User.where.not(name: "Jon", role: "admin")
|
703
|
-
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
|
704
|
-
|
705
|
-
After:
|
706
|
-
|
707
|
-
User.where.not(name: "Jon", role: "admin")
|
708
|
-
# SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
|
709
|
-
|
710
|
-
*Rafael Mendonça França*
|
711
|
-
|
712
|
-
* Remove deprecated `ActiveRecord::Result#to_hash` method.
|
713
|
-
|
714
|
-
*Rafael Mendonça França*
|
715
|
-
|
716
|
-
* Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
|
717
|
-
|
718
|
-
*Rafael Mendonça França*
|
719
|
-
|
720
|
-
* Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
|
721
|
-
|
722
|
-
*Rafael Mendonça França*
|
723
|
-
|
724
|
-
* Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
|
725
|
-
message using `config.active_record.suppress_multiple_database_warning`.
|
726
|
-
|
727
|
-
*Omri Gabay*
|
728
|
-
|
729
|
-
* Connections can be granularly switched for abstract classes when `connected_to` is called.
|
730
|
-
|
731
|
-
This change allows `connected_to` to switch a `role` and/or `shard` for a single abstract class instead of all classes globally. Applications that want to use the new feature need to set `config.active_record.legacy_connection_handling` to `false` in their application configuration.
|
732
|
-
|
733
|
-
Example usage:
|
734
|
-
|
735
|
-
Given an application we have a `User` model that inherits from `ApplicationRecord` and a `Dog` model that inherits from `AnimalsRecord`. `AnimalsRecord` and `ApplicationRecord` have writing and reading connections as well as shard `default`, `one`, and `two`.
|
150
|
+
By default the application, controller and action details are added to the query tags:
|
736
151
|
|
737
152
|
```ruby
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
AnimalsRecord.connected_to(role: :writing, shard: :one) do
|
743
|
-
User.first # reads from default replica
|
744
|
-
Dog.first # reads from shard one primary
|
745
|
-
end
|
746
|
-
|
747
|
-
User.first # reads from default replica
|
748
|
-
Dog.first # reads from default replica
|
749
|
-
|
750
|
-
ApplicationRecord.connected_to(role: :writing, shard: :two) do
|
751
|
-
User.first # reads from shard two primary
|
752
|
-
Dog.first # reads from default replica
|
153
|
+
class BooksController < ApplicationController
|
154
|
+
def index
|
155
|
+
@books = Book.all
|
753
156
|
end
|
754
157
|
end
|
755
158
|
```
|
756
159
|
|
757
|
-
*Eileen M. Uchitelle*, *John Crepezzi*
|
758
|
-
|
759
|
-
* Allow double-dash comment syntax when querying read-only databases
|
760
|
-
|
761
|
-
*James Adam*
|
762
|
-
|
763
|
-
* Add `values_at` method.
|
764
|
-
|
765
|
-
Returns an array containing the values associated with the given methods.
|
766
|
-
|
767
160
|
```ruby
|
768
|
-
|
769
|
-
|
770
|
-
# => ["Budget", "Jason"]
|
161
|
+
GET /books
|
162
|
+
# SELECT * FROM books /*application:MyApp;controller:books;action:index*/
|
771
163
|
```
|
772
164
|
|
773
|
-
|
774
|
-
|
775
|
-
*Guillaume Briday*
|
776
|
-
|
777
|
-
* Fix `read_attribute_before_type_cast` to consider attribute aliases.
|
778
|
-
|
779
|
-
*Marcelo Lauxen*
|
780
|
-
|
781
|
-
* Support passing record to uniqueness validator `:conditions` callable:
|
165
|
+
Custom tags containing static values and Procs can be defined in the application configuration:
|
782
166
|
|
783
167
|
```ruby
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
168
|
+
config.active_record.query_log_tags = [
|
169
|
+
:application,
|
170
|
+
:controller,
|
171
|
+
:action,
|
172
|
+
{
|
173
|
+
custom_static: "foo",
|
174
|
+
custom_dynamic: -> { Time.now }
|
788
175
|
}
|
789
|
-
|
790
|
-
```
|
791
|
-
|
792
|
-
*Eliot Sykes*
|
793
|
-
|
794
|
-
* `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
|
795
|
-
total number of rows affected, just like their non-batched counterparts.
|
796
|
-
|
797
|
-
```ruby
|
798
|
-
Person.in_batches.update_all("first_name = 'Eugene'") # => 42
|
799
|
-
Person.in_batches.delete_all # => 42
|
800
|
-
```
|
801
|
-
|
802
|
-
Fixes #40287.
|
803
|
-
|
804
|
-
*Eugene Kenny*
|
805
|
-
|
806
|
-
* Add support for PostgreSQL `interval` data type with conversion to
|
807
|
-
`ActiveSupport::Duration` when loading records from database and
|
808
|
-
serialization to ISO 8601 formatted duration string on save.
|
809
|
-
Add support to define a column in migrations and get it in a schema dump.
|
810
|
-
Optional column precision is supported.
|
811
|
-
|
812
|
-
To use this in 6.1, you need to place the next string to your model file:
|
813
|
-
|
814
|
-
attribute :duration, :interval
|
815
|
-
|
816
|
-
To keep old behavior until 7.0 is released:
|
817
|
-
|
818
|
-
attribute :duration, :string
|
819
|
-
|
820
|
-
Example:
|
821
|
-
|
822
|
-
create_table :events do |t|
|
823
|
-
t.string :name
|
824
|
-
t.interval :duration
|
825
|
-
end
|
826
|
-
|
827
|
-
class Event < ApplicationRecord
|
828
|
-
attribute :duration, :interval
|
829
|
-
end
|
830
|
-
|
831
|
-
Event.create!(name: 'Rock Fest', duration: 2.days)
|
832
|
-
Event.last.duration # => 2 days
|
833
|
-
Event.last.duration.iso8601 # => "P2D"
|
834
|
-
Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
|
835
|
-
Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
|
836
|
-
|
837
|
-
*Andrey Novikov*
|
838
|
-
|
839
|
-
* Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
|
840
|
-
|
841
|
-
```ruby
|
842
|
-
class Account < ActiveRecord::Base
|
843
|
-
belongs_to :supplier, dependent: :destroy_async
|
844
|
-
end
|
845
|
-
```
|
846
|
-
|
847
|
-
`:destroy_async` will enqueue a job to destroy associated records in the background.
|
848
|
-
|
849
|
-
*DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
|
850
|
-
|
851
|
-
* Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
|
852
|
-
|
853
|
-
*Jason Schweier*
|
854
|
-
|
855
|
-
* `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
|
856
|
-
|
857
|
-
Ensure that `connects_to` can only be called from `ActiveRecord::Base` or abstract classes. This protects the application from opening duplicate or too many connections.
|
858
|
-
|
859
|
-
*Eileen M. Uchitelle*, *John Crepezzi*
|
860
|
-
|
861
|
-
* All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
862
|
-
`ActiveRecord::StatementInvalid` when they encounter a connection error.
|
863
|
-
|
864
|
-
*Jean Boussier*
|
865
|
-
|
866
|
-
* `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
867
|
-
`ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
|
868
|
-
|
869
|
-
*Jean Boussier*
|
870
|
-
|
871
|
-
* Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
|
872
|
-
|
873
|
-
*Alex Robbin*
|
874
|
-
|
875
|
-
* Ensure the default configuration is considered primary or first for an environment
|
876
|
-
|
877
|
-
If a multiple database application provides a configuration named primary, that will be treated as default. In applications that do not have a primary entry, the default database configuration will be the first configuration for an environment.
|
878
|
-
|
879
|
-
*Eileen M. Uchitelle*
|
880
|
-
|
881
|
-
* Allow `where` references association names as joined table name aliases.
|
882
|
-
|
883
|
-
```ruby
|
884
|
-
class Comment < ActiveRecord::Base
|
885
|
-
enum label: [:default, :child]
|
886
|
-
has_many :children, class_name: "Comment", foreign_key: :parent_id
|
887
|
-
end
|
888
|
-
|
889
|
-
# ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1
|
890
|
-
Comment.includes(:children).where("children.label": "child")
|
176
|
+
]
|
891
177
|
```
|
892
178
|
|
893
|
-
*
|
179
|
+
*Keeran Raj Hawoldar*, *Eileen M. Uchitelle*, *Kasper Timm Hansen*
|
894
180
|
|
895
|
-
*
|
181
|
+
* Added support for multiple databases to `rails db:setup` and `rails db:reset`.
|
896
182
|
|
897
|
-
|
898
|
-
by `store_full_sti_class` class attribute.
|
183
|
+
*Ryan Hall*
|
899
184
|
|
900
|
-
|
185
|
+
* Add `ActiveRecord::Relation#structurally_compatible?`.
|
901
186
|
|
902
|
-
|
187
|
+
Adds a query method by which a user can tell if the relation that they're
|
188
|
+
about to use for `#or` or `#and` is structurally compatible with the
|
189
|
+
receiver.
|
903
190
|
|
904
|
-
*
|
905
|
-
`rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
|
906
|
-
depending on `config.active_record.schema_format` configuration value.
|
191
|
+
*Kevin Newton*
|
907
192
|
|
908
|
-
|
193
|
+
* Add `ActiveRecord::QueryMethods#in_order_of`.
|
909
194
|
|
910
|
-
|
195
|
+
This allows you to specify an explicit order that you'd like records
|
196
|
+
returned in based on a SQL expression. By default, this will be accomplished
|
197
|
+
using a case statement, as in:
|
911
198
|
|
912
199
|
```ruby
|
913
|
-
|
914
|
-
post.title # => "WELCOME TO THE WEBLOG"
|
915
|
-
post.body # => ActiveModel::MissingAttributeError
|
916
|
-
|
917
|
-
# Rails 6.0 (ignore the `select` values)
|
918
|
-
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
919
|
-
post.title # => "Welcome to the weblog"
|
920
|
-
post.body # => "Such a lovely day"
|
921
|
-
|
922
|
-
# Rails 6.1 (respect the `select` values)
|
923
|
-
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
924
|
-
post.title # => "WELCOME TO THE WEBLOG"
|
925
|
-
post.body # => ActiveModel::MissingAttributeError
|
200
|
+
Post.in_order_of(:id, [3, 5, 1])
|
926
201
|
```
|
927
202
|
|
928
|
-
|
929
|
-
|
930
|
-
* Allow attribute's default to be configured but keeping its own type.
|
203
|
+
will generate the SQL:
|
931
204
|
|
932
|
-
```
|
933
|
-
|
934
|
-
attribute :written_at, default: -> { Time.now.utc }
|
935
|
-
end
|
936
|
-
|
937
|
-
# Rails 6.0
|
938
|
-
Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
|
939
|
-
|
940
|
-
# Rails 6.1
|
941
|
-
Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
|
205
|
+
```sql
|
206
|
+
SELECT "posts".* FROM "posts" ORDER BY CASE "posts"."id" WHEN 3 THEN 1 WHEN 5 THEN 2 WHEN 1 THEN 3 ELSE 4 END ASC
|
942
207
|
```
|
943
208
|
|
944
|
-
|
945
|
-
|
946
|
-
|
209
|
+
However, because this functionality is built into MySQL in the form of the
|
210
|
+
`FIELD` function, that connection adapter will generate the following SQL
|
211
|
+
instead:
|
947
212
|
|
948
|
-
```
|
949
|
-
|
950
|
-
enum status: [:proposed, :written, :published], _default: :published
|
951
|
-
end
|
952
|
-
|
953
|
-
Book.new.status # => "published"
|
213
|
+
```sql
|
214
|
+
SELECT "posts".* FROM "posts" ORDER BY FIELD("posts"."id", 1, 5, 3) DESC
|
954
215
|
```
|
955
216
|
|
956
|
-
*
|
957
|
-
|
958
|
-
* Deprecate YAML loading from legacy format older than Rails 5.0.
|
217
|
+
*Kevin Newton*
|
959
218
|
|
960
|
-
|
219
|
+
* Fix `eager_loading?` when ordering with `Symbol`.
|
961
220
|
|
962
|
-
|
963
|
-
allows you to specify that all string columns should be frozen unless
|
964
|
-
otherwise specified. This will reduce memory pressure for applications which
|
965
|
-
do not generally mutate string properties of Active Record objects.
|
966
|
-
|
967
|
-
*Sean Griffin*, *Ryuta Kamizono*
|
968
|
-
|
969
|
-
* Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
|
970
|
-
|
971
|
-
*Ryuta Kamizono*
|
972
|
-
|
973
|
-
* Support `relation.and` for intersection as Set theory.
|
221
|
+
`eager_loading?` is triggered correctly when using `order` with symbols.
|
974
222
|
|
975
223
|
```ruby
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
david_and_mary.merge(mary_and_bob) # => [mary, bob]
|
980
|
-
|
981
|
-
david_and_mary.and(mary_and_bob) # => [mary]
|
982
|
-
david_and_mary.or(mary_and_bob) # => [david, mary, bob]
|
224
|
+
scope = Post.includes(:comments).order(:"comments.label")
|
225
|
+
=> true
|
983
226
|
```
|
984
227
|
|
985
|
-
*
|
986
|
-
|
987
|
-
* Merging conditions on the same column no longer maintain both conditions,
|
988
|
-
and will be consistently replaced by the latter condition in Rails 7.0.
|
989
|
-
To migrate to Rails 7.0's behavior, use `relation.merge(other, rewhere: true)`.
|
990
|
-
|
991
|
-
```ruby
|
992
|
-
# Rails 6.1 (IN clause is replaced by merger side equality condition)
|
993
|
-
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
994
|
-
|
995
|
-
# Rails 6.1 (both conflict conditions exists, deprecated)
|
996
|
-
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
|
997
|
-
|
998
|
-
# Rails 6.1 with rewhere to migrate to Rails 7.0's behavior
|
999
|
-
Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
|
1000
|
-
|
1001
|
-
# Rails 7.0 (same behavior with IN clause, mergee side condition is consistently replaced)
|
1002
|
-
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
1003
|
-
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
|
1004
|
-
```
|
1005
|
-
|
1006
|
-
*Ryuta Kamizono*
|
1007
|
-
|
1008
|
-
* Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
|
1009
|
-
|
1010
|
-
*Peter Fry*
|
1011
|
-
|
1012
|
-
* Resolve issue with insert_all unique_by option when used with expression index.
|
1013
|
-
|
1014
|
-
When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
|
1015
|
-
`ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
|
1016
|
-
was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
|
228
|
+
*Jacopo Beschi*
|
1017
229
|
|
1018
|
-
|
230
|
+
* Two change tracking methods are added for `belongs_to` associations.
|
1019
231
|
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
t.index "lower(name)", unique: true
|
1024
|
-
end
|
232
|
+
The `association_changed?` method (assuming an association named `:association`) returns true
|
233
|
+
if a different associated object has been assigned and the foreign key will be updated in the
|
234
|
+
next save.
|
1025
235
|
|
1026
|
-
|
1027
|
-
|
236
|
+
The `association_previously_changed?` method returns true if the previous save updated the
|
237
|
+
association to reference a different associated object.
|
1028
238
|
|
1029
|
-
|
239
|
+
*George Claghorn*
|
1030
240
|
|
1031
|
-
|
241
|
+
* Add option to disable schema dump per-database.
|
1032
242
|
|
1033
|
-
|
243
|
+
Dumping the schema is on by default for all databases in an application. To turn it off for a
|
244
|
+
specific database use the `schema_dump` option:
|
1034
245
|
|
1035
|
-
|
246
|
+
```yaml
|
247
|
+
# config/database.yml
|
1036
248
|
|
1037
|
-
|
1038
|
-
|
1039
|
-
remove_check_constraint :products, name: "price_check"
|
249
|
+
production:
|
250
|
+
schema_dump: false
|
1040
251
|
```
|
1041
252
|
|
1042
|
-
*
|
253
|
+
*Luis Vasconcellos*, *Eileen M. Uchitelle*
|
1043
254
|
|
1044
|
-
*
|
1045
|
-
to enable/disable strict_loading mode by default for a model. The configuration's value is
|
1046
|
-
inheritable by subclasses, but they can override that value and it will not impact parent class.
|
255
|
+
* Fix `eager_loading?` when ordering with `Hash` syntax.
|
1047
256
|
|
1048
|
-
|
257
|
+
`eager_loading?` is triggered correctly when using `order` with hash syntax
|
258
|
+
on an outer table.
|
1049
259
|
|
1050
260
|
```ruby
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
has_many :projects
|
1055
|
-
end
|
1056
|
-
|
1057
|
-
dev = Developer.first
|
1058
|
-
dev.projects.first
|
1059
|
-
# => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
|
261
|
+
Post.includes(:comments).order({ "comments.label": :ASC }).eager_loading?
|
262
|
+
# => true
|
1060
263
|
```
|
1061
264
|
|
1062
|
-
*
|
1063
|
-
|
1064
|
-
* Deprecate passing an Active Record object to `quote`/`type_cast` directly.
|
265
|
+
*Jacopo Beschi*
|
1065
266
|
|
1066
|
-
|
267
|
+
* Move the forcing of clear text encoding to the `ActiveRecord::Encryption::Encryptor`.
|
1067
268
|
|
1068
|
-
|
269
|
+
Fixes #42699.
|
1069
270
|
|
1070
|
-
|
271
|
+
*J Smith*
|
1071
272
|
|
1072
|
-
|
1073
|
-
create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
|
1074
|
-
end
|
1075
|
-
```
|
273
|
+
* `partial_inserts` is now disabled by default in new apps.
|
1076
274
|
|
1077
|
-
|
275
|
+
This will be the default for new apps in Rails 7. To opt in:
|
1078
276
|
|
1079
277
|
```ruby
|
1080
|
-
|
1081
|
-
end
|
278
|
+
config.active_record.partial_inserts = true
|
1082
279
|
```
|
1083
280
|
|
1084
|
-
|
281
|
+
If a migration remove the default value of a column, this option
|
282
|
+
would cause old processes to no longer be able to create new records.
|
1085
283
|
|
1086
|
-
|
1087
|
-
|
284
|
+
If you need to remove a column, you should first use `ignored_columns`
|
285
|
+
to stop using it.
|
1088
286
|
|
1089
|
-
*
|
287
|
+
*Jean Boussier*
|
1090
288
|
|
1091
|
-
*
|
289
|
+
* Rails can now verify foreign keys after loading fixtures in tests.
|
1092
290
|
|
1093
|
-
|
291
|
+
This will be the default for new apps in Rails 7. To opt in:
|
1094
292
|
|
1095
293
|
```ruby
|
1096
|
-
|
1097
|
-
|
1098
|
-
# duplicated group fields, deprecated.
|
1099
|
-
accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
|
1100
|
-
# => {
|
1101
|
-
# [1, 1] => 50,
|
1102
|
-
# [2, 2] => 60
|
1103
|
-
# }
|
1104
|
-
|
1105
|
-
# use `uniq!(:group)` to deduplicate group fields.
|
1106
|
-
accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
|
1107
|
-
# => {
|
1108
|
-
# 1 => 50,
|
1109
|
-
# 2 => 60
|
1110
|
-
# }
|
294
|
+
config.active_record.verify_foreign_keys_for_fixtures = true
|
1111
295
|
```
|
1112
296
|
|
1113
|
-
|
297
|
+
Tests will not run if there is a foreign key constraint violation in your fixture data.
|
1114
298
|
|
1115
|
-
|
299
|
+
The feature is supported by SQLite and PostgreSQL, other adapters can also add support for it.
|
1116
300
|
|
1117
|
-
|
301
|
+
*Alex Ghiculescu*
|
1118
302
|
|
1119
|
-
|
1120
|
-
accounts = Account.where(id: [1, 2]).annotate("david and mary")
|
303
|
+
* Clear cached `has_one` association after setting `belongs_to` association to `nil`.
|
1121
304
|
|
1122
|
-
|
1123
|
-
|
1124
|
-
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
|
305
|
+
After setting a `belongs_to` relation to `nil` and updating an unrelated attribute on the owner,
|
306
|
+
the owner should still return `nil` on the `has_one` relation.
|
1125
307
|
|
1126
|
-
#
|
1127
|
-
accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
|
1128
|
-
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
|
1129
|
-
```
|
308
|
+
Fixes #42597.
|
1130
309
|
|
1131
|
-
*
|
310
|
+
*Michiel de Mare*
|
1132
311
|
|
1133
|
-
*
|
312
|
+
* OpenSSL constants are now used for Digest computations.
|
1134
313
|
|
1135
|
-
|
1136
|
-
cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
|
1137
|
-
upon subsequent transactions by maintaining parity with the corresponding
|
1138
|
-
database record's `lock_version` column.
|
314
|
+
*Dirkjan Bussink*
|
1139
315
|
|
1140
|
-
|
316
|
+
* Adds support for `if_not_exists` to `add_foreign_key` and `if_exists` to `remove_foreign_key`.
|
1141
317
|
|
1142
|
-
|
318
|
+
Applications can set their migrations to ignore exceptions raised when adding a foreign key
|
319
|
+
that already exists or when removing a foreign key that does not exist.
|
1143
320
|
|
1144
|
-
|
321
|
+
Example Usage:
|
1145
322
|
|
1146
323
|
```ruby
|
1147
|
-
|
324
|
+
class AddAuthorsForeignKeyToArticles < ActiveRecord::Migration[7.0]
|
325
|
+
def change
|
326
|
+
add_foreign_key :articles, :authors, if_not_exists: true
|
327
|
+
end
|
328
|
+
end
|
329
|
+
```
|
1148
330
|
|
1149
|
-
|
1150
|
-
|
331
|
+
```ruby
|
332
|
+
class RemoveAuthorsForeignKeyFromArticles < ActiveRecord::Migration[7.0]
|
333
|
+
def change
|
334
|
+
remove_foreign_key :articles, :authors, if_exists: true
|
335
|
+
end
|
336
|
+
end
|
337
|
+
```
|
1151
338
|
|
1152
|
-
|
1153
|
-
david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
|
339
|
+
*Roberto Miranda*
|
1154
340
|
|
1155
|
-
|
1156
|
-
david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
|
1157
|
-
```
|
341
|
+
* Prevent polluting ENV during postgresql structure dump/load.
|
1158
342
|
|
1159
|
-
|
343
|
+
Some configuration parameters were provided to pg_dump / psql via
|
344
|
+
environment variables which persisted beyond the command being run, and may
|
345
|
+
have caused subsequent commands and connections to fail. Tasks running
|
346
|
+
across multiple postgresql databases like `rails db:test:prepare` may have
|
347
|
+
been affected.
|
1160
348
|
|
1161
|
-
*
|
1162
|
-
set to expire and scoped with a purpose. This is particularly useful for things like password reset
|
1163
|
-
or email verification, where you want the bearer of the signed id to be able to interact with the
|
1164
|
-
underlying record, but usually only within a certain time period.
|
349
|
+
*Samuel Cochran*
|
1165
350
|
|
1166
|
-
|
1167
|
-
signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
|
351
|
+
* Set precision 6 by default for `datetime` columns.
|
1168
352
|
|
1169
|
-
|
353
|
+
By default, datetime columns will have microseconds precision instead of seconds precision.
|
1170
354
|
|
1171
|
-
|
1172
|
-
User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
|
355
|
+
*Roberto Miranda*
|
1173
356
|
|
1174
|
-
|
1175
|
-
User.find_signed signed_id, purpose: :password_reset # => User.first
|
357
|
+
* Allow preloading of associations with instance dependent scopes.
|
1176
358
|
|
1177
|
-
|
1178
|
-
```
|
359
|
+
*John Hawthorn*, *John Crepezzi*, *Adam Hess*, *Eileen M. Uchitelle*, *Dinah Shi*
|
1179
360
|
|
1180
|
-
|
361
|
+
* Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
|
1181
362
|
|
1182
|
-
*
|
363
|
+
*Jamie McCarthy*
|
1183
364
|
|
1184
|
-
|
365
|
+
* Active Record Encryption will now encode values as UTF-8 when using deterministic
|
366
|
+
encryption. The encoding is part of the encrypted payload, so different encodings for
|
367
|
+
different values result in different ciphertexts. This can break unique constraints and
|
368
|
+
queries.
|
1185
369
|
|
1186
|
-
|
370
|
+
The new behavior is configurable via `active_record.encryption.forced_encoding_for_deterministic_encryption`
|
371
|
+
that is `Encoding::UTF_8` by default. It can be disabled by setting it to `nil`.
|
1187
372
|
|
1188
|
-
*
|
373
|
+
*Jorge Manrubia*
|
1189
374
|
|
1190
|
-
*
|
375
|
+
* The MySQL adapter now cast numbers and booleans bind parameters to string for safety reasons.
|
1191
376
|
|
1192
|
-
|
377
|
+
When comparing a string and a number in a query, MySQL converts the string to a number. So for
|
378
|
+
instance `"foo" = 0`, will implicitly cast `"foo"` to `0` and will evaluate to `TRUE` which can
|
379
|
+
lead to security vulnerabilities.
|
1193
380
|
|
1194
|
-
|
1195
|
-
|
1196
|
-
posts = posts.where("posts.hidden": false, "comments.hidden": false)
|
381
|
+
Active Record already protect against that vulnerability when it knows the type of the column
|
382
|
+
being compared, however until now it was still vulnerable when using bind parameters:
|
1197
383
|
|
1198
|
-
|
1199
|
-
|
384
|
+
```ruby
|
385
|
+
User.where("login_token = ?", 0).first
|
386
|
+
```
|
1200
387
|
|
1201
|
-
|
1202
|
-
posts.unscope(where: :hidden).count
|
1203
|
-
# => { false => 11, true => 1 }
|
388
|
+
Would perform:
|
1204
389
|
|
1205
|
-
|
1206
|
-
|
1207
|
-
# => { false => 11 }
|
390
|
+
```sql
|
391
|
+
SELECT * FROM `users` WHERE `login_token` = 0 LIMIT 1;
|
1208
392
|
```
|
1209
393
|
|
1210
|
-
|
394
|
+
Now it will perform:
|
1211
395
|
|
1212
|
-
|
396
|
+
```sql
|
397
|
+
SELECT * FROM `users` WHERE `login_token` = '0' LIMIT 1;
|
398
|
+
```
|
1213
399
|
|
1214
|
-
|
1215
|
-
steve = Person.find_by(name: "Steve")
|
1216
|
-
david = Author.find_by(name: "David")
|
400
|
+
*Jean Boussier*
|
1217
401
|
|
1218
|
-
|
402
|
+
* Fixture configurations (`_fixture`) are now strictly validated.
|
1219
403
|
|
1220
|
-
|
1221
|
-
|
404
|
+
If an error will be raised if that entry contains unknown keys while previously it
|
405
|
+
would silently have no effects.
|
1222
406
|
|
1223
|
-
|
1224
|
-
relation.rewhere(writer: david).to_a # => [david]
|
1225
|
-
```
|
407
|
+
*Jean Boussier*
|
1226
408
|
|
1227
|
-
|
409
|
+
* Add `ActiveRecord::Base.update!` that works like `ActiveRecord::Base.update` but raises exceptions.
|
1228
410
|
|
1229
|
-
|
411
|
+
This allows for the same behavior as the instance method `#update!` at a class level.
|
1230
412
|
|
1231
413
|
```ruby
|
1232
|
-
|
1233
|
-
=> #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
|
414
|
+
Person.update!(:all, state: "confirmed")
|
1234
415
|
```
|
1235
416
|
|
1236
|
-
*
|
417
|
+
*Dorian Marié*
|
1237
418
|
|
1238
|
-
*
|
419
|
+
* Add `ActiveRecord::Base#attributes_for_database`.
|
1239
420
|
|
1240
|
-
|
421
|
+
Returns attributes with values for assignment to the database.
|
1241
422
|
|
1242
|
-
*
|
423
|
+
*Chris Salzberg*
|
1243
424
|
|
1244
|
-
|
425
|
+
* Use an empty query to check if the PostgreSQL connection is still active.
|
1245
426
|
|
1246
|
-
|
427
|
+
An empty query is faster than `SELECT 1`.
|
1247
428
|
|
1248
|
-
*
|
429
|
+
*Heinrich Lee Yu*
|
1249
430
|
|
1250
|
-
*
|
431
|
+
* Add `ActiveRecord::Base#previously_persisted?`.
|
1251
432
|
|
1252
|
-
|
433
|
+
Returns `true` if the object has been previously persisted but now it has been deleted.
|
1253
434
|
|
1254
|
-
*
|
435
|
+
* Deprecate `partial_writes` in favor of `partial_inserts` and `partial_updates`.
|
1255
436
|
|
1256
|
-
|
437
|
+
This allows to have a different behavior on update and create.
|
1257
438
|
|
1258
|
-
*
|
439
|
+
*Jean Boussier*
|
1259
440
|
|
1260
|
-
*
|
441
|
+
* Fix compatibility with `psych >= 4`.
|
1261
442
|
|
1262
|
-
|
443
|
+
Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load`. To preserve compatibility
|
444
|
+
Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
|
1263
445
|
|
1264
|
-
*
|
446
|
+
*Jean Boussier*
|
1265
447
|
|
1266
|
-
|
448
|
+
* `ActiveRecord::Base.logger` is now a `class_attribute`.
|
1267
449
|
|
1268
|
-
|
450
|
+
This means it can no longer be accessed directly through `@@logger`, and that setting `logger =`
|
451
|
+
on a subclass won't change the parent's logger.
|
1269
452
|
|
1270
|
-
*
|
453
|
+
*Jean Boussier*
|
1271
454
|
|
1272
|
-
|
1273
|
-
index won't be added.
|
455
|
+
* Add `.asc.nulls_first` for all databases. Unfortunately MySQL still doesn't like `nulls_last`.
|
1274
456
|
|
1275
|
-
|
457
|
+
*Keenan Brock*
|
1276
458
|
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
459
|
+
* Improve performance of `one?` and `many?` by limiting the generated count query to 2 results.
|
460
|
+
|
461
|
+
*Gonzalo Riestra*
|
462
|
+
|
463
|
+
* Don't check type when using `if_not_exists` on `add_column`.
|
464
|
+
|
465
|
+
Previously, if a migration called `add_column` with the `if_not_exists` option set to true
|
466
|
+
the `column_exists?` check would look for a column with the same name and type as the migration.
|
1280
467
|
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
468
|
+
Recently it was discovered that the type passed to the migration is not always the same type
|
469
|
+
as the column after migration. For example a column set to `:mediumblob` in the migration will
|
470
|
+
be casted to `binary` when calling `column.type`. Since there is no straightforward way to cast
|
471
|
+
the type to the database type without running the migration, we opted to drop the type check from
|
472
|
+
`add_column`. This means that migrations adding a duplicate column with a different type will no
|
473
|
+
longer raise an error.
|
1284
474
|
|
1285
|
-
*
|
475
|
+
*Eileen M. Uchitelle*
|
476
|
+
|
477
|
+
* Log a warning message when running SQLite in production.
|
1286
478
|
|
1287
|
-
|
479
|
+
Using SQLite in production ENV is generally discouraged. SQLite is also the default adapter
|
480
|
+
in a new Rails application.
|
481
|
+
For the above reasons log a warning message when running SQLite in production.
|
1288
482
|
|
1289
|
-
|
483
|
+
The warning can be disabled by setting `config.active_record.sqlite3_production_warning=false`.
|
1290
484
|
|
1291
|
-
*
|
485
|
+
*Jacopo Beschi*
|
1292
486
|
|
1293
|
-
|
487
|
+
* Add option to disable joins for `has_one` associations.
|
1294
488
|
|
1295
|
-
|
489
|
+
In a multiple database application, associations can't join across
|
490
|
+
databases. When set, this option instructs Rails to generate 2 or
|
491
|
+
more queries rather than generating joins for `has_one` associations.
|
1296
492
|
|
1297
|
-
|
493
|
+
Set the option on a has one through association:
|
1298
494
|
|
1299
495
|
```ruby
|
1300
|
-
Person
|
1301
|
-
|
496
|
+
class Person
|
497
|
+
belongs_to :dog
|
498
|
+
has_one :veterinarian, through: :dog, disable_joins: true
|
1302
499
|
end
|
1303
500
|
```
|
1304
501
|
|
1305
|
-
|
502
|
+
Then instead of generating join SQL, two queries are used for `@person.veterinarian`:
|
503
|
+
|
504
|
+
```
|
505
|
+
SELECT "dogs"."id" FROM "dogs" WHERE "dogs"."person_id" = ? [["person_id", 1]]
|
506
|
+
SELECT "veterinarians".* FROM "veterinarians" WHERE "veterinarians"."dog_id" = ? [["dog_id", 1]]
|
507
|
+
```
|
1306
508
|
|
1307
|
-
*
|
509
|
+
*Sarah Vessels*, *Eileen M. Uchitelle*
|
1308
510
|
|
1309
|
-
|
511
|
+
* `Arel::Visitors::Dot` now renders a complete set of properties when visiting
|
512
|
+
`Arel::Nodes::SelectCore`, `SelectStatement`, `InsertStatement`, `UpdateStatement`, and
|
513
|
+
`DeleteStatement`, which fixes #42026. Previously, some properties were omitted.
|
1310
514
|
|
1311
|
-
*
|
515
|
+
*Mike Dalessio*
|
1312
516
|
|
1313
|
-
*
|
517
|
+
* `Arel::Visitors::Dot` now supports `Arel::Nodes::Bin`, `Case`, `CurrentRow`, `Distinct`,
|
518
|
+
`DistinctOn`, `Else`, `Except`, `InfixOperation`, `Intersect`, `Lock`, `NotRegexp`, `Quoted`,
|
519
|
+
`Regexp`, `UnaryOperation`, `Union`, `UnionAll`, `When`, and `With`. Previously, these node
|
520
|
+
types caused an exception to be raised by `Arel::Visitors::Dot#accept`.
|
1314
521
|
|
1315
|
-
|
522
|
+
*Mike Dalessio*
|
1316
523
|
|
1317
|
-
|
524
|
+
* Optimize `remove_columns` to use a single SQL statement.
|
1318
525
|
|
1319
|
-
|
526
|
+
```ruby
|
527
|
+
remove_columns :my_table, :col_one, :col_two
|
528
|
+
```
|
1320
529
|
|
1321
|
-
|
530
|
+
Now results in the following SQL:
|
1322
531
|
|
1323
|
-
|
532
|
+
```sql
|
533
|
+
ALTER TABLE "my_table" DROP COLUMN "col_one", DROP COLUMN "col_two"
|
534
|
+
```
|
1324
535
|
|
1325
|
-
*
|
536
|
+
*Jon Dufresne*
|
1326
537
|
|
1327
|
-
*
|
538
|
+
* Ensure `has_one` autosave association callbacks get called once.
|
1328
539
|
|
1329
|
-
|
540
|
+
Change the `has_one` autosave callback to be non cyclic as well.
|
541
|
+
By doing this the autosave callback are made more consistent for
|
542
|
+
all 3 cases: `has_many`, `has_one`, and `belongs_to`.
|
1330
543
|
|
1331
|
-
|
544
|
+
*Petrik de Heus*
|
1332
545
|
|
1333
|
-
|
546
|
+
* Add option to disable joins for associations.
|
1334
547
|
|
1335
|
-
|
548
|
+
In a multiple database application, associations can't join across
|
549
|
+
databases. When set, this option instructs Rails to generate 2 or
|
550
|
+
more queries rather than generating joins for associations.
|
1336
551
|
|
1337
|
-
|
552
|
+
Set the option on a has many through association:
|
1338
553
|
|
1339
|
-
|
554
|
+
```ruby
|
555
|
+
class Dog
|
556
|
+
has_many :treats, through: :humans, disable_joins: true
|
557
|
+
has_many :humans
|
558
|
+
end
|
559
|
+
```
|
1340
560
|
|
1341
|
-
|
561
|
+
Then instead of generating join SQL, two queries are used for `@dog.treats`:
|
1342
562
|
|
1343
|
-
|
563
|
+
```
|
564
|
+
SELECT "humans"."id" FROM "humans" WHERE "humans"."dog_id" = ? [["dog_id", 1]]
|
565
|
+
SELECT "treats".* FROM "treats" WHERE "treats"."human_id" IN (?, ?, ?) [["human_id", 1], ["human_id", 2], ["human_id", 3]]
|
566
|
+
```
|
1344
567
|
|
1345
|
-
*Eileen M. Uchitelle*, *
|
568
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*, *Lee Quarella*
|
1346
569
|
|
1347
|
-
* Add
|
570
|
+
* Add setting for enumerating column names in SELECT statements.
|
1348
571
|
|
1349
|
-
|
572
|
+
Adding a column to a PostgreSQL database, for example, while the application is running can
|
573
|
+
change the result of wildcard `SELECT *` queries, which invalidates the result
|
574
|
+
of cached prepared statements and raises a `PreparedStatementCacheExpired` error.
|
1350
575
|
|
1351
|
-
|
576
|
+
When enabled, Active Record will avoid wildcards and always include column names
|
577
|
+
in `SELECT` queries, which will return consistent results and avoid prepared
|
578
|
+
statement errors.
|
1352
579
|
|
1353
|
-
|
580
|
+
Before:
|
1354
581
|
|
1355
|
-
```
|
1356
|
-
|
1357
|
-
|
1358
|
-
primary:
|
1359
|
-
database: my_database
|
1360
|
-
primary_shard_one:
|
1361
|
-
database: my_database_shard_one
|
582
|
+
```ruby
|
583
|
+
Book.limit(5)
|
584
|
+
# SELECT * FROM books LIMIT 5
|
1362
585
|
```
|
1363
586
|
|
1364
|
-
|
587
|
+
After:
|
1365
588
|
|
1366
589
|
```ruby
|
1367
|
-
|
1368
|
-
|
590
|
+
# config/application.rb
|
591
|
+
module MyApp
|
592
|
+
class Application < Rails::Application
|
593
|
+
config.active_record.enumerate_columns_in_select_statements = true
|
594
|
+
end
|
595
|
+
end
|
1369
596
|
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
597
|
+
# or, configure per-model
|
598
|
+
class Book < ApplicationRecord
|
599
|
+
self.enumerate_columns_in_select_statements = true
|
600
|
+
end
|
1374
601
|
```
|
1375
602
|
|
1376
|
-
Swap between shards in your controller / model code:
|
1377
|
-
|
1378
603
|
```ruby
|
1379
|
-
|
1380
|
-
|
1381
|
-
end
|
604
|
+
Book.limit(5)
|
605
|
+
# SELECT id, author_id, name, format, status, language, etc FROM books LIMIT 5
|
1382
606
|
```
|
1383
607
|
|
1384
|
-
|
608
|
+
*Matt Duszynski*
|
1385
609
|
|
1386
|
-
|
610
|
+
* Allow passing SQL as `on_duplicate` value to `#upsert_all` to make it possible to use raw SQL to update columns on conflict:
|
1387
611
|
|
1388
|
-
|
612
|
+
```ruby
|
613
|
+
Book.upsert_all(
|
614
|
+
[{ id: 1, status: 1 }, { id: 2, status: 1 }],
|
615
|
+
on_duplicate: Arel.sql("status = GREATEST(books.status, EXCLUDED.status)")
|
616
|
+
)
|
617
|
+
```
|
1389
618
|
|
1390
|
-
|
619
|
+
*Vladimir Dementyev*
|
1391
620
|
|
1392
|
-
|
621
|
+
* Allow passing SQL as `returning` statement to `#upsert_all`:
|
1393
622
|
|
1394
623
|
```ruby
|
1395
|
-
|
1396
|
-
|
624
|
+
Article.insert_all(
|
625
|
+
[
|
626
|
+
{ title: "Article 1", slug: "article-1", published: false },
|
627
|
+
{ title: "Article 2", slug: "article-2", published: false }
|
628
|
+
],
|
629
|
+
returning: Arel.sql("id, (xmax = '0') as inserted, name as new_name")
|
630
|
+
)
|
1397
631
|
```
|
1398
632
|
|
1399
|
-
|
633
|
+
*Vladimir Dementyev*
|
1400
634
|
|
1401
|
-
|
1402
|
-
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary")
|
1403
|
-
db_config.name
|
1404
|
-
```
|
635
|
+
* Deprecate `legacy_connection_handling`.
|
1405
636
|
|
1406
637
|
*Eileen M. Uchitelle*
|
1407
638
|
|
1408
|
-
* Add
|
639
|
+
* Add attribute encryption support.
|
1409
640
|
|
1410
|
-
|
1411
|
-
|
641
|
+
Encrypted attributes are declared at the model level. These
|
642
|
+
are regular Active Record attributes backed by a column with
|
643
|
+
the same name. The system will transparently encrypt these
|
644
|
+
attributes before saving them into the database and will
|
645
|
+
decrypt them when retrieving their values.
|
1412
646
|
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
rails db:drop:animals
|
1420
|
-
rails db:migrate
|
1421
|
-
rails db:migrate:primary
|
1422
|
-
rails db:migrate:animals
|
647
|
+
|
648
|
+
```ruby
|
649
|
+
class Person < ApplicationRecord
|
650
|
+
encrypts :name
|
651
|
+
encrypts :email_address, deterministic: true
|
652
|
+
end
|
1423
653
|
```
|
1424
654
|
|
1425
|
-
|
1426
|
-
|
655
|
+
You can learn more in the [Active Record Encryption
|
656
|
+
guide](https://edgeguides.rubyonrails.org/active_record_encryption.html).
|
1427
657
|
|
1428
|
-
|
1429
|
-
rails db:schema:dump
|
1430
|
-
rails db:schema:dump:primary
|
1431
|
-
rails db:schema:dump:animals
|
1432
|
-
rails db:schema:load
|
1433
|
-
rails db:schema:load:primary
|
1434
|
-
rails db:schema:load:animals
|
1435
|
-
rails db:structure:dump
|
1436
|
-
rails db:structure:dump:primary
|
1437
|
-
rails db:structure:dump:animals
|
1438
|
-
rails db:structure:load
|
1439
|
-
rails db:structure:load:primary
|
1440
|
-
rails db:structure:load:animals
|
1441
|
-
rails db:test:prepare
|
1442
|
-
rails db:test:prepare:primary
|
1443
|
-
rails db:test:prepare:animals
|
1444
|
-
```
|
658
|
+
*Jorge Manrubia*
|
1445
659
|
|
1446
|
-
|
660
|
+
* Changed Arel predications `contains` and `overlaps` to use
|
661
|
+
`quoted_node` so that PostgreSQL arrays are quoted properly.
|
1447
662
|
|
1448
|
-
*
|
663
|
+
*Bradley Priest*
|
1449
664
|
|
1450
|
-
|
665
|
+
* Add mode argument to record level `strict_loading!`.
|
1451
666
|
|
1452
|
-
|
667
|
+
This argument can be used when enabling strict loading for a single record
|
668
|
+
to specify that we only want to raise on n plus one queries.
|
1453
669
|
|
1454
670
|
```ruby
|
1455
|
-
|
1456
|
-
has_many :projects, strict_loading: true
|
1457
|
-
end
|
671
|
+
developer.strict_loading!(mode: :n_plus_one_only)
|
1458
672
|
|
1459
|
-
|
1460
|
-
|
1461
|
-
# => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
|
673
|
+
developer.projects.to_a # Does not raise
|
674
|
+
developer.projects.first.client # Raises StrictLoadingViolationError
|
1462
675
|
```
|
1463
676
|
|
1464
|
-
|
677
|
+
Previously, enabling strict loading would cause any lazily loaded
|
678
|
+
association to raise an error. Using `n_plus_one_only` mode allows us to
|
679
|
+
lazily load belongs_to, has_many, and other associations that are fetched
|
680
|
+
through a single query.
|
1465
681
|
|
1466
|
-
*
|
682
|
+
*Dinah Shi*
|
1467
683
|
|
1468
|
-
|
684
|
+
* Fix Float::INFINITY assignment to datetime column with postgresql adapter.
|
1469
685
|
|
1470
|
-
|
686
|
+
Before:
|
1471
687
|
|
1472
688
|
```ruby
|
1473
|
-
|
1474
|
-
|
1475
|
-
# => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
|
1476
|
-
```
|
689
|
+
# With this config
|
690
|
+
ActiveRecord::Base.time_zone_aware_attributes = true
|
1477
691
|
|
1478
|
-
|
692
|
+
# and the following schema:
|
693
|
+
create_table "postgresql_infinities" do |t|
|
694
|
+
t.datetime "datetime"
|
695
|
+
end
|
1479
696
|
|
1480
|
-
|
697
|
+
# This test fails
|
698
|
+
record = PostgresqlInfinity.create!(datetime: Float::INFINITY)
|
699
|
+
assert_equal Float::INFINITY, record.datetime # record.datetime gets nil
|
700
|
+
```
|
1481
701
|
|
1482
|
-
|
702
|
+
After this commit, `record.datetime` gets `Float::INFINITY` as expected.
|
1483
703
|
|
1484
|
-
*
|
704
|
+
*Shunichi Ikegami*
|
1485
705
|
|
1486
|
-
|
706
|
+
* Type cast enum values by the original attribute type.
|
1487
707
|
|
1488
|
-
|
708
|
+
The notable thing about this change is that unknown labels will no longer match 0 on MySQL.
|
1489
709
|
|
1490
710
|
```ruby
|
1491
|
-
class
|
1492
|
-
|
1493
|
-
add_column :posts, :title, :string, if_not_exists: true
|
1494
|
-
end
|
711
|
+
class Book < ActiveRecord::Base
|
712
|
+
enum :status, { proposed: 0, written: 1, published: 2 }
|
1495
713
|
end
|
1496
714
|
```
|
1497
715
|
|
716
|
+
Before:
|
717
|
+
|
1498
718
|
```ruby
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
719
|
+
# SELECT `books`.* FROM `books` WHERE `books`.`status` = 'prohibited' LIMIT 1
|
720
|
+
Book.find_by(status: :prohibited)
|
721
|
+
# => #<Book id: 1, status: "proposed", ...> (for mysql2 adapter)
|
722
|
+
# => ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: invalid input syntax for type integer: "prohibited" (for postgresql adapter)
|
723
|
+
# => nil (for sqlite3 adapter)
|
1504
724
|
```
|
1505
725
|
|
1506
|
-
|
1507
|
-
|
1508
|
-
* Regexp-escape table name for MS SQL Server.
|
1509
|
-
|
1510
|
-
Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
|
1511
|
-
|
1512
|
-
*Larry Reid*
|
1513
|
-
|
1514
|
-
* Store advisory locks on their own named connection.
|
726
|
+
After:
|
1515
727
|
|
1516
|
-
|
728
|
+
```ruby
|
729
|
+
# SELECT `books`.* FROM `books` WHERE `books`.`status` IS NULL LIMIT 1
|
730
|
+
Book.find_by(status: :prohibited)
|
731
|
+
# => nil (for all adapters)
|
732
|
+
```
|
1517
733
|
|
1518
|
-
|
734
|
+
*Ryuta Kamizono*
|
1519
735
|
|
1520
|
-
|
736
|
+
* Fixtures for `has_many :through` associations now load timestamps on join tables.
|
1521
737
|
|
1522
|
-
|
738
|
+
Given this fixture:
|
1523
739
|
|
1524
|
-
|
740
|
+
```yml
|
741
|
+
### monkeys.yml
|
742
|
+
george:
|
743
|
+
name: George the Monkey
|
744
|
+
fruits: apple
|
1525
745
|
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
database: blog_development
|
1530
|
-
pool: 5
|
1531
|
-
schema_cache_path: tmp/schema/main.yml
|
746
|
+
### fruits.yml
|
747
|
+
apple:
|
748
|
+
name: apple
|
1532
749
|
```
|
1533
750
|
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
751
|
+
If the join table (`fruit_monkeys`) contains `created_at` or `updated_at` columns,
|
752
|
+
these will now be populated when loading the fixture. Previously, fixture loading
|
753
|
+
would crash if these columns were required, and leave them as null otherwise.
|
1537
754
|
|
1538
|
-
|
1539
|
-
|
1540
|
-
*Eileen M. Uchitelle*, *John Crepezzi*
|
1541
|
-
|
1542
|
-
* Deprecate `#default_hash` and it's alias `#[]` on database configurations.
|
755
|
+
*Alex Ghiculescu*
|
1543
756
|
|
1544
|
-
|
757
|
+
* Allow applications to configure the thread pool for async queries.
|
1545
758
|
|
1546
|
-
|
759
|
+
Some applications may want one thread pool per database whereas others want to use
|
760
|
+
a single global thread pool for all queries. By default, Rails will set `async_query_executor`
|
761
|
+
to `nil` which will not initialize any executor. If `load_async` is called and no executor
|
762
|
+
has been configured, the query will be executed in the foreground.
|
1547
763
|
|
1548
|
-
|
764
|
+
To create one thread pool for all database connections to use applications can set
|
765
|
+
`config.active_record.async_query_executor` to `:global_thread_pool` and optionally define
|
766
|
+
`config.active_record.global_executor_concurrency`. This defaults to 4. For applications that want
|
767
|
+
to have a thread pool for each database connection, `config.active_record.async_query_executor` can
|
768
|
+
be set to `:multi_thread_pool`. The configuration for each thread pool is set in the database
|
769
|
+
configuration.
|
1549
770
|
|
1550
|
-
*
|
771
|
+
*Eileen M. Uchitelle*
|
1551
772
|
|
1552
|
-
*
|
773
|
+
* Allow new syntax for `enum` to avoid leading `_` from reserved options.
|
1553
774
|
|
1554
775
|
Before:
|
1555
776
|
|
1556
777
|
```ruby
|
1557
|
-
|
778
|
+
class Book < ActiveRecord::Base
|
779
|
+
enum status: [ :proposed, :written ], _prefix: true, _scopes: false
|
780
|
+
enum cover: [ :hard, :soft ], _suffix: true, _default: :hard
|
781
|
+
end
|
1558
782
|
```
|
1559
783
|
|
1560
784
|
After:
|
1561
785
|
|
1562
786
|
```ruby
|
1563
|
-
|
787
|
+
class Book < ActiveRecord::Base
|
788
|
+
enum :status, [ :proposed, :written ], prefix: true, scopes: false
|
789
|
+
enum :cover, [ :hard, :soft ], suffix: true, default: :hard
|
790
|
+
end
|
1564
791
|
```
|
1565
792
|
|
1566
|
-
*
|
1567
|
-
|
1568
|
-
* Ensure `:reading` connections always raise if a write is attempted.
|
1569
|
-
|
1570
|
-
Now Rails will raise an `ActiveRecord::ReadOnlyError` if any connection on the reading handler attempts to make a write. If your reading role needs to write you should name the role something other than `:reading`.
|
1571
|
-
|
1572
|
-
*Eileen M. Uchitelle*
|
1573
|
-
|
1574
|
-
* Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
|
1575
|
-
|
1576
|
-
`"primary"` has been deprecated as the `connection_specification_name` for `ActiveRecord::Base` in favor of using `"ActiveRecord::Base"`. This change affects calls to `ActiveRecord::Base.connection_handler.retrieve_connection` and `ActiveRecord::Base.connection_handler.remove_connection`. If you're calling these methods with `"primary"`, please switch to `"ActiveRecord::Base"`.
|
793
|
+
*Ryuta Kamizono*
|
1577
794
|
|
1578
|
-
|
795
|
+
* Add `ActiveRecord::Relation#load_async`.
|
1579
796
|
|
1580
|
-
|
1581
|
-
support for casting floats using a database columns' precision value.
|
797
|
+
This method schedules the query to be performed asynchronously from a thread pool.
|
1582
798
|
|
1583
|
-
|
799
|
+
If the result is accessed before a background thread had the opportunity to perform
|
800
|
+
the query, it will be performed in the foreground.
|
1584
801
|
|
1585
|
-
|
1586
|
-
|
1587
|
-
ActionController::ConditionalGet to ensure that when collection cache versioning
|
1588
|
-
is enabled, requests using ConditionalGet don't return the same ETag header
|
1589
|
-
after a collection is modified.
|
802
|
+
This is useful for queries that can be performed long enough before their result will be
|
803
|
+
needed, or for controllers which need to perform several independent queries.
|
1590
804
|
|
1591
|
-
|
805
|
+
```ruby
|
806
|
+
def index
|
807
|
+
@categories = Category.some_complex_scope.load_async
|
808
|
+
@posts = Post.some_complex_scope.load_async
|
809
|
+
end
|
810
|
+
```
|
1592
811
|
|
1593
|
-
|
812
|
+
Active Record logs will also include timing info for the duration of how long
|
813
|
+
the main thread had to wait to access the result. This timing is useful to know
|
814
|
+
whether or not it's worth to load the query asynchronously.
|
1594
815
|
|
1595
|
-
|
1596
|
-
|
816
|
+
```
|
817
|
+
DEBUG -- : Category Load (62.1ms) SELECT * FROM `categories` LIMIT 50
|
818
|
+
DEBUG -- : ASYNC Post Load (64ms) (db time 126.1ms) SELECT * FROM `posts` LIMIT 100
|
819
|
+
```
|
1597
820
|
|
1598
|
-
|
821
|
+
The duration in the first set of parens is how long the main thread was blocked
|
822
|
+
waiting for the results, and the second set of parens with "db time" is how long
|
823
|
+
the entire query took to execute.
|
1599
824
|
|
1600
|
-
*
|
825
|
+
*Jean Boussier*
|
1601
826
|
|
1602
|
-
|
827
|
+
* Implemented `ActiveRecord::Relation#excluding` method.
|
1603
828
|
|
1604
|
-
|
829
|
+
This method excludes the specified record (or collection of records) from
|
830
|
+
the resulting relation:
|
1605
831
|
|
1606
832
|
```ruby
|
1607
|
-
|
1608
|
-
|
833
|
+
Post.excluding(post)
|
834
|
+
Post.excluding(post_one, post_two)
|
1609
835
|
```
|
1610
836
|
|
1611
|
-
|
837
|
+
Also works on associations:
|
1612
838
|
|
1613
839
|
```ruby
|
1614
|
-
|
1615
|
-
|
1616
|
-
db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
|
840
|
+
post.comments.excluding(comment)
|
841
|
+
post.comments.excluding(comment_one, comment_two)
|
1617
842
|
```
|
1618
843
|
|
1619
|
-
|
1620
|
-
|
1621
|
-
* Remove `:connection_id` from the `sql.active_record` notification.
|
844
|
+
This is short-hand for `Post.where.not(id: post.id)` (for a single record)
|
845
|
+
and `Post.where.not(id: [post_one.id, post_two.id])` (for a collection).
|
1622
846
|
|
1623
|
-
*
|
847
|
+
*Glen Crawford*
|
1624
848
|
|
1625
|
-
*
|
849
|
+
* Skip optimised #exist? query when #include? is called on a relation
|
850
|
+
with a having clause.
|
1626
851
|
|
1627
|
-
|
852
|
+
Relations that have aliased select values AND a having clause that
|
853
|
+
references an aliased select value would generate an error when
|
854
|
+
#include? was called, due to an optimisation that would generate
|
855
|
+
call #exists? on the relation instead, which effectively alters
|
856
|
+
the select values of the query (and thus removes the aliased select
|
857
|
+
values), but leaves the having clause intact. Because the having
|
858
|
+
clause is then referencing an aliased column that is no longer
|
859
|
+
present in the simplified query, an ActiveRecord::InvalidStatement
|
860
|
+
error was raised.
|
1628
861
|
|
1629
|
-
|
862
|
+
A sample query affected by this problem:
|
1630
863
|
|
1631
|
-
|
1632
|
-
|
864
|
+
```ruby
|
865
|
+
Author.select('COUNT(*) as total_posts', 'authors.*')
|
866
|
+
.joins(:posts)
|
867
|
+
.group(:id)
|
868
|
+
.having('total_posts > 2')
|
869
|
+
.include?(Author.first)
|
870
|
+
```
|
1633
871
|
|
1634
|
-
This change
|
1635
|
-
|
872
|
+
This change adds an addition check to the condition that skips the
|
873
|
+
simplified #exists? query, which simply checks for the presence of
|
874
|
+
a having clause.
|
1636
875
|
|
1637
|
-
|
876
|
+
Fixes #41417.
|
1638
877
|
|
1639
|
-
*
|
878
|
+
*Michael Smart*
|
1640
879
|
|
1641
|
-
|
880
|
+
* Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
|
881
|
+
without Rails knowledge (e.g., if app gets killed during long-running query or due to Rack::Timeout), app won't end
|
882
|
+
up in perpetual crash state for being inconsistent with PostgreSQL.
|
1642
883
|
|
1643
|
-
*
|
884
|
+
*wbharding*, *Martin Tepper*
|
1644
885
|
|
1645
|
-
|
886
|
+
* Add ability to apply `scoping` to `all_queries`.
|
1646
887
|
|
1647
|
-
|
888
|
+
Some applications may want to use the `scoping` method but previously it only
|
889
|
+
worked on certain types of queries. This change allows the `scoping` method to apply
|
890
|
+
to all queries for a model in a block.
|
1648
891
|
|
1649
|
-
|
892
|
+
```ruby
|
893
|
+
Post.where(blog_id: post.blog_id).scoping(all_queries: true) do
|
894
|
+
post.update(title: "a post title") # adds `posts.blog_id = 1` to the query
|
895
|
+
end
|
896
|
+
```
|
1650
897
|
|
1651
|
-
*Eileen M. Uchitelle
|
898
|
+
*Eileen M. Uchitelle*
|
1652
899
|
|
1653
|
-
*
|
900
|
+
* `ActiveRecord::Calculations.calculate` called with `:average`
|
901
|
+
(aliased as `ActiveRecord::Calculations.average`) will now use column-based
|
902
|
+
type casting. This means that floating-point number columns will now be
|
903
|
+
aggregated as `Float` and decimal columns will be aggregated as `BigDecimal`.
|
1654
904
|
|
1655
|
-
|
905
|
+
Integers are handled as a special case returning `BigDecimal` always
|
906
|
+
(this was the case before already).
|
1656
907
|
|
1657
|
-
|
908
|
+
```ruby
|
909
|
+
# With the following schema:
|
910
|
+
create_table "measurements" do |t|
|
911
|
+
t.float "temperature"
|
912
|
+
end
|
1658
913
|
|
1659
|
-
|
914
|
+
# Before:
|
915
|
+
Measurement.average(:temperature).class
|
916
|
+
# => BigDecimal
|
1660
917
|
|
1661
|
-
|
918
|
+
# After:
|
919
|
+
Measurement.average(:temperature).class
|
920
|
+
# => Float
|
921
|
+
```
|
1662
922
|
|
1663
|
-
|
923
|
+
Before this change, Rails just called `to_d` on average aggregates from the
|
924
|
+
database adapter. This is not the case anymore. If you relied on that kind
|
925
|
+
of magic, you now need to register your own `ActiveRecord::Type`
|
926
|
+
(see `ActiveRecord::Attributes::ClassMethods` for documentation).
|
1664
927
|
|
1665
|
-
*
|
928
|
+
*Josua Schmid*
|
1666
929
|
|
1667
|
-
|
930
|
+
* PostgreSQL: introduce `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type`.
|
1668
931
|
|
1669
|
-
|
932
|
+
This setting controls what native type Active Record should use when you call `datetime` in
|
933
|
+
a migration or schema. It takes a symbol which must correspond to one of the configured
|
934
|
+
`NATIVE_DATABASE_TYPES`. The default is `:timestamp`, meaning `t.datetime` in a migration
|
935
|
+
will create a "timestamp without time zone" column. To use "timestamp with time zone",
|
936
|
+
change this to `:timestamptz` in an initializer.
|
1670
937
|
|
1671
|
-
|
938
|
+
You should run `bin/rails db:migrate` to rebuild your schema.rb if you change this.
|
1672
939
|
|
1673
|
-
*
|
940
|
+
*Alex Ghiculescu*
|
1674
941
|
|
1675
|
-
|
942
|
+
* PostgreSQL: handle `timestamp with time zone` columns correctly in `schema.rb`.
|
1676
943
|
|
1677
|
-
|
944
|
+
Previously they dumped as `t.datetime :column_name`, now they dump as `t.timestamptz :column_name`,
|
945
|
+
and are created as `timestamptz` columns when the schema is loaded.
|
1678
946
|
|
1679
|
-
*
|
947
|
+
*Alex Ghiculescu*
|
1680
948
|
|
1681
|
-
*
|
1682
|
-
|
949
|
+
* Removing trailing whitespace when matching columns in
|
950
|
+
`ActiveRecord::Sanitization.disallow_raw_sql!`.
|
1683
951
|
|
1684
|
-
|
952
|
+
*Gannon McGibbon*, *Adrian Hirt*
|
1685
953
|
|
1686
|
-
|
1687
|
-
has_secure_token :auth_token
|
1688
|
-
```
|
954
|
+
* Expose a way for applications to set a `primary_abstract_class`.
|
1689
955
|
|
1690
|
-
|
956
|
+
Multiple database applications that use a primary abstract class that is not
|
957
|
+
named `ApplicationRecord` can now set a specific class to be the `primary_abstract_class`.
|
1691
958
|
|
1692
959
|
```ruby
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
960
|
+
class PrimaryApplicationRecord
|
961
|
+
self.primary_abstract_class
|
962
|
+
end
|
1696
963
|
```
|
1697
964
|
|
1698
|
-
|
965
|
+
When an application boots it automatically connects to the primary or first database in the
|
966
|
+
database configuration file. In a multiple database application that then call `connects_to`
|
967
|
+
needs to know that the default connection is the same as the `ApplicationRecord` connection.
|
968
|
+
However, some applications have a differently named `ApplicationRecord`. This prevents Active
|
969
|
+
Record from opening duplicate connections to the same database.
|
1699
970
|
|
1700
|
-
*
|
1701
|
-
|
1702
|
-
*Eileen Uchitelle*, *John Crepezzi*
|
971
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1703
972
|
|
1704
|
-
*
|
973
|
+
* Support hash config for `structure_dump_flags` and `structure_load_flags` flags
|
974
|
+
Now that Active Record supports multiple databases configuration
|
975
|
+
we need a way to pass specific flags for dump/load databases since
|
976
|
+
the options are not the same for different adapters.
|
977
|
+
We can use in the original way:
|
1705
978
|
|
1706
|
-
|
979
|
+
```ruby
|
980
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = ['--no-defaults', '--skip-add-drop-table']
|
981
|
+
# or
|
982
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = '--no-defaults --skip-add-drop-table'
|
983
|
+
```
|
1707
984
|
|
1708
|
-
|
985
|
+
And also use it passing a hash, with one or more keys, where the key
|
986
|
+
is the adapter
|
1709
987
|
|
1710
|
-
|
988
|
+
```ruby
|
989
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = {
|
990
|
+
mysql2: ['--no-defaults', '--skip-add-drop-table'],
|
991
|
+
postgres: '--no-tablespaces'
|
992
|
+
}
|
993
|
+
```
|
1711
994
|
|
1712
|
-
|
995
|
+
*Gustavo Gonzalez*
|
1713
996
|
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
997
|
+
* Connection specification now passes the "url" key as a configuration for the
|
998
|
+
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
|
999
|
+
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
|
1000
|
+
are assumed to be adapter specification urls.
|
1718
1001
|
|
1719
|
-
|
1002
|
+
Fixes #41137.
|
1720
1003
|
|
1721
|
-
|
1004
|
+
*Jonathan Bracy*
|
1722
1005
|
|
1723
|
-
|
1006
|
+
* Allow to opt-out of `strict_loading` mode on a per-record base.
|
1724
1007
|
|
1725
|
-
|
1008
|
+
This is useful when strict loading is enabled application wide or on a
|
1009
|
+
model level.
|
1726
1010
|
|
1727
|
-
|
1011
|
+
```ruby
|
1012
|
+
class User < ApplicationRecord
|
1013
|
+
has_many :bookmarks
|
1014
|
+
has_many :articles, strict_loading: true
|
1015
|
+
end
|
1728
1016
|
|
1729
|
-
|
1017
|
+
user = User.first
|
1018
|
+
user.articles # => ActiveRecord::StrictLoadingViolationError
|
1019
|
+
user.bookmarks # => #<ActiveRecord::Associations::CollectionProxy>
|
1730
1020
|
|
1731
|
-
|
1021
|
+
user.strict_loading!(true) # => true
|
1022
|
+
user.bookmarks # => ActiveRecord::StrictLoadingViolationError
|
1732
1023
|
|
1733
|
-
|
1024
|
+
user.strict_loading!(false) # => false
|
1025
|
+
user.bookmarks # => #<ActiveRecord::Associations::CollectionProxy>
|
1026
|
+
user.articles.strict_loading!(false) # => #<ActiveRecord::Associations::CollectionProxy>
|
1027
|
+
```
|
1734
1028
|
|
1735
|
-
|
1029
|
+
*Ayrton De Craene*
|
1736
1030
|
|
1737
|
-
|
1031
|
+
* Add `FinderMethods#sole` and `#find_sole_by` to find and assert the
|
1032
|
+
presence of exactly one record.
|
1738
1033
|
|
1739
|
-
|
1034
|
+
Used when you need a single row, but also want to assert that there aren't
|
1035
|
+
multiple rows matching the condition; especially for when database
|
1036
|
+
constraints aren't enough or are impractical.
|
1740
1037
|
|
1741
|
-
|
1038
|
+
```ruby
|
1039
|
+
Product.where(["price = %?", price]).sole
|
1040
|
+
# => ActiveRecord::RecordNotFound (if no Product with given price)
|
1041
|
+
# => #<Product ...> (if one Product with given price)
|
1042
|
+
# => ActiveRecord::SoleRecordExceeded (if more than one Product with given price)
|
1742
1043
|
|
1743
|
-
|
1044
|
+
user.api_keys.find_sole_by(key: key)
|
1045
|
+
# as above
|
1046
|
+
```
|
1744
1047
|
|
1745
|
-
*
|
1048
|
+
*Asherah Connor*
|
1746
1049
|
|
1747
|
-
|
1050
|
+
* Makes `ActiveRecord::AttributeMethods::Query` respect the getter overrides defined in the model.
|
1748
1051
|
|
1749
|
-
|
1052
|
+
Before:
|
1750
1053
|
|
1751
|
-
|
1054
|
+
```ruby
|
1055
|
+
class User
|
1056
|
+
def admin
|
1057
|
+
false # Overriding the getter to always return false
|
1058
|
+
end
|
1059
|
+
end
|
1752
1060
|
|
1753
|
-
|
1061
|
+
user = User.first
|
1062
|
+
user.update(admin: true)
|
1754
1063
|
|
1755
|
-
|
1064
|
+
user.admin # false (as expected, due to the getter overwrite)
|
1065
|
+
user.admin? # true (not expected, returned the DB column value)
|
1066
|
+
```
|
1756
1067
|
|
1757
|
-
|
1068
|
+
After this commit, `user.admin?` above returns false, as expected.
|
1758
1069
|
|
1759
|
-
|
1070
|
+
Fixes #40771.
|
1760
1071
|
|
1761
|
-
*
|
1072
|
+
*Felipe*
|
1762
1073
|
|
1763
|
-
|
1074
|
+
* Allow delegated_type to be specified primary_key and foreign_key.
|
1764
1075
|
|
1765
|
-
|
1076
|
+
Since delegated_type assumes that the foreign_key ends with `_id`,
|
1077
|
+
`singular_id` defined by it does not work when the foreign_key does
|
1078
|
+
not end with `id`. This change fixes it by taking into account
|
1079
|
+
`primary_key` and `foreign_key` in the options.
|
1766
1080
|
|
1767
|
-
*
|
1081
|
+
*Ryota Egusa*
|
1768
1082
|
|
1769
|
-
*
|
1083
|
+
* Expose an `invert_where` method that will invert all scope conditions.
|
1770
1084
|
|
1771
|
-
|
1085
|
+
```ruby
|
1086
|
+
class User
|
1087
|
+
scope :active, -> { where(accepted: true, locked: false) }
|
1088
|
+
end
|
1772
1089
|
|
1773
|
-
|
1090
|
+
User.active
|
1091
|
+
# ... WHERE `accepted` = 1 AND `locked` = 0
|
1774
1092
|
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1093
|
+
User.active.invert_where
|
1094
|
+
# ... WHERE NOT (`accepted` = 1 AND `locked` = 0)
|
1095
|
+
```
|
1778
1096
|
|
1779
|
-
*
|
1097
|
+
*Kevin Deisz*
|
1780
1098
|
|
1781
|
-
*
|
1099
|
+
* Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
|
1782
1100
|
|
1783
|
-
|
1101
|
+
Previously, passing `false` would trigger the option validation logic
|
1102
|
+
to throw an error saying :polymorphic would not be a valid option.
|
1784
1103
|
|
1785
|
-
*
|
1104
|
+
*glaszig*
|
1786
1105
|
|
1787
|
-
|
1106
|
+
* Remove deprecated `database` kwarg from `connected_to`.
|
1788
1107
|
|
1789
|
-
*
|
1108
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1790
1109
|
|
1791
|
-
|
1110
|
+
* Allow adding nonnamed expression indexes to be revertible.
|
1792
1111
|
|
1793
|
-
|
1112
|
+
Previously, the following code would raise an error, when executed while rolling back,
|
1113
|
+
and the index name should be specified explicitly. Now, the index name is inferred
|
1114
|
+
automatically.
|
1794
1115
|
|
1795
|
-
|
1116
|
+
```ruby
|
1117
|
+
add_index(:items, "to_tsvector('english', description)")
|
1118
|
+
```
|
1796
1119
|
|
1797
|
-
|
1120
|
+
Fixes #40732.
|
1798
1121
|
|
1799
|
-
|
1122
|
+
*fatkodima*
|
1800
1123
|
|
1801
|
-
|
1124
|
+
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
1802
1125
|
|
1803
|
-
|
1126
|
+
Fixes #39065.
|
1804
1127
|
|
1805
|
-
|
1128
|
+
*Alex Ghiculescu*
|
1806
1129
|
|
1807
|
-
|
1130
|
+
* Add option to run `default_scope` on all queries.
|
1808
1131
|
|
1809
|
-
|
1132
|
+
Previously, a `default_scope` would only run on select or insert queries. In some cases, like non-Rails tenant sharding solutions, it may be desirable to run `default_scope` on all queries in order to ensure queries are including a foreign key for the shard (i.e. `blog_id`).
|
1810
1133
|
|
1811
|
-
|
1134
|
+
Now applications can add an option to run on all queries including select, insert, delete, and update by adding an `all_queries` option to the default scope definition.
|
1812
1135
|
|
1813
|
-
|
1136
|
+
```ruby
|
1137
|
+
class Article < ApplicationRecord
|
1138
|
+
default_scope -> { where(blog_id: Current.blog.id) }, all_queries: true
|
1139
|
+
end
|
1140
|
+
```
|
1814
1141
|
|
1815
|
-
*
|
1142
|
+
*Eileen M. Uchitelle*
|
1816
1143
|
|
1817
|
-
*
|
1144
|
+
* Add `where.associated` to check for the presence of an association.
|
1818
1145
|
|
1819
|
-
|
1146
|
+
```ruby
|
1147
|
+
# Before:
|
1148
|
+
account.users.joins(:contact).where.not(contact_id: nil)
|
1820
1149
|
|
1821
|
-
|
1150
|
+
# After:
|
1151
|
+
account.users.where.associated(:contact)
|
1152
|
+
```
|
1822
1153
|
|
1823
|
-
|
1154
|
+
Also mirrors `where.missing`.
|
1824
1155
|
|
1825
|
-
*
|
1156
|
+
*Kasper Timm Hansen*
|
1826
1157
|
|
1827
|
-
* Allow
|
1158
|
+
* Allow constructors (`build_association` and `create_association`) on
|
1159
|
+
`has_one :through` associations.
|
1828
1160
|
|
1829
|
-
*
|
1161
|
+
*Santiago Perez Perret*
|
1830
1162
|
|
1831
1163
|
|
1832
|
-
Please check [6-
|
1164
|
+
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activerecord/CHANGELOG.md) for previous changes.
|