activerecord 6.1.3.1 → 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 +733 -1057
- 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 +35 -7
- data/lib/active_record/associations/association_scope.rb +1 -3
- data/lib/active_record/associations/belongs_to_association.rb +16 -6
- 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 +24 -25
- 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 -49
- 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 +11 -1
- 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 +14 -7
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +5 -18
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +30 -9
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +60 -16
- data/lib/active_record/connection_adapters/abstract/transaction.rb +17 -6
- data/lib/active_record/connection_adapters/abstract_adapter.rb +115 -69
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +96 -81
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +6 -2
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +33 -21
- data/lib/active_record/connection_adapters/mysql/quoting.rb +16 -1
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +3 -0
- 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/pool_manager.rb +5 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +19 -12
- 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 -6
- 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 +157 -100
- data/lib/active_record/connection_adapters/schema_cache.rb +35 -4
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +0 -2
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +23 -17
- 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 +8 -5
- data/lib/active_record/connection_handling.rb +20 -38
- data/lib/active_record/core.rb +129 -117
- 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 +18 -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 +44 -46
- 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 +39 -6
- data/lib/active_record/integration.rb +1 -1
- data/lib/active_record/internal_metadata.rb +3 -5
- data/lib/active_record/legacy_yaml_adapter.rb +1 -1
- 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 +83 -1
- 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 +46 -32
- 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 +83 -58
- 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 +42 -25
- data/lib/active_record/relation/delegation.rb +6 -6
- data/lib/active_record/relation/finder_methods.rb +32 -23
- 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 +233 -50
- 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 +22 -15
- data/lib/active_record/relation.rb +170 -87
- 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 +62 -15
- 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/statement_cache.rb +2 -2
- data/lib/active_record/tasks/database_tasks.rb +107 -23
- 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 +45 -4
- 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/validations/numericality.rb +1 -1
- data/lib/active_record.rb +170 -2
- data/lib/arel/attributes/attribute.rb +0 -8
- data/lib/arel/collectors/bind.rb +2 -2
- data/lib/arel/collectors/composite.rb +3 -3
- data/lib/arel/collectors/sql_string.rb +1 -1
- data/lib/arel/collectors/substitute_binds.rb +1 -1
- 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/homogeneous_in.rb +4 -0
- 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 +3 -3
- 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 +44 -3
- 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 +52 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8b1381be32717b39c0060b1d2fe294fa5bd782565949f7ef9d106dff7de7caa
|
4
|
+
data.tar.gz: 003b65d0b2e4b6ac2492bd5249b1bb609173c5885dee85fc3caa6ab7ae9512e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 942850951ae80edc566d1748d560e5928d1e541081c74f43a771226f50d95a3f82f119b1e47d74ef1d328d6374ab0cddb6e87df849fec3e9765990fe9983b958
|
7
|
+
data.tar.gz: 017cae0c0f11441244b2d505aeca4c9157e3fd6458a58ca49910f3158df5a45ab6d0401a36cacca046200bec484dc7434d9b2416feced753cbbf89587dcb9a2b
|
data/CHANGELOG.md
CHANGED
@@ -1,1488 +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
|
-
|
7
|
-
|
8
|
-
* Fix the MySQL adapter to always set the right collation and charset
|
9
|
-
to the connection session.
|
10
|
-
|
11
|
-
*Rafael Mendonça França*
|
12
|
-
|
13
|
-
* Fix MySQL adapter handling of time objects when prepared statements
|
14
|
-
are enabled.
|
15
|
-
|
16
|
-
*Rafael Mendonça França*
|
17
|
-
|
18
|
-
* Fix scoping in enum fields using conditions that would generate
|
19
|
-
an `IN` clause.
|
20
|
-
|
21
|
-
*Ryuta Kamizono*
|
22
|
-
|
23
|
-
* Skip optimised #exist? query when #include? is called on a relation
|
24
|
-
with a having clause
|
25
|
-
|
26
|
-
Relations that have aliased select values AND a having clause that
|
27
|
-
references an aliased select value would generate an error when
|
28
|
-
#include? was called, due to an optimisation that would generate
|
29
|
-
call #exists? on the relation instead, which effectively alters
|
30
|
-
the select values of the query (and thus removes the aliased select
|
31
|
-
values), but leaves the having clause intact. Because the having
|
32
|
-
clause is then referencing an aliased column that is no longer
|
33
|
-
present in the simplified query, an ActiveRecord::InvalidStatement
|
34
|
-
error was raised.
|
35
|
-
|
36
|
-
An sample query affected by this problem:
|
37
|
-
|
38
|
-
```ruby
|
39
|
-
Author.select('COUNT(*) as total_posts', 'authors.*')
|
40
|
-
.joins(:posts)
|
41
|
-
.group(:id)
|
42
|
-
.having('total_posts > 2')
|
43
|
-
.include?(Author.first)
|
7
|
+
```
|
8
|
+
Creating scope :my_scope_name. Overwriting existing method "MyClass.my_scope_name" when overwriting existing scopes
|
44
9
|
```
|
45
10
|
|
46
|
-
|
47
|
-
simplified #exists? query, which simply checks for the presence of
|
48
|
-
a having clause.
|
49
|
-
|
50
|
-
Fixes #41417
|
51
|
-
|
52
|
-
*Michael Smart*
|
53
|
-
|
54
|
-
* Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
|
55
|
-
without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
|
56
|
-
up in perpetual crash state for being inconsistent with Postgres.
|
57
|
-
|
58
|
-
*wbharding*, *Martin Tepper*
|
59
|
-
|
60
|
-
|
61
|
-
## Rails 6.1.2.1 (February 10, 2021) ##
|
62
|
-
|
63
|
-
* Fix possible DoS vector in PostgreSQL money type
|
64
|
-
|
65
|
-
Carefully crafted input can cause a DoS via the regular expressions used
|
66
|
-
for validating the money format in the PostgreSQL adapter. This patch
|
67
|
-
fixes the regexp.
|
68
|
-
|
69
|
-
Thanks to @dee-see from Hackerone for this patch!
|
70
|
-
|
71
|
-
[CVE-2021-22880]
|
72
|
-
|
73
|
-
*Aaron Patterson*
|
74
|
-
|
75
|
-
|
76
|
-
## Rails 6.1.2 (February 09, 2021) ##
|
77
|
-
|
78
|
-
* Fix timestamp type for sqlite3.
|
79
|
-
|
80
|
-
*Eileen M. Uchitelle*
|
81
|
-
|
82
|
-
* Make destroy async transactional.
|
83
|
-
|
84
|
-
An active record rollback could occur while enqueuing a job. In this
|
85
|
-
case the job would enqueue even though the database deletion
|
86
|
-
rolledback putting things in a funky state.
|
87
|
-
|
88
|
-
Now the jobs are only enqueued until after the db transaction has been committed.
|
89
|
-
|
90
|
-
*Cory Gwin*
|
91
|
-
|
92
|
-
* Fix malformed packet error in MySQL statement for connection configuration.
|
93
|
-
|
94
|
-
*robinroestenburg*
|
95
|
-
|
96
|
-
* Connection specification now passes the "url" key as a configuration for the
|
97
|
-
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
|
98
|
-
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
|
99
|
-
are assumed to be adapter specification urls.
|
100
|
-
|
101
|
-
Fixes #41137.
|
102
|
-
|
103
|
-
*Jonathan Bracy*
|
104
|
-
|
105
|
-
* Fix granular connection swapping when there are multiple abstract classes.
|
106
|
-
|
107
|
-
*Eileen M. Uchitelle*
|
108
|
-
|
109
|
-
* Fix `find_by` with custom primary key for belongs_to association.
|
110
|
-
|
111
|
-
*Ryuta Kamizono*
|
112
|
-
|
113
|
-
* Add support for `rails console --sandbox` for multiple database applications.
|
114
|
-
|
115
|
-
*alpaca-tc*
|
116
|
-
|
117
|
-
* Fix `where` on polymorphic association with empty array.
|
118
|
-
|
119
|
-
*Ryuta Kamizono*
|
120
|
-
|
121
|
-
* Fix preventing writes for `ApplicationRecord`.
|
122
|
-
|
123
|
-
*Eileen M. Uchitelle*
|
124
|
-
|
125
|
-
|
126
|
-
## Rails 6.1.1 (January 07, 2021) ##
|
127
|
-
|
128
|
-
* Fix fixtures loading when strict loading is enabled for the association.
|
11
|
+
*Weston Ganger*
|
129
12
|
|
130
|
-
|
13
|
+
* Use full precision for `updated_at` in `insert_all`/`upsert_all`
|
131
14
|
|
132
|
-
|
15
|
+
`CURRENT_TIMESTAMP` provides differing precision depending on the database,
|
16
|
+
and not all databases support explicitly specifying additional precision.
|
133
17
|
|
134
|
-
|
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.
|
135
20
|
|
136
|
-
|
21
|
+
Fixes #42992
|
137
22
|
|
138
|
-
*
|
23
|
+
*Sam Bostock*
|
139
24
|
|
140
|
-
*
|
25
|
+
* Add ssl support for postgresql database tasks
|
141
26
|
|
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
|
-
*Ryuta Kamizono*
|
30
|
+
```yaml
|
31
|
+
# config/database.yml
|
147
32
|
|
148
|
-
|
33
|
+
production:
|
34
|
+
sslmode: verify-full
|
35
|
+
sslcert: client.crt
|
36
|
+
sslkey: client.key
|
37
|
+
sslrootcert: ca.crt
|
38
|
+
```
|
149
39
|
|
150
|
-
|
40
|
+
Environment variables
|
151
41
|
|
152
|
-
|
42
|
+
```
|
43
|
+
PGSSLMODE=verify-full
|
44
|
+
PGSSLCERT=client.crt
|
45
|
+
PGSSLKEY=client.key
|
46
|
+
PGSSLROOTCERT=ca.crt
|
47
|
+
```
|
153
48
|
|
154
|
-
|
49
|
+
Fixes #42994
|
155
50
|
|
156
|
-
*
|
51
|
+
*Michael Bayucot*
|
157
52
|
|
158
|
-
|
53
|
+
* Avoid scoping update callbacks in `ActiveRecord::Relation#update!`.
|
159
54
|
|
160
|
-
|
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.
|
161
57
|
|
162
|
-
*
|
58
|
+
*Dylan Thacker-Smith*
|
163
59
|
|
164
|
-
*
|
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`.
|
165
62
|
|
166
|
-
|
167
|
-
|
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`
|
168
66
|
|
169
|
-
*
|
67
|
+
*Jimmy Bourassa*
|
170
68
|
|
171
|
-
*
|
69
|
+
* Add config option for ignoring tables when dumping the schema cache.
|
172
70
|
|
173
|
-
|
71
|
+
Applications can now be configured to ignore certain tables when dumping the schema cache.
|
174
72
|
|
175
|
-
|
176
|
-
and the index name should be specified explicitly. Now, the index name is inferred
|
177
|
-
automatically.
|
73
|
+
The configuration option can table an array of tables:
|
178
74
|
|
179
75
|
```ruby
|
180
|
-
|
76
|
+
config.active_record.schema_cache_ignored_tables = ["ignored_table", "another_ignored_table"]
|
181
77
|
```
|
182
78
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
## Rails 6.1.0 (December 09, 2020) ##
|
187
|
-
|
188
|
-
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
189
|
-
|
190
|
-
Fixes #39065.
|
191
|
-
|
192
|
-
*Alex Ghiculescu*
|
193
|
-
|
194
|
-
* Change `attribute_for_inspect` to take `filter_attributes` in consideration.
|
195
|
-
|
196
|
-
*Rafael Mendonça França*
|
197
|
-
|
198
|
-
* Fix odd behavior of inverse_of with multiple belongs_to to same class.
|
199
|
-
|
200
|
-
Fixes #35204.
|
201
|
-
|
202
|
-
*Tomoyuki Kai*
|
203
|
-
|
204
|
-
* Build predicate conditions with objects that delegate `#id` and primary key:
|
79
|
+
Or a regex:
|
205
80
|
|
206
81
|
```ruby
|
207
|
-
|
208
|
-
delegate_missing_to :@author
|
209
|
-
|
210
|
-
def initialize(author)
|
211
|
-
@author = author
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
Post.where(author: AdminAuthor.new(author))
|
82
|
+
config.active_record.schema_cache_ignored_tables = [/^_/]
|
216
83
|
```
|
217
84
|
|
218
|
-
*Sean Doyle*
|
219
|
-
|
220
|
-
* Add `connected_to_many` API.
|
221
|
-
|
222
|
-
This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
|
223
|
-
|
224
|
-
Before:
|
225
|
-
|
226
|
-
AnimalsRecord.connected_to(role: :reading) do
|
227
|
-
MealsRecord.connected_to(role: :reading) do
|
228
|
-
Dog.first # read from animals replica
|
229
|
-
Dinner.first # read from meals replica
|
230
|
-
Person.first # read from primary writer
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
After:
|
235
|
-
|
236
|
-
ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
|
237
|
-
Dog.first # read from animals replica
|
238
|
-
Dinner.first # read from meals replica
|
239
|
-
Person.first # read from primary writer
|
240
|
-
end
|
241
|
-
|
242
|
-
*Eileen M. Uchitelle*, *John Crepezzi*
|
243
|
-
|
244
|
-
* Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
|
245
|
-
|
246
|
-
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.
|
247
|
-
|
248
|
-
Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
|
249
|
-
|
250
85
|
*Eileen M. Uchitelle*
|
251
86
|
|
252
|
-
*
|
253
|
-
|
254
|
-
Fixes #34255.
|
255
|
-
|
256
|
-
*Steven Weber*
|
257
|
-
|
258
|
-
* Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
|
259
|
-
|
260
|
-
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.
|
261
|
-
|
262
|
-
This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
|
263
|
-
|
264
|
-
Fixes #38655.
|
265
|
-
|
266
|
-
*Luke Redpath*
|
267
|
-
|
268
|
-
* MySQL: Uniqueness validator now respects default database collation,
|
269
|
-
no longer enforce case sensitive comparison by default.
|
270
|
-
|
271
|
-
*Ryuta Kamizono*
|
272
|
-
|
273
|
-
* Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
|
87
|
+
* Make schema cache methods return consistent results.
|
274
88
|
|
275
|
-
`
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
`columns_per_multicolumn_index`
|
280
|
-
`sql_query_length`
|
281
|
-
`joins_per_query`
|
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.
|
282
93
|
|
283
|
-
|
94
|
+
The behavior now is:
|
284
95
|
|
285
|
-
|
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
|
286
100
|
|
287
|
-
*
|
288
|
-
|
289
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
|
290
|
-
|
291
|
-
*Rafael Mendonça França*
|
292
|
-
|
293
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
|
294
|
-
|
295
|
-
*Rafael Mendonça França*
|
296
|
-
|
297
|
-
* Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
|
298
|
-
|
299
|
-
*Rafael Mendonça França*
|
300
|
-
|
301
|
-
* Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
|
302
|
-
|
303
|
-
*Rafael Mendonça França*
|
304
|
-
|
305
|
-
* Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
|
306
|
-
|
307
|
-
*Rafael Mendonça França*
|
308
|
-
|
309
|
-
* `relation.create` does no longer leak scope to class level querying methods
|
310
|
-
in initialization block and callbacks.
|
311
|
-
|
312
|
-
Before:
|
313
|
-
|
314
|
-
User.where(name: "John").create do |john|
|
315
|
-
User.find_by(name: "David") # => nil
|
316
|
-
end
|
317
|
-
|
318
|
-
After:
|
319
|
-
|
320
|
-
User.where(name: "John").create do |john|
|
321
|
-
User.find_by(name: "David") # => #<User name: "David", ...>
|
322
|
-
end
|
323
|
-
|
324
|
-
*Ryuta Kamizono*
|
325
|
-
|
326
|
-
* Named scope chain does no longer leak scope to class level querying methods.
|
327
|
-
|
328
|
-
class User < ActiveRecord::Base
|
329
|
-
scope :david, -> { User.where(name: "David") }
|
330
|
-
end
|
331
|
-
|
332
|
-
Before:
|
333
|
-
|
334
|
-
User.where(name: "John").david
|
335
|
-
# SELECT * FROM users WHERE name = 'John' AND name = 'David'
|
336
|
-
|
337
|
-
After:
|
338
|
-
|
339
|
-
User.where(name: "John").david
|
340
|
-
# SELECT * FROM users WHERE name = 'David'
|
341
|
-
|
342
|
-
*Ryuta Kamizono*
|
343
|
-
|
344
|
-
* Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
|
345
|
-
|
346
|
-
`fetch`
|
347
|
-
`each`
|
348
|
-
`first`
|
349
|
-
`values`
|
350
|
-
`[]=`
|
351
|
-
|
352
|
-
*Rafael Mendonça França*
|
353
|
-
|
354
|
-
* `where.not` now generates NAND predicates instead of NOR.
|
355
|
-
|
356
|
-
Before:
|
357
|
-
|
358
|
-
User.where.not(name: "Jon", role: "admin")
|
359
|
-
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
|
360
|
-
|
361
|
-
After:
|
362
|
-
|
363
|
-
User.where.not(name: "Jon", role: "admin")
|
364
|
-
# SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
|
101
|
+
*Eileen M. Uchitelle*
|
365
102
|
|
366
|
-
|
103
|
+
* Reestablish connection to previous database after after running `db:schema:load:name`
|
367
104
|
|
368
|
-
|
105
|
+
After running `db:schema:load:name` the previous connection is restored.
|
369
106
|
|
370
|
-
*
|
107
|
+
*Jacopo Beschi*
|
371
108
|
|
372
|
-
*
|
109
|
+
* Add database config option `database_tasks`
|
373
110
|
|
374
|
-
|
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`
|
375
114
|
|
376
|
-
|
115
|
+
```yaml
|
116
|
+
# config/database.yml
|
377
117
|
|
378
|
-
|
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
|
126
|
+
```
|
379
127
|
|
380
|
-
*
|
381
|
-
message using `config.active_record.suppress_multiple_database_warning`.
|
128
|
+
*Weston Ganger*
|
382
129
|
|
383
|
-
|
130
|
+
* Fix `ActiveRecord::InternalMetadata` to not be broken by `config.active_record.record_timestamps = false`
|
384
131
|
|
385
|
-
|
132
|
+
Since the model always create the timestamp columns, it has to set them, otherwise it breaks
|
133
|
+
various DB management tasks.
|
386
134
|
|
387
|
-
|
135
|
+
Fixes #42983
|
388
136
|
|
389
|
-
|
137
|
+
* Add `ActiveRecord::QueryLogs`.
|
390
138
|
|
391
|
-
|
139
|
+
Configurable tags can be automatically added to all SQL queries generated by Active Record.
|
392
140
|
|
393
141
|
```ruby
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
AnimalsRecord.connected_to(role: :writing, shard: :one) do
|
399
|
-
User.first # reads from default replica
|
400
|
-
Dog.first # reads from shard one primary
|
401
|
-
end
|
402
|
-
|
403
|
-
User.first # reads from default replica
|
404
|
-
Dog.first # reads from default replica
|
405
|
-
|
406
|
-
ApplicationRecord.connected_to(role: :writing, shard: :two) do
|
407
|
-
User.first # reads from shard two primary
|
408
|
-
Dog.first # reads from default replica
|
142
|
+
# config/application.rb
|
143
|
+
module MyApp
|
144
|
+
class Application < Rails::Application
|
145
|
+
config.active_record.query_log_tags_enabled = true
|
409
146
|
end
|
410
147
|
end
|
411
148
|
```
|
412
149
|
|
413
|
-
|
414
|
-
|
415
|
-
* Allow double-dash comment syntax when querying read-only databases
|
416
|
-
|
417
|
-
*James Adam*
|
418
|
-
|
419
|
-
* Add `values_at` method.
|
420
|
-
|
421
|
-
Returns an array containing the values associated with the given methods.
|
150
|
+
By default the application, controller and action details are added to the query tags:
|
422
151
|
|
423
152
|
```ruby
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
Similar to `Hash#values_at` but on an Active Record instance.
|
430
|
-
|
431
|
-
*Guillaume Briday*
|
432
|
-
|
433
|
-
* Fix `read_attribute_before_type_cast` to consider attribute aliases.
|
434
|
-
|
435
|
-
*Marcelo Lauxen*
|
436
|
-
|
437
|
-
* Support passing record to uniqueness validator `:conditions` callable:
|
438
|
-
|
439
|
-
```ruby
|
440
|
-
class Article < ApplicationRecord
|
441
|
-
validates_uniqueness_of :title, conditions: ->(article) {
|
442
|
-
published_at = article.published_at
|
443
|
-
where(published_at: published_at.beginning_of_year..published_at.end_of_year)
|
444
|
-
}
|
153
|
+
class BooksController < ApplicationController
|
154
|
+
def index
|
155
|
+
@books = Book.all
|
156
|
+
end
|
445
157
|
end
|
446
158
|
```
|
447
159
|
|
448
|
-
*Eliot Sykes*
|
449
|
-
|
450
|
-
* `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
|
451
|
-
total number of rows affected, just like their non-batched counterparts.
|
452
|
-
|
453
|
-
```ruby
|
454
|
-
Person.in_batches.update_all("first_name = 'Eugene'") # => 42
|
455
|
-
Person.in_batches.delete_all # => 42
|
456
|
-
```
|
457
|
-
|
458
|
-
Fixes #40287.
|
459
|
-
|
460
|
-
*Eugene Kenny*
|
461
|
-
|
462
|
-
* Add support for PostgreSQL `interval` data type with conversion to
|
463
|
-
`ActiveSupport::Duration` when loading records from database and
|
464
|
-
serialization to ISO 8601 formatted duration string on save.
|
465
|
-
Add support to define a column in migrations and get it in a schema dump.
|
466
|
-
Optional column precision is supported.
|
467
|
-
|
468
|
-
To use this in 6.1, you need to place the next string to your model file:
|
469
|
-
|
470
|
-
attribute :duration, :interval
|
471
|
-
|
472
|
-
To keep old behavior until 6.2 is released:
|
473
|
-
|
474
|
-
attribute :duration, :string
|
475
|
-
|
476
|
-
Example:
|
477
|
-
|
478
|
-
create_table :events do |t|
|
479
|
-
t.string :name
|
480
|
-
t.interval :duration
|
481
|
-
end
|
482
|
-
|
483
|
-
class Event < ApplicationRecord
|
484
|
-
attribute :duration, :interval
|
485
|
-
end
|
486
|
-
|
487
|
-
Event.create!(name: 'Rock Fest', duration: 2.days)
|
488
|
-
Event.last.duration # => 2 days
|
489
|
-
Event.last.duration.iso8601 # => "P2D"
|
490
|
-
Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
|
491
|
-
Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
|
492
|
-
|
493
|
-
*Andrey Novikov*
|
494
|
-
|
495
|
-
* Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
|
496
|
-
|
497
160
|
```ruby
|
498
|
-
|
499
|
-
|
500
|
-
end
|
161
|
+
GET /books
|
162
|
+
# SELECT * FROM books /*application:MyApp;controller:books;action:index*/
|
501
163
|
```
|
502
164
|
|
503
|
-
|
504
|
-
|
505
|
-
*DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
|
506
|
-
|
507
|
-
* Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
|
508
|
-
|
509
|
-
*Jason Schweier*
|
510
|
-
|
511
|
-
* `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
|
512
|
-
|
513
|
-
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.
|
514
|
-
|
515
|
-
*Eileen M. Uchitelle*, *John Crepezzi*
|
516
|
-
|
517
|
-
* All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
518
|
-
`ActiveRecord::StatementInvalid` when they encounter a connection error.
|
519
|
-
|
520
|
-
*Jean Boussier*
|
521
|
-
|
522
|
-
* `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
523
|
-
`ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
|
524
|
-
|
525
|
-
*Jean Boussier*
|
526
|
-
|
527
|
-
* Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
|
528
|
-
|
529
|
-
*Alex Robbin*
|
530
|
-
|
531
|
-
* Ensure the default configuration is considered primary or first for an environment
|
532
|
-
|
533
|
-
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.
|
534
|
-
|
535
|
-
*Eileen M. Uchitelle*
|
536
|
-
|
537
|
-
* Allow `where` references association names as joined table name aliases.
|
165
|
+
Custom tags containing static values and Procs can be defined in the application configuration:
|
538
166
|
|
539
167
|
```ruby
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
168
|
+
config.active_record.query_log_tags = [
|
169
|
+
:application,
|
170
|
+
:controller,
|
171
|
+
:action,
|
172
|
+
{
|
173
|
+
custom_static: "foo",
|
174
|
+
custom_dynamic: -> { Time.now }
|
175
|
+
}
|
176
|
+
]
|
547
177
|
```
|
548
178
|
|
549
|
-
*
|
179
|
+
*Keeran Raj Hawoldar*, *Eileen M. Uchitelle*, *Kasper Timm Hansen*
|
550
180
|
|
551
|
-
*
|
181
|
+
* Added support for multiple databases to `rails db:setup` and `rails db:reset`.
|
552
182
|
|
553
|
-
|
554
|
-
by `store_full_sti_class` class attribute.
|
183
|
+
*Ryan Hall*
|
555
184
|
|
556
|
-
|
185
|
+
* Add `ActiveRecord::Relation#structurally_compatible?`.
|
557
186
|
|
558
|
-
|
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.
|
559
190
|
|
560
|
-
*
|
561
|
-
`rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
|
562
|
-
depending on `config.active_record.schema_format` configuration value.
|
191
|
+
*Kevin Newton*
|
563
192
|
|
564
|
-
|
193
|
+
* Add `ActiveRecord::QueryMethods#in_order_of`.
|
565
194
|
|
566
|
-
|
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:
|
567
198
|
|
568
199
|
```ruby
|
569
|
-
|
570
|
-
post.title # => "WELCOME TO THE WEBLOG"
|
571
|
-
post.body # => ActiveModel::MissingAttributeError
|
572
|
-
|
573
|
-
# Rails 6.0 (ignore the `select` values)
|
574
|
-
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
575
|
-
post.title # => "Welcome to the weblog"
|
576
|
-
post.body # => "Such a lovely day"
|
577
|
-
|
578
|
-
# Rails 6.1 (respect the `select` values)
|
579
|
-
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
580
|
-
post.title # => "WELCOME TO THE WEBLOG"
|
581
|
-
post.body # => ActiveModel::MissingAttributeError
|
200
|
+
Post.in_order_of(:id, [3, 5, 1])
|
582
201
|
```
|
583
202
|
|
584
|
-
|
585
|
-
|
586
|
-
* Allow attribute's default to be configured but keeping its own type.
|
203
|
+
will generate the SQL:
|
587
204
|
|
588
|
-
```
|
589
|
-
|
590
|
-
attribute :written_at, default: -> { Time.now.utc }
|
591
|
-
end
|
592
|
-
|
593
|
-
# Rails 6.0
|
594
|
-
Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
|
595
|
-
|
596
|
-
# Rails 6.1
|
597
|
-
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
|
598
207
|
```
|
599
208
|
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
```ruby
|
605
|
-
class Book < ActiveRecord::Base
|
606
|
-
enum status: [:proposed, :written, :published], _default: :published
|
607
|
-
end
|
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:
|
608
212
|
|
609
|
-
|
213
|
+
```sql
|
214
|
+
SELECT "posts".* FROM "posts" ORDER BY FIELD("posts"."id", 1, 5, 3) DESC
|
610
215
|
```
|
611
216
|
|
612
|
-
*
|
613
|
-
|
614
|
-
* Deprecate YAML loading from legacy format older than Rails 5.0.
|
615
|
-
|
616
|
-
*Ryuta Kamizono*
|
617
|
-
|
618
|
-
* Added the setting `ActiveRecord::Base.immutable_strings_by_default`, which
|
619
|
-
allows you to specify that all string columns should be frozen unless
|
620
|
-
otherwise specified. This will reduce memory pressure for applications which
|
621
|
-
do not generally mutate string properties of Active Record objects.
|
217
|
+
*Kevin Newton*
|
622
218
|
|
623
|
-
|
219
|
+
* Fix `eager_loading?` when ordering with `Symbol`.
|
624
220
|
|
625
|
-
|
626
|
-
|
627
|
-
*Ryuta Kamizono*
|
628
|
-
|
629
|
-
* Support `relation.and` for intersection as Set theory.
|
221
|
+
`eager_loading?` is triggered correctly when using `order` with symbols.
|
630
222
|
|
631
223
|
```ruby
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
david_and_mary.merge(mary_and_bob) # => [mary, bob]
|
636
|
-
|
637
|
-
david_and_mary.and(mary_and_bob) # => [mary]
|
638
|
-
david_and_mary.or(mary_and_bob) # => [david, mary, bob]
|
639
|
-
```
|
640
|
-
|
641
|
-
*Ryuta Kamizono*
|
642
|
-
|
643
|
-
* Merging conditions on the same column no longer maintain both conditions,
|
644
|
-
and will be consistently replaced by the latter condition in Rails 6.2.
|
645
|
-
To migrate to Rails 6.2's behavior, use `relation.merge(other, rewhere: true)`.
|
646
|
-
|
647
|
-
```ruby
|
648
|
-
# Rails 6.1 (IN clause is replaced by merger side equality condition)
|
649
|
-
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
650
|
-
|
651
|
-
# Rails 6.1 (both conflict conditions exists, deprecated)
|
652
|
-
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
|
653
|
-
|
654
|
-
# Rails 6.1 with rewhere to migrate to Rails 6.2's behavior
|
655
|
-
Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
|
656
|
-
|
657
|
-
# Rails 6.2 (same behavior with IN clause, mergee side condition is consistently replaced)
|
658
|
-
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
659
|
-
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
|
224
|
+
scope = Post.includes(:comments).order(:"comments.label")
|
225
|
+
=> true
|
660
226
|
```
|
661
227
|
|
662
|
-
*
|
663
|
-
|
664
|
-
* Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
|
665
|
-
|
666
|
-
*Peter Fry*
|
667
|
-
|
668
|
-
* Resolve issue with insert_all unique_by option when used with expression index.
|
228
|
+
*Jacopo Beschi*
|
669
229
|
|
670
|
-
|
671
|
-
`ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
|
672
|
-
was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
|
673
|
-
|
674
|
-
Usage:
|
675
|
-
|
676
|
-
```ruby
|
677
|
-
create_table :books, id: :integer, force: true do |t|
|
678
|
-
t.column :name, :string
|
679
|
-
t.index "lower(name)", unique: true
|
680
|
-
end
|
230
|
+
* Two change tracking methods are added for `belongs_to` associations.
|
681
231
|
|
682
|
-
|
683
|
-
|
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.
|
684
235
|
|
685
|
-
|
236
|
+
The `association_previously_changed?` method returns true if the previous save updated the
|
237
|
+
association to reference a different associated object.
|
686
238
|
|
687
|
-
*
|
239
|
+
*George Claghorn*
|
688
240
|
|
689
|
-
* Add
|
241
|
+
* Add option to disable schema dump per-database.
|
690
242
|
|
691
|
-
|
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:
|
692
245
|
|
693
|
-
```
|
694
|
-
|
695
|
-
|
246
|
+
```yaml
|
247
|
+
# config/database.yml
|
248
|
+
|
249
|
+
production:
|
250
|
+
schema_dump: false
|
696
251
|
```
|
697
252
|
|
698
|
-
*
|
253
|
+
*Luis Vasconcellos*, *Eileen M. Uchitelle*
|
699
254
|
|
700
|
-
*
|
701
|
-
to enable/disable strict_loading mode by default for a model. The configuration's value is
|
702
|
-
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.
|
703
256
|
|
704
|
-
|
257
|
+
`eager_loading?` is triggered correctly when using `order` with hash syntax
|
258
|
+
on an outer table.
|
705
259
|
|
706
260
|
```ruby
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
has_many :projects
|
711
|
-
end
|
712
|
-
|
713
|
-
dev = Developer.first
|
714
|
-
dev.projects.first
|
715
|
-
# => 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
|
716
263
|
```
|
717
264
|
|
718
|
-
*
|
265
|
+
*Jacopo Beschi*
|
719
266
|
|
720
|
-
*
|
721
|
-
|
722
|
-
*Ryuta Kamizono*
|
267
|
+
* Move the forcing of clear text encoding to the `ActiveRecord::Encryption::Encryptor`.
|
723
268
|
|
724
|
-
|
269
|
+
Fixes #42699.
|
725
270
|
|
726
|
-
|
271
|
+
*J Smith*
|
727
272
|
|
728
|
-
|
729
|
-
create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
|
730
|
-
end
|
731
|
-
```
|
273
|
+
* `partial_inserts` is now disabled by default in new apps.
|
732
274
|
|
733
|
-
|
275
|
+
This will be the default for new apps in Rails 7. To opt in:
|
734
276
|
|
735
277
|
```ruby
|
736
|
-
|
737
|
-
end
|
278
|
+
config.active_record.partial_inserts = true
|
738
279
|
```
|
739
280
|
|
740
|
-
|
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.
|
741
283
|
|
742
|
-
|
743
|
-
|
284
|
+
If you need to remove a column, you should first use `ignored_columns`
|
285
|
+
to stop using it.
|
744
286
|
|
745
|
-
*
|
287
|
+
*Jean Boussier*
|
746
288
|
|
747
|
-
*
|
289
|
+
* Rails can now verify foreign keys after loading fixtures in tests.
|
748
290
|
|
749
|
-
|
291
|
+
This will be the default for new apps in Rails 7. To opt in:
|
750
292
|
|
751
293
|
```ruby
|
752
|
-
|
753
|
-
|
754
|
-
# duplicated group fields, deprecated.
|
755
|
-
accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
|
756
|
-
# => {
|
757
|
-
# [1, 1] => 50,
|
758
|
-
# [2, 2] => 60
|
759
|
-
# }
|
760
|
-
|
761
|
-
# use `uniq!(:group)` to deduplicate group fields.
|
762
|
-
accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
|
763
|
-
# => {
|
764
|
-
# 1 => 50,
|
765
|
-
# 2 => 60
|
766
|
-
# }
|
294
|
+
config.active_record.verify_foreign_keys_for_fixtures = true
|
767
295
|
```
|
768
296
|
|
769
|
-
|
297
|
+
Tests will not run if there is a foreign key constraint violation in your fixture data.
|
298
|
+
|
299
|
+
The feature is supported by SQLite and PostgreSQL, other adapters can also add support for it.
|
770
300
|
|
771
|
-
*
|
301
|
+
*Alex Ghiculescu*
|
772
302
|
|
773
|
-
|
303
|
+
* Clear cached `has_one` association after setting `belongs_to` association to `nil`.
|
774
304
|
|
775
|
-
|
776
|
-
|
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.
|
777
307
|
|
778
|
-
#
|
779
|
-
accounts.merge(accounts.rewhere(id: 3))
|
780
|
-
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
|
308
|
+
Fixes #42597.
|
781
309
|
|
782
|
-
|
783
|
-
accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
|
784
|
-
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
|
785
|
-
```
|
310
|
+
*Michiel de Mare*
|
786
311
|
|
787
|
-
|
312
|
+
* OpenSSL constants are now used for Digest computations.
|
788
313
|
|
789
|
-
*
|
314
|
+
*Dirkjan Bussink*
|
790
315
|
|
791
|
-
|
792
|
-
cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
|
793
|
-
upon subsequent transactions by maintaining parity with the corresponding
|
794
|
-
database record's `lock_version` column.
|
316
|
+
* Adds support for `if_not_exists` to `add_foreign_key` and `if_exists` to `remove_foreign_key`.
|
795
317
|
|
796
|
-
|
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.
|
797
320
|
|
798
|
-
|
321
|
+
Example Usage:
|
799
322
|
|
800
|
-
|
323
|
+
```ruby
|
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
|
+
```
|
801
330
|
|
802
331
|
```ruby
|
803
|
-
|
332
|
+
class RemoveAuthorsForeignKeyFromArticles < ActiveRecord::Migration[7.0]
|
333
|
+
def change
|
334
|
+
remove_foreign_key :articles, :authors, if_exists: true
|
335
|
+
end
|
336
|
+
end
|
337
|
+
```
|
804
338
|
|
805
|
-
|
806
|
-
david_and_mary.merge(Author.where(id: bob)) # => []
|
339
|
+
*Roberto Miranda*
|
807
340
|
|
808
|
-
|
809
|
-
david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
|
341
|
+
* Prevent polluting ENV during postgresql structure dump/load.
|
810
342
|
|
811
|
-
|
812
|
-
|
813
|
-
|
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.
|
814
348
|
|
815
|
-
*
|
349
|
+
*Samuel Cochran*
|
816
350
|
|
817
|
-
*
|
818
|
-
set to expire and scoped with a purpose. This is particularly useful for things like password reset
|
819
|
-
or email verification, where you want the bearer of the signed id to be able to interact with the
|
820
|
-
underlying record, but usually only within a certain time period.
|
351
|
+
* Set precision 6 by default for `datetime` columns.
|
821
352
|
|
822
|
-
|
823
|
-
signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
|
353
|
+
By default, datetime columns will have microseconds precision instead of seconds precision.
|
824
354
|
|
825
|
-
|
355
|
+
*Roberto Miranda*
|
826
356
|
|
827
|
-
|
828
|
-
User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
|
357
|
+
* Allow preloading of associations with instance dependent scopes.
|
829
358
|
|
830
|
-
|
831
|
-
User.find_signed signed_id, purpose: :password_reset # => User.first
|
359
|
+
*John Hawthorn*, *John Crepezzi*, *Adam Hess*, *Eileen M. Uchitelle*, *Dinah Shi*
|
832
360
|
|
833
|
-
|
834
|
-
```
|
361
|
+
* Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
|
835
362
|
|
836
|
-
*
|
363
|
+
*Jamie McCarthy*
|
837
364
|
|
838
|
-
*
|
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.
|
839
369
|
|
840
|
-
|
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`.
|
841
372
|
|
842
|
-
*
|
373
|
+
*Jorge Manrubia*
|
843
374
|
|
844
|
-
|
375
|
+
* The MySQL adapter now cast numbers and booleans bind parameters to string for safety reasons.
|
845
376
|
|
846
|
-
|
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.
|
847
380
|
|
848
|
-
|
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:
|
849
383
|
|
850
384
|
```ruby
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
posts.count
|
855
|
-
# => { false => 10 }
|
385
|
+
User.where("login_token = ?", 0).first
|
386
|
+
```
|
856
387
|
|
857
|
-
|
858
|
-
posts.unscope(where: :hidden).count
|
859
|
-
# => { false => 11, true => 1 }
|
388
|
+
Would perform:
|
860
389
|
|
861
|
-
|
862
|
-
|
863
|
-
# => { false => 11 }
|
390
|
+
```sql
|
391
|
+
SELECT * FROM `users` WHERE `login_token` = 0 LIMIT 1;
|
864
392
|
```
|
865
393
|
|
866
|
-
|
394
|
+
Now it will perform:
|
867
395
|
|
868
|
-
|
396
|
+
```sql
|
397
|
+
SELECT * FROM `users` WHERE `login_token` = '0' LIMIT 1;
|
398
|
+
```
|
869
399
|
|
870
|
-
|
871
|
-
steve = Person.find_by(name: "Steve")
|
872
|
-
david = Author.find_by(name: "David")
|
400
|
+
*Jean Boussier*
|
873
401
|
|
874
|
-
|
402
|
+
* Fixture configurations (`_fixture`) are now strictly validated.
|
875
403
|
|
876
|
-
|
877
|
-
|
404
|
+
If an error will be raised if that entry contains unknown keys while previously it
|
405
|
+
would silently have no effects.
|
878
406
|
|
879
|
-
|
880
|
-
relation.rewhere(writer: david).to_a # => [david]
|
881
|
-
```
|
407
|
+
*Jean Boussier*
|
882
408
|
|
883
|
-
|
409
|
+
* Add `ActiveRecord::Base.update!` that works like `ActiveRecord::Base.update` but raises exceptions.
|
884
410
|
|
885
|
-
|
411
|
+
This allows for the same behavior as the instance method `#update!` at a class level.
|
886
412
|
|
887
413
|
```ruby
|
888
|
-
|
889
|
-
=> #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
|
414
|
+
Person.update!(:all, state: "confirmed")
|
890
415
|
```
|
891
416
|
|
892
|
-
*
|
417
|
+
*Dorian Marié*
|
893
418
|
|
894
|
-
*
|
419
|
+
* Add `ActiveRecord::Base#attributes_for_database`.
|
895
420
|
|
896
|
-
|
421
|
+
Returns attributes with values for assignment to the database.
|
897
422
|
|
898
|
-
*
|
423
|
+
*Chris Salzberg*
|
899
424
|
|
900
|
-
|
425
|
+
* Use an empty query to check if the PostgreSQL connection is still active.
|
901
426
|
|
902
|
-
|
427
|
+
An empty query is faster than `SELECT 1`.
|
903
428
|
|
904
|
-
*
|
429
|
+
*Heinrich Lee Yu*
|
905
430
|
|
906
|
-
*
|
431
|
+
* Add `ActiveRecord::Base#previously_persisted?`.
|
907
432
|
|
908
|
-
|
433
|
+
Returns `true` if the object has been previously persisted but now it has been deleted.
|
909
434
|
|
910
|
-
*
|
435
|
+
* Deprecate `partial_writes` in favor of `partial_inserts` and `partial_updates`.
|
911
436
|
|
912
|
-
|
437
|
+
This allows to have a different behavior on update and create.
|
913
438
|
|
914
|
-
*
|
439
|
+
*Jean Boussier*
|
915
440
|
|
916
|
-
*
|
441
|
+
* Fix compatibility with `psych >= 4`.
|
917
442
|
|
918
|
-
|
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.
|
919
445
|
|
920
|
-
*
|
446
|
+
*Jean Boussier*
|
921
447
|
|
922
|
-
|
448
|
+
* `ActiveRecord::Base.logger` is now a `class_attribute`.
|
923
449
|
|
924
|
-
|
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.
|
925
452
|
|
926
|
-
*
|
453
|
+
*Jean Boussier*
|
927
454
|
|
928
|
-
|
929
|
-
index won't be added.
|
455
|
+
* Add `.asc.nulls_first` for all databases. Unfortunately MySQL still doesn't like `nulls_last`.
|
930
456
|
|
931
|
-
|
457
|
+
*Keenan Brock*
|
932
458
|
|
933
|
-
|
934
|
-
|
935
|
-
|
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.
|
936
467
|
|
937
|
-
|
938
|
-
|
939
|
-
|
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.
|
940
474
|
|
941
|
-
*
|
475
|
+
*Eileen M. Uchitelle*
|
476
|
+
|
477
|
+
* Log a warning message when running SQLite in production.
|
942
478
|
|
943
|
-
|
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.
|
944
482
|
|
945
|
-
|
483
|
+
The warning can be disabled by setting `config.active_record.sqlite3_production_warning=false`.
|
946
484
|
|
947
|
-
*
|
485
|
+
*Jacopo Beschi*
|
948
486
|
|
949
|
-
|
487
|
+
* Add option to disable joins for `has_one` associations.
|
950
488
|
|
951
|
-
|
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.
|
952
492
|
|
953
|
-
|
493
|
+
Set the option on a has one through association:
|
954
494
|
|
955
495
|
```ruby
|
956
|
-
Person
|
957
|
-
|
496
|
+
class Person
|
497
|
+
belongs_to :dog
|
498
|
+
has_one :veterinarian, through: :dog, disable_joins: true
|
958
499
|
end
|
959
500
|
```
|
960
501
|
|
961
|
-
|
502
|
+
Then instead of generating join SQL, two queries are used for `@person.veterinarian`:
|
962
503
|
|
963
|
-
|
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
|
+
```
|
964
508
|
|
965
|
-
|
509
|
+
*Sarah Vessels*, *Eileen M. Uchitelle*
|
966
510
|
|
967
|
-
|
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.
|
968
514
|
|
969
|
-
*
|
515
|
+
*Mike Dalessio*
|
970
516
|
|
971
|
-
|
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`.
|
972
521
|
|
973
|
-
*
|
522
|
+
*Mike Dalessio*
|
974
523
|
|
975
|
-
* `
|
524
|
+
* Optimize `remove_columns` to use a single SQL statement.
|
976
525
|
|
977
|
-
|
526
|
+
```ruby
|
527
|
+
remove_columns :my_table, :col_one, :col_two
|
528
|
+
```
|
978
529
|
|
979
|
-
|
530
|
+
Now results in the following SQL:
|
980
531
|
|
981
|
-
|
532
|
+
```sql
|
533
|
+
ALTER TABLE "my_table" DROP COLUMN "col_one", DROP COLUMN "col_two"
|
534
|
+
```
|
982
535
|
|
983
|
-
*
|
536
|
+
*Jon Dufresne*
|
984
537
|
|
985
|
-
|
538
|
+
* Ensure `has_one` autosave association callbacks get called once.
|
986
539
|
|
987
|
-
|
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`.
|
988
543
|
|
989
|
-
*
|
544
|
+
*Petrik de Heus*
|
990
545
|
|
991
|
-
*
|
546
|
+
* Add option to disable joins for associations.
|
992
547
|
|
993
|
-
|
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.
|
994
551
|
|
995
|
-
|
552
|
+
Set the option on a has many through association:
|
996
553
|
|
997
|
-
|
554
|
+
```ruby
|
555
|
+
class Dog
|
556
|
+
has_many :treats, through: :humans, disable_joins: true
|
557
|
+
has_many :humans
|
558
|
+
end
|
559
|
+
```
|
998
560
|
|
999
|
-
|
561
|
+
Then instead of generating join SQL, two queries are used for `@dog.treats`:
|
1000
562
|
|
1001
|
-
|
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
|
+
```
|
1002
567
|
|
1003
|
-
*
|
568
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*, *Lee Quarella*
|
1004
569
|
|
1005
|
-
|
570
|
+
* Add setting for enumerating column names in SELECT statements.
|
1006
571
|
|
1007
|
-
|
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.
|
1008
575
|
|
1009
|
-
|
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.
|
1010
579
|
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
primary_shard_one:
|
1017
|
-
database: my_database_shard_one
|
580
|
+
Before:
|
581
|
+
|
582
|
+
```ruby
|
583
|
+
Book.limit(5)
|
584
|
+
# SELECT * FROM books LIMIT 5
|
1018
585
|
```
|
1019
586
|
|
1020
|
-
|
587
|
+
After:
|
1021
588
|
|
1022
589
|
```ruby
|
1023
|
-
|
1024
|
-
|
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
|
1025
596
|
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
597
|
+
# or, configure per-model
|
598
|
+
class Book < ApplicationRecord
|
599
|
+
self.enumerate_columns_in_select_statements = true
|
600
|
+
end
|
1030
601
|
```
|
1031
602
|
|
1032
|
-
Swap between shards in your controller / model code:
|
1033
|
-
|
1034
603
|
```ruby
|
1035
|
-
|
1036
|
-
|
1037
|
-
end
|
604
|
+
Book.limit(5)
|
605
|
+
# SELECT id, author_id, name, format, status, language, etc FROM books LIMIT 5
|
1038
606
|
```
|
1039
607
|
|
1040
|
-
|
608
|
+
*Matt Duszynski*
|
1041
609
|
|
1042
|
-
|
610
|
+
* Allow passing SQL as `on_duplicate` value to `#upsert_all` to make it possible to use raw SQL to update columns on conflict:
|
1043
611
|
|
1044
|
-
|
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
|
+
```
|
1045
618
|
|
1046
|
-
|
619
|
+
*Vladimir Dementyev*
|
1047
620
|
|
1048
|
-
|
621
|
+
* Allow passing SQL as `returning` statement to `#upsert_all`:
|
1049
622
|
|
1050
623
|
```ruby
|
1051
|
-
|
1052
|
-
|
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
|
+
)
|
1053
631
|
```
|
1054
632
|
|
1055
|
-
|
633
|
+
*Vladimir Dementyev*
|
1056
634
|
|
1057
|
-
|
1058
|
-
db_config = ActiveRecord::Base.configs_for(env_name: "development", name: "primary")
|
1059
|
-
db_config.name
|
1060
|
-
```
|
635
|
+
* Deprecate `legacy_connection_handling`.
|
1061
636
|
|
1062
637
|
*Eileen M. Uchitelle*
|
1063
638
|
|
1064
|
-
* Add
|
639
|
+
* Add attribute encryption support.
|
1065
640
|
|
1066
|
-
|
1067
|
-
|
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.
|
1068
646
|
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
rails db:drop:animals
|
1076
|
-
rails db:migrate
|
1077
|
-
rails db:migrate:primary
|
1078
|
-
rails db:migrate:animals
|
647
|
+
|
648
|
+
```ruby
|
649
|
+
class Person < ApplicationRecord
|
650
|
+
encrypts :name
|
651
|
+
encrypts :email_address, deterministic: true
|
652
|
+
end
|
1079
653
|
```
|
1080
654
|
|
1081
|
-
|
1082
|
-
|
655
|
+
You can learn more in the [Active Record Encryption
|
656
|
+
guide](https://edgeguides.rubyonrails.org/active_record_encryption.html).
|
1083
657
|
|
1084
|
-
|
1085
|
-
rails db:schema:dump
|
1086
|
-
rails db:schema:dump:primary
|
1087
|
-
rails db:schema:dump:animals
|
1088
|
-
rails db:schema:load
|
1089
|
-
rails db:schema:load:primary
|
1090
|
-
rails db:schema:load:animals
|
1091
|
-
rails db:structure:dump
|
1092
|
-
rails db:structure:dump:primary
|
1093
|
-
rails db:structure:dump:animals
|
1094
|
-
rails db:structure:load
|
1095
|
-
rails db:structure:load:primary
|
1096
|
-
rails db:structure:load:animals
|
1097
|
-
rails db:test:prepare
|
1098
|
-
rails db:test:prepare:primary
|
1099
|
-
rails db:test:prepare:animals
|
1100
|
-
```
|
658
|
+
*Jorge Manrubia*
|
1101
659
|
|
1102
|
-
|
660
|
+
* Changed Arel predications `contains` and `overlaps` to use
|
661
|
+
`quoted_node` so that PostgreSQL arrays are quoted properly.
|
1103
662
|
|
1104
|
-
*
|
663
|
+
*Bradley Priest*
|
1105
664
|
|
1106
|
-
|
665
|
+
* Add mode argument to record level `strict_loading!`.
|
1107
666
|
|
1108
|
-
|
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.
|
1109
669
|
|
1110
670
|
```ruby
|
1111
|
-
|
1112
|
-
has_many :projects, strict_loading: true
|
1113
|
-
end
|
671
|
+
developer.strict_loading!(mode: :n_plus_one_only)
|
1114
672
|
|
1115
|
-
|
1116
|
-
|
1117
|
-
# => 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
|
1118
675
|
```
|
1119
676
|
|
1120
|
-
|
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.
|
1121
681
|
|
1122
|
-
*
|
682
|
+
*Dinah Shi*
|
1123
683
|
|
1124
|
-
|
684
|
+
* Fix Float::INFINITY assignment to datetime column with postgresql adapter.
|
1125
685
|
|
1126
|
-
|
686
|
+
Before:
|
1127
687
|
|
1128
688
|
```ruby
|
1129
|
-
|
1130
|
-
|
1131
|
-
# => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
|
1132
|
-
```
|
689
|
+
# With this config
|
690
|
+
ActiveRecord::Base.time_zone_aware_attributes = true
|
1133
691
|
|
1134
|
-
|
692
|
+
# and the following schema:
|
693
|
+
create_table "postgresql_infinities" do |t|
|
694
|
+
t.datetime "datetime"
|
695
|
+
end
|
1135
696
|
|
1136
|
-
|
697
|
+
# This test fails
|
698
|
+
record = PostgresqlInfinity.create!(datetime: Float::INFINITY)
|
699
|
+
assert_equal Float::INFINITY, record.datetime # record.datetime gets nil
|
700
|
+
```
|
1137
701
|
|
1138
|
-
|
702
|
+
After this commit, `record.datetime` gets `Float::INFINITY` as expected.
|
1139
703
|
|
1140
|
-
*
|
704
|
+
*Shunichi Ikegami*
|
1141
705
|
|
1142
|
-
|
706
|
+
* Type cast enum values by the original attribute type.
|
1143
707
|
|
1144
|
-
|
708
|
+
The notable thing about this change is that unknown labels will no longer match 0 on MySQL.
|
1145
709
|
|
1146
710
|
```ruby
|
1147
|
-
class
|
1148
|
-
|
1149
|
-
add_column :posts, :title, :string, if_not_exists: true
|
1150
|
-
end
|
711
|
+
class Book < ActiveRecord::Base
|
712
|
+
enum :status, { proposed: 0, written: 1, published: 2 }
|
1151
713
|
end
|
1152
714
|
```
|
1153
715
|
|
716
|
+
Before:
|
717
|
+
|
1154
718
|
```ruby
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
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)
|
1160
724
|
```
|
1161
725
|
|
1162
|
-
|
1163
|
-
|
1164
|
-
* Regexp-escape table name for MS SQL Server.
|
1165
|
-
|
1166
|
-
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.
|
1167
|
-
|
1168
|
-
*Larry Reid*
|
1169
|
-
|
1170
|
-
* Store advisory locks on their own named connection.
|
726
|
+
After:
|
1171
727
|
|
1172
|
-
|
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
|
+
```
|
1173
733
|
|
1174
|
-
|
734
|
+
*Ryuta Kamizono*
|
1175
735
|
|
1176
|
-
|
736
|
+
* Fixtures for `has_many :through` associations now load timestamps on join tables.
|
1177
737
|
|
1178
|
-
|
738
|
+
Given this fixture:
|
1179
739
|
|
1180
|
-
|
740
|
+
```yml
|
741
|
+
### monkeys.yml
|
742
|
+
george:
|
743
|
+
name: George the Monkey
|
744
|
+
fruits: apple
|
1181
745
|
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
database: blog_development
|
1186
|
-
pool: 5
|
1187
|
-
schema_cache_path: tmp/schema/main.yml
|
746
|
+
### fruits.yml
|
747
|
+
apple:
|
748
|
+
name: apple
|
1188
749
|
```
|
1189
750
|
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
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.
|
1193
754
|
|
1194
|
-
|
1195
|
-
|
1196
|
-
*Eileen M. Uchitelle*, *John Crepezzi*
|
1197
|
-
|
1198
|
-
* Deprecate `#default_hash` and it's alias `#[]` on database configurations.
|
755
|
+
*Alex Ghiculescu*
|
1199
756
|
|
1200
|
-
|
757
|
+
* Allow applications to configure the thread pool for async queries.
|
1201
758
|
|
1202
|
-
|
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.
|
1203
763
|
|
1204
|
-
|
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.
|
1205
770
|
|
1206
|
-
*
|
771
|
+
*Eileen M. Uchitelle*
|
1207
772
|
|
1208
|
-
*
|
773
|
+
* Allow new syntax for `enum` to avoid leading `_` from reserved options.
|
1209
774
|
|
1210
775
|
Before:
|
1211
776
|
|
1212
777
|
```ruby
|
1213
|
-
|
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
|
1214
782
|
```
|
1215
783
|
|
1216
784
|
After:
|
1217
785
|
|
1218
786
|
```ruby
|
1219
|
-
|
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
|
1220
791
|
```
|
1221
792
|
|
1222
|
-
*
|
1223
|
-
|
1224
|
-
* Ensure `:reading` connections always raise if a write is attempted.
|
1225
|
-
|
1226
|
-
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`.
|
1227
|
-
|
1228
|
-
*Eileen M. Uchitelle*
|
1229
|
-
|
1230
|
-
* Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
|
1231
|
-
|
1232
|
-
`"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*
|
1233
794
|
|
1234
|
-
|
795
|
+
* Add `ActiveRecord::Relation#load_async`.
|
1235
796
|
|
1236
|
-
|
1237
|
-
support for casting floats using a database columns' precision value.
|
797
|
+
This method schedules the query to be performed asynchronously from a thread pool.
|
1238
798
|
|
1239
|
-
|
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.
|
1240
801
|
|
1241
|
-
|
1242
|
-
|
1243
|
-
ActionController::ConditionalGet to ensure that when collection cache versioning
|
1244
|
-
is enabled, requests using ConditionalGet don't return the same ETag header
|
1245
|
-
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.
|
1246
804
|
|
1247
|
-
|
805
|
+
```ruby
|
806
|
+
def index
|
807
|
+
@categories = Category.some_complex_scope.load_async
|
808
|
+
@posts = Post.some_complex_scope.load_async
|
809
|
+
end
|
810
|
+
```
|
1248
811
|
|
1249
|
-
|
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.
|
1250
815
|
|
1251
|
-
|
1252
|
-
|
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
|
+
```
|
1253
820
|
|
1254
|
-
|
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.
|
1255
824
|
|
1256
|
-
*
|
825
|
+
*Jean Boussier*
|
1257
826
|
|
1258
|
-
|
827
|
+
* Implemented `ActiveRecord::Relation#excluding` method.
|
1259
828
|
|
1260
|
-
|
829
|
+
This method excludes the specified record (or collection of records) from
|
830
|
+
the resulting relation:
|
1261
831
|
|
1262
832
|
```ruby
|
1263
|
-
|
1264
|
-
|
833
|
+
Post.excluding(post)
|
834
|
+
Post.excluding(post_one, post_two)
|
1265
835
|
```
|
1266
836
|
|
1267
|
-
|
837
|
+
Also works on associations:
|
1268
838
|
|
1269
839
|
```ruby
|
1270
|
-
|
1271
|
-
|
1272
|
-
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)
|
1273
842
|
```
|
1274
843
|
|
1275
|
-
|
1276
|
-
|
1277
|
-
* 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).
|
1278
846
|
|
1279
|
-
*
|
847
|
+
*Glen Crawford*
|
1280
848
|
|
1281
|
-
*
|
849
|
+
* Skip optimised #exist? query when #include? is called on a relation
|
850
|
+
with a having clause.
|
1282
851
|
|
1283
|
-
|
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.
|
1284
861
|
|
1285
|
-
|
862
|
+
A sample query affected by this problem:
|
1286
863
|
|
1287
|
-
|
1288
|
-
|
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
|
+
```
|
1289
871
|
|
1290
|
-
This change
|
1291
|
-
|
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.
|
1292
875
|
|
1293
|
-
|
876
|
+
Fixes #41417.
|
1294
877
|
|
1295
|
-
*
|
878
|
+
*Michael Smart*
|
1296
879
|
|
1297
|
-
|
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.
|
1298
883
|
|
1299
|
-
*
|
884
|
+
*wbharding*, *Martin Tepper*
|
1300
885
|
|
1301
|
-
|
886
|
+
* Add ability to apply `scoping` to `all_queries`.
|
1302
887
|
|
1303
|
-
|
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.
|
1304
891
|
|
1305
|
-
|
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
|
+
```
|
1306
897
|
|
1307
|
-
*Eileen M. Uchitelle
|
898
|
+
*Eileen M. Uchitelle*
|
1308
899
|
|
1309
|
-
*
|
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`.
|
1310
904
|
|
1311
|
-
|
905
|
+
Integers are handled as a special case returning `BigDecimal` always
|
906
|
+
(this was the case before already).
|
1312
907
|
|
1313
|
-
|
908
|
+
```ruby
|
909
|
+
# With the following schema:
|
910
|
+
create_table "measurements" do |t|
|
911
|
+
t.float "temperature"
|
912
|
+
end
|
1314
913
|
|
1315
|
-
|
914
|
+
# Before:
|
915
|
+
Measurement.average(:temperature).class
|
916
|
+
# => BigDecimal
|
1316
917
|
|
1317
|
-
|
918
|
+
# After:
|
919
|
+
Measurement.average(:temperature).class
|
920
|
+
# => Float
|
921
|
+
```
|
1318
922
|
|
1319
|
-
|
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).
|
1320
927
|
|
1321
|
-
*
|
928
|
+
*Josua Schmid*
|
1322
929
|
|
1323
|
-
|
930
|
+
* PostgreSQL: introduce `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type`.
|
1324
931
|
|
1325
|
-
|
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.
|
1326
937
|
|
1327
|
-
|
938
|
+
You should run `bin/rails db:migrate` to rebuild your schema.rb if you change this.
|
1328
939
|
|
1329
|
-
*
|
940
|
+
*Alex Ghiculescu*
|
1330
941
|
|
1331
|
-
|
942
|
+
* PostgreSQL: handle `timestamp with time zone` columns correctly in `schema.rb`.
|
1332
943
|
|
1333
|
-
|
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.
|
1334
946
|
|
1335
|
-
*
|
947
|
+
*Alex Ghiculescu*
|
1336
948
|
|
1337
|
-
*
|
1338
|
-
|
949
|
+
* Removing trailing whitespace when matching columns in
|
950
|
+
`ActiveRecord::Sanitization.disallow_raw_sql!`.
|
1339
951
|
|
1340
|
-
|
952
|
+
*Gannon McGibbon*, *Adrian Hirt*
|
1341
953
|
|
1342
|
-
|
1343
|
-
has_secure_token :auth_token
|
1344
|
-
```
|
954
|
+
* Expose a way for applications to set a `primary_abstract_class`.
|
1345
955
|
|
1346
|
-
|
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`.
|
1347
958
|
|
1348
959
|
```ruby
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
960
|
+
class PrimaryApplicationRecord
|
961
|
+
self.primary_abstract_class
|
962
|
+
end
|
1352
963
|
```
|
1353
964
|
|
1354
|
-
|
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.
|
1355
970
|
|
1356
|
-
*
|
1357
|
-
|
1358
|
-
*Eileen Uchitelle*, *John Crepezzi*
|
971
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1359
972
|
|
1360
|
-
*
|
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:
|
1361
978
|
|
1362
|
-
|
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
|
+
```
|
1363
984
|
|
1364
|
-
|
985
|
+
And also use it passing a hash, with one or more keys, where the key
|
986
|
+
is the adapter
|
1365
987
|
|
1366
|
-
|
988
|
+
```ruby
|
989
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = {
|
990
|
+
mysql2: ['--no-defaults', '--skip-add-drop-table'],
|
991
|
+
postgres: '--no-tablespaces'
|
992
|
+
}
|
993
|
+
```
|
1367
994
|
|
1368
|
-
|
995
|
+
*Gustavo Gonzalez*
|
1369
996
|
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
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.
|
1374
1001
|
|
1375
|
-
|
1002
|
+
Fixes #41137.
|
1376
1003
|
|
1377
|
-
|
1004
|
+
*Jonathan Bracy*
|
1378
1005
|
|
1379
|
-
|
1006
|
+
* Allow to opt-out of `strict_loading` mode on a per-record base.
|
1380
1007
|
|
1381
|
-
|
1008
|
+
This is useful when strict loading is enabled application wide or on a
|
1009
|
+
model level.
|
1382
1010
|
|
1383
|
-
|
1011
|
+
```ruby
|
1012
|
+
class User < ApplicationRecord
|
1013
|
+
has_many :bookmarks
|
1014
|
+
has_many :articles, strict_loading: true
|
1015
|
+
end
|
1384
1016
|
|
1385
|
-
|
1017
|
+
user = User.first
|
1018
|
+
user.articles # => ActiveRecord::StrictLoadingViolationError
|
1019
|
+
user.bookmarks # => #<ActiveRecord::Associations::CollectionProxy>
|
1386
1020
|
|
1387
|
-
|
1021
|
+
user.strict_loading!(true) # => true
|
1022
|
+
user.bookmarks # => ActiveRecord::StrictLoadingViolationError
|
1388
1023
|
|
1389
|
-
|
1024
|
+
user.strict_loading!(false) # => false
|
1025
|
+
user.bookmarks # => #<ActiveRecord::Associations::CollectionProxy>
|
1026
|
+
user.articles.strict_loading!(false) # => #<ActiveRecord::Associations::CollectionProxy>
|
1027
|
+
```
|
1390
1028
|
|
1391
|
-
|
1029
|
+
*Ayrton De Craene*
|
1392
1030
|
|
1393
|
-
|
1031
|
+
* Add `FinderMethods#sole` and `#find_sole_by` to find and assert the
|
1032
|
+
presence of exactly one record.
|
1394
1033
|
|
1395
|
-
|
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.
|
1396
1037
|
|
1397
|
-
|
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)
|
1398
1043
|
|
1399
|
-
|
1044
|
+
user.api_keys.find_sole_by(key: key)
|
1045
|
+
# as above
|
1046
|
+
```
|
1400
1047
|
|
1401
|
-
*
|
1048
|
+
*Asherah Connor*
|
1402
1049
|
|
1403
|
-
|
1050
|
+
* Makes `ActiveRecord::AttributeMethods::Query` respect the getter overrides defined in the model.
|
1404
1051
|
|
1405
|
-
|
1052
|
+
Before:
|
1406
1053
|
|
1407
|
-
|
1054
|
+
```ruby
|
1055
|
+
class User
|
1056
|
+
def admin
|
1057
|
+
false # Overriding the getter to always return false
|
1058
|
+
end
|
1059
|
+
end
|
1408
1060
|
|
1409
|
-
|
1061
|
+
user = User.first
|
1062
|
+
user.update(admin: true)
|
1410
1063
|
|
1411
|
-
|
1064
|
+
user.admin # false (as expected, due to the getter overwrite)
|
1065
|
+
user.admin? # true (not expected, returned the DB column value)
|
1066
|
+
```
|
1412
1067
|
|
1413
|
-
|
1068
|
+
After this commit, `user.admin?` above returns false, as expected.
|
1414
1069
|
|
1415
|
-
|
1070
|
+
Fixes #40771.
|
1416
1071
|
|
1417
|
-
*
|
1072
|
+
*Felipe*
|
1418
1073
|
|
1419
|
-
|
1074
|
+
* Allow delegated_type to be specified primary_key and foreign_key.
|
1420
1075
|
|
1421
|
-
|
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.
|
1422
1080
|
|
1423
|
-
*
|
1081
|
+
*Ryota Egusa*
|
1424
1082
|
|
1425
|
-
*
|
1083
|
+
* Expose an `invert_where` method that will invert all scope conditions.
|
1426
1084
|
|
1427
|
-
|
1085
|
+
```ruby
|
1086
|
+
class User
|
1087
|
+
scope :active, -> { where(accepted: true, locked: false) }
|
1088
|
+
end
|
1428
1089
|
|
1429
|
-
|
1090
|
+
User.active
|
1091
|
+
# ... WHERE `accepted` = 1 AND `locked` = 0
|
1430
1092
|
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1093
|
+
User.active.invert_where
|
1094
|
+
# ... WHERE NOT (`accepted` = 1 AND `locked` = 0)
|
1095
|
+
```
|
1434
1096
|
|
1435
|
-
*
|
1097
|
+
*Kevin Deisz*
|
1436
1098
|
|
1437
|
-
*
|
1099
|
+
* Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
|
1438
1100
|
|
1439
|
-
|
1101
|
+
Previously, passing `false` would trigger the option validation logic
|
1102
|
+
to throw an error saying :polymorphic would not be a valid option.
|
1440
1103
|
|
1441
|
-
*
|
1104
|
+
*glaszig*
|
1442
1105
|
|
1443
|
-
|
1106
|
+
* Remove deprecated `database` kwarg from `connected_to`.
|
1444
1107
|
|
1445
|
-
*
|
1108
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1446
1109
|
|
1447
|
-
|
1110
|
+
* Allow adding nonnamed expression indexes to be revertible.
|
1448
1111
|
|
1449
|
-
|
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.
|
1450
1115
|
|
1451
|
-
|
1116
|
+
```ruby
|
1117
|
+
add_index(:items, "to_tsvector('english', description)")
|
1118
|
+
```
|
1452
1119
|
|
1453
|
-
|
1120
|
+
Fixes #40732.
|
1454
1121
|
|
1455
|
-
|
1122
|
+
*fatkodima*
|
1456
1123
|
|
1457
|
-
|
1124
|
+
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
1458
1125
|
|
1459
|
-
|
1126
|
+
Fixes #39065.
|
1460
1127
|
|
1461
|
-
|
1128
|
+
*Alex Ghiculescu*
|
1462
1129
|
|
1463
|
-
|
1130
|
+
* Add option to run `default_scope` on all queries.
|
1464
1131
|
|
1465
|
-
|
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`).
|
1466
1133
|
|
1467
|
-
|
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.
|
1468
1135
|
|
1469
|
-
|
1136
|
+
```ruby
|
1137
|
+
class Article < ApplicationRecord
|
1138
|
+
default_scope -> { where(blog_id: Current.blog.id) }, all_queries: true
|
1139
|
+
end
|
1140
|
+
```
|
1470
1141
|
|
1471
|
-
*
|
1142
|
+
*Eileen M. Uchitelle*
|
1472
1143
|
|
1473
|
-
*
|
1144
|
+
* Add `where.associated` to check for the presence of an association.
|
1474
1145
|
|
1475
|
-
|
1146
|
+
```ruby
|
1147
|
+
# Before:
|
1148
|
+
account.users.joins(:contact).where.not(contact_id: nil)
|
1476
1149
|
|
1477
|
-
|
1150
|
+
# After:
|
1151
|
+
account.users.where.associated(:contact)
|
1152
|
+
```
|
1478
1153
|
|
1479
|
-
|
1154
|
+
Also mirrors `where.missing`.
|
1480
1155
|
|
1481
|
-
*
|
1156
|
+
*Kasper Timm Hansen*
|
1482
1157
|
|
1483
|
-
* Allow
|
1158
|
+
* Allow constructors (`build_association` and `create_association`) on
|
1159
|
+
`has_one :through` associations.
|
1484
1160
|
|
1485
|
-
*
|
1161
|
+
*Santiago Perez Perret*
|
1486
1162
|
|
1487
1163
|
|
1488
|
-
Please check [6-
|
1164
|
+
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activerecord/CHANGELOG.md) for previous changes.
|