activerecord 6.0.0.beta2 → 6.0.2.rc1
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 +471 -9
- data/README.rdoc +3 -1
- data/lib/active_record.rb +0 -1
- data/lib/active_record/association_relation.rb +15 -6
- data/lib/active_record/associations.rb +4 -3
- data/lib/active_record/associations/association.rb +10 -2
- data/lib/active_record/associations/builder/association.rb +14 -18
- data/lib/active_record/associations/builder/belongs_to.rb +5 -2
- data/lib/active_record/associations/builder/collection_association.rb +5 -15
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +1 -1
- data/lib/active_record/associations/builder/has_many.rb +2 -0
- data/lib/active_record/associations/builder/has_one.rb +35 -1
- data/lib/active_record/associations/builder/singular_association.rb +2 -0
- data/lib/active_record/associations/collection_association.rb +6 -2
- data/lib/active_record/associations/collection_proxy.rb +2 -2
- data/lib/active_record/associations/has_many_through_association.rb +4 -11
- data/lib/active_record/associations/join_dependency.rb +14 -9
- data/lib/active_record/associations/join_dependency/join_association.rb +12 -3
- data/lib/active_record/associations/preloader.rb +13 -8
- data/lib/active_record/associations/preloader/association.rb +34 -30
- data/lib/active_record/associations/preloader/through_association.rb +48 -28
- data/lib/active_record/attribute_methods.rb +3 -53
- data/lib/active_record/attribute_methods/before_type_cast.rb +4 -1
- data/lib/active_record/attribute_methods/dirty.rb +47 -14
- data/lib/active_record/attribute_methods/primary_key.rb +7 -15
- data/lib/active_record/attribute_methods/query.rb +2 -3
- data/lib/active_record/attribute_methods/read.rb +3 -9
- data/lib/active_record/attribute_methods/write.rb +6 -12
- data/lib/active_record/attributes.rb +13 -0
- data/lib/active_record/autosave_association.rb +21 -7
- data/lib/active_record/base.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +109 -11
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +8 -4
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +88 -61
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +6 -4
- data/lib/active_record/connection_adapters/abstract/quoting.rb +63 -6
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +4 -7
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +79 -22
- data/lib/active_record/connection_adapters/abstract/transaction.rb +12 -4
- data/lib/active_record/connection_adapters/abstract_adapter.rb +114 -34
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +78 -73
- data/lib/active_record/connection_adapters/column.rb +17 -13
- data/lib/active_record/connection_adapters/connection_specification.rb +2 -2
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +2 -2
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +48 -8
- data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +7 -5
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +10 -7
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +18 -5
- data/lib/active_record/connection_adapters/postgresql/column.rb +17 -30
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +8 -2
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +39 -2
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +34 -38
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +23 -27
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +68 -27
- data/lib/active_record/connection_adapters/schema_cache.rb +32 -14
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +120 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +38 -2
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +2 -2
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +66 -114
- data/lib/active_record/connection_handling.rb +31 -13
- data/lib/active_record/core.rb +23 -24
- data/lib/active_record/database_configurations.rb +73 -44
- data/lib/active_record/database_configurations/hash_config.rb +11 -11
- data/lib/active_record/database_configurations/url_config.rb +12 -12
- data/lib/active_record/dynamic_matchers.rb +1 -1
- data/lib/active_record/enum.rb +15 -0
- data/lib/active_record/errors.rb +1 -1
- data/lib/active_record/fixtures.rb +11 -6
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/insert_all.rb +179 -0
- data/lib/active_record/integration.rb +13 -1
- data/lib/active_record/internal_metadata.rb +5 -1
- data/lib/active_record/locking/optimistic.rb +3 -4
- data/lib/active_record/log_subscriber.rb +1 -1
- data/lib/active_record/middleware/database_selector.rb +3 -3
- data/lib/active_record/middleware/database_selector/resolver.rb +4 -6
- data/lib/active_record/migration.rb +62 -44
- data/lib/active_record/migration/command_recorder.rb +28 -14
- data/lib/active_record/migration/compatibility.rb +10 -0
- data/lib/active_record/model_schema.rb +3 -0
- data/lib/active_record/persistence.rb +206 -13
- data/lib/active_record/querying.rb +17 -12
- data/lib/active_record/railtie.rb +0 -1
- data/lib/active_record/railties/databases.rake +127 -25
- data/lib/active_record/reflection.rb +3 -3
- data/lib/active_record/relation.rb +99 -20
- data/lib/active_record/relation/calculations.rb +38 -40
- data/lib/active_record/relation/delegation.rb +22 -30
- data/lib/active_record/relation/finder_methods.rb +17 -12
- data/lib/active_record/relation/merger.rb +11 -16
- data/lib/active_record/relation/query_methods.rb +228 -76
- data/lib/active_record/relation/where_clause.rb +9 -5
- data/lib/active_record/sanitization.rb +33 -4
- data/lib/active_record/schema.rb +1 -1
- data/lib/active_record/schema_dumper.rb +10 -1
- data/lib/active_record/schema_migration.rb +1 -1
- data/lib/active_record/scoping/default.rb +6 -7
- data/lib/active_record/scoping/named.rb +3 -2
- data/lib/active_record/statement_cache.rb +2 -2
- data/lib/active_record/store.rb +48 -0
- data/lib/active_record/table_metadata.rb +9 -13
- data/lib/active_record/tasks/database_tasks.rb +109 -6
- data/lib/active_record/tasks/mysql_database_tasks.rb +3 -1
- data/lib/active_record/test_databases.rb +1 -16
- data/lib/active_record/test_fixtures.rb +1 -0
- data/lib/active_record/timestamp.rb +26 -16
- data/lib/active_record/touch_later.rb +4 -2
- data/lib/active_record/transactions.rb +56 -46
- data/lib/active_record/type_caster/connection.rb +16 -10
- data/lib/active_record/validations.rb +1 -0
- data/lib/active_record/validations/uniqueness.rb +3 -5
- data/lib/arel.rb +12 -5
- data/lib/arel/insert_manager.rb +3 -3
- data/lib/arel/nodes.rb +2 -1
- data/lib/arel/nodes/comment.rb +29 -0
- data/lib/arel/nodes/select_core.rb +16 -12
- data/lib/arel/nodes/unary.rb +1 -0
- data/lib/arel/nodes/values_list.rb +2 -17
- data/lib/arel/select_manager.rb +10 -10
- data/lib/arel/visitors/depth_first.rb +7 -2
- data/lib/arel/visitors/dot.rb +7 -2
- data/lib/arel/visitors/ibm_db.rb +13 -0
- data/lib/arel/visitors/informix.rb +6 -0
- data/lib/arel/visitors/mssql.rb +15 -1
- data/lib/arel/visitors/oracle12.rb +4 -5
- data/lib/arel/visitors/postgresql.rb +4 -10
- data/lib/arel/visitors/to_sql.rb +107 -131
- data/lib/arel/visitors/visitor.rb +9 -5
- data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -1
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
- metadata +16 -12
- data/lib/active_record/collection_cache_key.rb +0 -53
- data/lib/arel/nodes/values.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 458c4f148157e395ef92a5830397087711428bdb229ca9eea60cd405eec3af13
|
4
|
+
data.tar.gz: 940647c02f001e722bf339d93faf088f64747eb3c22be454a30dbec897cf136a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aed3b17f1ba36e57cac853c10e0c6f8ca43c2bbfb00acf58fcc73397e89ee4bca17513ae31ad76e35c06c98fc7e477a41095a3a0dd58febf93179d03db4fe9f3
|
7
|
+
data.tar.gz: 3bf1aa4541ca63aeb46c499a357f93a79d9b060e15360e6b15a93e70d68616716ece4529499cc970c9799166464ff2f14630ab030b9db5ef708a4f0295499dda
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,465 @@
|
|
1
|
+
## Rails 6.0.2.rc1 (November 27, 2019) ##
|
2
|
+
|
3
|
+
* Share the same connection pool for primary and replica databases in the
|
4
|
+
transactional tests for the same database.
|
5
|
+
|
6
|
+
*Edouard Chin*
|
7
|
+
|
8
|
+
* Fix the preloader when one record is fetched using `after_initialize`
|
9
|
+
but not the entire colection.
|
10
|
+
|
11
|
+
*Bradley Price*
|
12
|
+
|
13
|
+
* Fix collection callbacks not terminating when `:abort` is thrown.
|
14
|
+
|
15
|
+
*Edouard Chin*, *Ryuta Kamizono*
|
16
|
+
|
17
|
+
* Correctly deprecate `where.not` working as NOR for relations.
|
18
|
+
|
19
|
+
12a9664 deprecated where.not working as NOR, however
|
20
|
+
doing a relation query like `where.not(relation: { ... })`
|
21
|
+
wouldn't be properly deprecated and `where.not` would work as
|
22
|
+
NAND instead.
|
23
|
+
|
24
|
+
*Edouard Chin*
|
25
|
+
|
26
|
+
* Fix `db:migrate` task with multiple databases to restore the connection
|
27
|
+
to the previous database.
|
28
|
+
|
29
|
+
The migrate task iterates and establish a connection over each db
|
30
|
+
resulting in the last one to be used by subsequent rake tasks.
|
31
|
+
We should reestablish a connection to the connection that was
|
32
|
+
established before the migrate tasks was run
|
33
|
+
|
34
|
+
*Edouard Chin*
|
35
|
+
|
36
|
+
* Fix multi-threaded issue for `AcceptanceValidator`.
|
37
|
+
|
38
|
+
*Ryuta Kamizono*
|
39
|
+
|
40
|
+
|
41
|
+
## Rails 6.0.1 (November 5, 2019) ##
|
42
|
+
|
43
|
+
* Common Table Expressions are allowed on read-only connections.
|
44
|
+
|
45
|
+
*Chris Morris*
|
46
|
+
|
47
|
+
* New record instantiation respects `unscope`.
|
48
|
+
|
49
|
+
*Ryuta Kamizono*
|
50
|
+
|
51
|
+
* Fixed a case where `find_in_batches` could halt too early.
|
52
|
+
|
53
|
+
*Takayuki Nakata*
|
54
|
+
|
55
|
+
* Autosaved associations always perform validations when a custom validation
|
56
|
+
context is used.
|
57
|
+
|
58
|
+
*Tekin Suleyman*
|
59
|
+
|
60
|
+
* `sql.active_record` notifications now include the `:connection` in
|
61
|
+
their payloads.
|
62
|
+
|
63
|
+
*Eugene Kenny*
|
64
|
+
|
65
|
+
* A rollback encountered in an `after_commit` callback does not reset
|
66
|
+
previously-committed record state.
|
67
|
+
|
68
|
+
*Ryuta Kamizono*
|
69
|
+
|
70
|
+
* Fixed that join order was lost when eager-loading.
|
71
|
+
|
72
|
+
*Ryuta Kamizono*
|
73
|
+
|
74
|
+
* `DESCRIBE` queries are allowed on read-only connections.
|
75
|
+
|
76
|
+
*Dylan Thacker-Smith*
|
77
|
+
|
78
|
+
* Fixed that records that had been `inspect`ed could not be marshaled.
|
79
|
+
|
80
|
+
*Eugene Kenny*
|
81
|
+
|
82
|
+
* The connection pool reaper thread is respawned in forked processes. This
|
83
|
+
fixes that idle connections in forked processes wouldn't be reaped.
|
84
|
+
|
85
|
+
*John Hawthorn*
|
86
|
+
|
87
|
+
* The memoized result of `ActiveRecord::Relation#take` is properly cleared
|
88
|
+
when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
|
89
|
+
is called.
|
90
|
+
|
91
|
+
*Anmol Arora*
|
92
|
+
|
93
|
+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
|
94
|
+
|
95
|
+
*Hiroyuki Ishii*
|
96
|
+
|
97
|
+
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
|
98
|
+
|
99
|
+
*Eugene Kenny*
|
100
|
+
|
101
|
+
* Call `while_preventing_writes` directly from `connected_to`.
|
102
|
+
|
103
|
+
In some cases application authors want to use the database switching middleware and make explicit calls with `connected_to`. It's possible for an app to turn off writes and not turn them back on by the time we call `connected_to(role: :writing)`.
|
104
|
+
|
105
|
+
This change allows apps to fix this by assuming if a role is writing we want to allow writes, except in the case it's explicitly turned off.
|
106
|
+
|
107
|
+
*Eileen M. Uchitelle*
|
108
|
+
|
109
|
+
* Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
|
110
|
+
|
111
|
+
*Kir Shatrov*
|
112
|
+
|
113
|
+
|
114
|
+
## Rails 6.0.0 (August 16, 2019) ##
|
115
|
+
|
116
|
+
* Preserve user supplied joins order as much as possible.
|
117
|
+
|
118
|
+
Fixes #36761, #34328, #24281, #12953.
|
119
|
+
|
120
|
+
*Ryuta Kamizono*
|
121
|
+
|
122
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
123
|
+
|
124
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
125
|
+
|
126
|
+
* Add a warning for enum elements with 'not_' prefix.
|
127
|
+
|
128
|
+
class Foo
|
129
|
+
enum status: [:sent, :not_sent]
|
130
|
+
end
|
131
|
+
|
132
|
+
*Edu Depetris*
|
133
|
+
|
134
|
+
* Make currency symbols optional for money column type in PostgreSQL
|
135
|
+
|
136
|
+
*Joel Schneider*
|
137
|
+
|
138
|
+
|
139
|
+
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
140
|
+
|
141
|
+
* Add database_exists? method to connection adapters to check if a database exists.
|
142
|
+
|
143
|
+
*Guilherme Mansur*
|
144
|
+
|
145
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
146
|
+
|
147
|
+
Fixes #36022.
|
148
|
+
|
149
|
+
*Ryuta Kamizono*
|
150
|
+
|
151
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
152
|
+
|
153
|
+
Fixes #36465.
|
154
|
+
|
155
|
+
*Jeff Doering*
|
156
|
+
|
157
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
158
|
+
|
159
|
+
*Martin R. Schuster*
|
160
|
+
|
161
|
+
* Fix invalid schema when primary key column has a comment.
|
162
|
+
|
163
|
+
Fixes #29966.
|
164
|
+
|
165
|
+
*Guilherme Goettems Schneider*
|
166
|
+
|
167
|
+
* Fix table comment also being applied to the primary key column.
|
168
|
+
|
169
|
+
*Guilherme Goettems Schneider*
|
170
|
+
|
171
|
+
* Fix merging left_joins to maintain its own `join_type` context.
|
172
|
+
|
173
|
+
Fixes #36103.
|
174
|
+
|
175
|
+
*Ryuta Kamizono*
|
176
|
+
|
177
|
+
|
178
|
+
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
179
|
+
|
180
|
+
* Add `touch` option to `has_one` association.
|
181
|
+
|
182
|
+
*Abhay Nikam*
|
183
|
+
|
184
|
+
* Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
|
188
|
+
assert_equal all, PriceEstimate.all.map(&:estimate_of)
|
189
|
+
```
|
190
|
+
|
191
|
+
In Rails 6.0:
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
sapphire = treasures(:sapphire)
|
195
|
+
|
196
|
+
nor = all.reject { |e|
|
197
|
+
e.estimate_of_type == sapphire.class.polymorphic_name
|
198
|
+
}.reject { |e|
|
199
|
+
e.estimate_of_id == sapphire.id
|
200
|
+
}
|
201
|
+
assert_equal [cars(:honda)], nor
|
202
|
+
|
203
|
+
without_sapphire = PriceEstimate.where.not(
|
204
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
205
|
+
)
|
206
|
+
assert_equal nor, without_sapphire.map(&:estimate_of)
|
207
|
+
```
|
208
|
+
|
209
|
+
In Rails 6.1:
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
sapphire = treasures(:sapphire)
|
213
|
+
|
214
|
+
nand = all - [sapphire]
|
215
|
+
assert_equal [treasures(:diamond), cars(:honda)], nand
|
216
|
+
|
217
|
+
without_sapphire = PriceEstimate.where.not(
|
218
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
219
|
+
)
|
220
|
+
assert_equal nand, without_sapphire.map(&:estimate_of)
|
221
|
+
```
|
222
|
+
|
223
|
+
*Ryuta Kamizono*
|
224
|
+
|
225
|
+
* Fix dirty tracking after rollback.
|
226
|
+
|
227
|
+
Fixes #15018, #30167, #33868.
|
228
|
+
|
229
|
+
*Ryuta Kamizono*
|
230
|
+
|
231
|
+
* Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
|
232
|
+
the versioned entries in `ActiveSupport::Cache`. This also means that
|
233
|
+
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
234
|
+
include the max timestamp or count any more.
|
235
|
+
|
236
|
+
NOTE: This feature is turned off by default, and `cache_key` will still return
|
237
|
+
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
238
|
+
That's the setting for all new apps on Rails 6.0+
|
239
|
+
|
240
|
+
*Lachlan Sylvester*
|
241
|
+
|
242
|
+
* Fix dirty tracking for `touch` to track saved changes.
|
243
|
+
|
244
|
+
Fixes #33429.
|
245
|
+
|
246
|
+
*Ryuta Kamzono*
|
247
|
+
|
248
|
+
* `change_column_comment` and `change_table_comment` are invertible only if
|
249
|
+
`to` and `from` options are specified.
|
250
|
+
|
251
|
+
*Yoshiyuki Kinjo*
|
252
|
+
|
253
|
+
* Don't call commit/rollback callbacks when a record isn't saved.
|
254
|
+
|
255
|
+
Fixes #29747.
|
256
|
+
|
257
|
+
*Ryuta Kamizono*
|
258
|
+
|
259
|
+
* Fix circular `autosave: true` causes invalid records to be saved.
|
260
|
+
|
261
|
+
Prior to the fix, when there was a circular series of `autosave: true`
|
262
|
+
associations, the callback for a `has_many` association was run while
|
263
|
+
another instance of the same callback on the same association hadn't
|
264
|
+
finished running. When control returned to the first instance of the
|
265
|
+
callback, the instance variable had changed, and subsequent associated
|
266
|
+
records weren't saved correctly. Specifically, the ID field for the
|
267
|
+
`belongs_to` corresponding to the `has_many` was `nil`.
|
268
|
+
|
269
|
+
Fixes #28080.
|
270
|
+
|
271
|
+
*Larry Reid*
|
272
|
+
|
273
|
+
* Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
|
274
|
+
|
275
|
+
Before:
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
279
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
280
|
+
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
281
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
282
|
+
```
|
283
|
+
|
284
|
+
After:
|
285
|
+
|
286
|
+
```ruby
|
287
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
288
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
289
|
+
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
|
290
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
|
291
|
+
```
|
292
|
+
|
293
|
+
*Ryuta Kamizono*
|
294
|
+
|
295
|
+
* Association loading isn't to be affected by scoping consistently
|
296
|
+
whether preloaded / eager loaded or not, with the exception of `unscoped`.
|
297
|
+
|
298
|
+
Before:
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
Post.where("1=0").scoping do
|
302
|
+
Comment.find(1).post # => nil
|
303
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
304
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
305
|
+
end
|
306
|
+
```
|
307
|
+
|
308
|
+
After:
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
Post.where("1=0").scoping do
|
312
|
+
Comment.find(1).post # => #<Post id: 1, ...>
|
313
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
314
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
315
|
+
end
|
316
|
+
```
|
317
|
+
|
318
|
+
Fixes #34638, #35398.
|
319
|
+
|
320
|
+
*Ryuta Kamizono*
|
321
|
+
|
322
|
+
* Add `rails db:prepare` to migrate or setup a database.
|
323
|
+
|
324
|
+
Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
|
325
|
+
|
326
|
+
*Roberto Miranda*
|
327
|
+
|
328
|
+
* Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
|
329
|
+
|
330
|
+
*DHH*
|
331
|
+
|
332
|
+
* Assign all attributes before calling `build` to ensure the child record is visible in
|
333
|
+
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
334
|
+
|
335
|
+
Fixes #33249.
|
336
|
+
|
337
|
+
*Ryan H. Kerr*
|
338
|
+
|
339
|
+
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
|
340
|
+
|
341
|
+
```
|
342
|
+
account.memberships.extract_associated(:user)
|
343
|
+
# => Returns collection of User records
|
344
|
+
```
|
345
|
+
|
346
|
+
*DHH*
|
347
|
+
|
348
|
+
* Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
|
349
|
+
|
350
|
+
For example:
|
351
|
+
|
352
|
+
```
|
353
|
+
Post.where(id: 123).annotate("this is a comment").to_sql
|
354
|
+
# SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
|
355
|
+
```
|
356
|
+
|
357
|
+
This can be useful in instrumentation or other analysis of issued queries.
|
358
|
+
|
359
|
+
*Matt Yoho*
|
360
|
+
|
361
|
+
* Support Optimizer Hints.
|
362
|
+
|
363
|
+
In most databases, a way to control the optimizer is by using optimizer hints,
|
364
|
+
which can be specified within individual statements.
|
365
|
+
|
366
|
+
Example (for MySQL):
|
367
|
+
|
368
|
+
Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
|
369
|
+
# SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
|
370
|
+
|
371
|
+
Example (for PostgreSQL with pg_hint_plan):
|
372
|
+
|
373
|
+
Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
|
374
|
+
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
375
|
+
|
376
|
+
See also:
|
377
|
+
|
378
|
+
* https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
|
379
|
+
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
380
|
+
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
381
|
+
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
382
|
+
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
383
|
+
|
384
|
+
*Ryuta Kamizono*
|
385
|
+
|
386
|
+
* Fix query attribute method on user-defined attribute to be aware of typecasted value.
|
387
|
+
|
388
|
+
For example, the following code no longer return false as casted non-empty string:
|
389
|
+
|
390
|
+
```
|
391
|
+
class Post < ActiveRecord::Base
|
392
|
+
attribute :user_defined_text, :text
|
393
|
+
end
|
394
|
+
|
395
|
+
Post.new(user_defined_text: "false").user_defined_text? # => true
|
396
|
+
```
|
397
|
+
|
398
|
+
*Yuji Kamijima*
|
399
|
+
|
400
|
+
* Quote empty ranges like other empty enumerables.
|
401
|
+
|
402
|
+
*Patrick Rebsch*
|
403
|
+
|
404
|
+
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
|
405
|
+
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
406
|
+
bulk deletes by `delete_all`.
|
407
|
+
|
408
|
+
Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
|
409
|
+
for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
|
410
|
+
for MySQL.
|
411
|
+
|
412
|
+
*Bob Lail*
|
413
|
+
|
414
|
+
* Add `rails db:seed:replant` that truncates tables of each database
|
415
|
+
for current environment and loads the seeds.
|
416
|
+
|
417
|
+
*bogdanvlviv*, *DHH*
|
418
|
+
|
419
|
+
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
|
420
|
+
|
421
|
+
*bogdanvlviv*
|
422
|
+
|
423
|
+
* Deprecate mismatched collation comparison for uniqueness validator.
|
424
|
+
|
425
|
+
Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
|
426
|
+
To continue case sensitive comparison on the case insensitive column,
|
427
|
+
pass `case_sensitive: true` option explicitly to the uniqueness validator.
|
428
|
+
|
429
|
+
*Ryuta Kamizono*
|
430
|
+
|
431
|
+
* Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
|
432
|
+
|
433
|
+
Fixes #27340.
|
434
|
+
|
435
|
+
*Willian Gustavo Veiga*
|
436
|
+
|
437
|
+
* Add negative scopes for all enum values.
|
438
|
+
|
439
|
+
Example:
|
440
|
+
|
441
|
+
class Post < ActiveRecord::Base
|
442
|
+
enum status: %i[ drafted active trashed ]
|
443
|
+
end
|
444
|
+
|
445
|
+
Post.not_drafted # => where.not(status: :drafted)
|
446
|
+
Post.not_active # => where.not(status: :active)
|
447
|
+
Post.not_trashed # => where.not(status: :trashed)
|
448
|
+
|
449
|
+
*DHH*
|
450
|
+
|
451
|
+
* Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
|
452
|
+
|
453
|
+
Fixes #35214.
|
454
|
+
|
455
|
+
*Juani Villarejo*
|
456
|
+
|
457
|
+
|
458
|
+
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
459
|
+
|
460
|
+
* No changes.
|
461
|
+
|
462
|
+
|
1
463
|
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
2
464
|
|
3
465
|
* Fix prepared statements caching to be enabled even when query caching is enabled.
|
@@ -62,7 +524,7 @@
|
|
62
524
|
`GET` and `HEAD` requests will read from the replica unless there was
|
63
525
|
a write in the last 2 seconds, otherwise they will read from the primary.
|
64
526
|
Non-get requests will always write to the primary. The middleware accepts
|
65
|
-
an argument for a Resolver class and
|
527
|
+
an argument for a Resolver class and an Operations class where you are able
|
66
528
|
to change how the auto-switcher works to be most beneficial for your
|
67
529
|
application.
|
68
530
|
|
@@ -129,7 +591,7 @@
|
|
129
591
|
|
130
592
|
*Rafael Mendonça França*
|
131
593
|
|
132
|
-
* Deprecate `config.
|
594
|
+
* Deprecate `config.active_record.sqlite3.represent_boolean_as_integer`.
|
133
595
|
|
134
596
|
*Rafael Mendonça França*
|
135
597
|
|
@@ -217,7 +679,7 @@
|
|
217
679
|
|
218
680
|
*Gannon McGibbon*
|
219
681
|
|
220
|
-
* Cached columns_hash fields should be excluded from ResultSet#column_types
|
682
|
+
* Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
|
221
683
|
|
222
684
|
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
223
685
|
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
@@ -248,12 +710,12 @@
|
|
248
710
|
|
249
711
|
* Make the implicit order column configurable.
|
250
712
|
|
251
|
-
When calling ordered finder methods such as
|
713
|
+
When calling ordered finder methods such as `first` or `last` without an
|
252
714
|
explicit order clause, ActiveRecord sorts records by primary key. This can
|
253
715
|
result in unpredictable and surprising behaviour when the primary key is
|
254
716
|
not an auto-incrementing integer, for example when it's a UUID. This change
|
255
717
|
makes it possible to override the column used for implicit ordering such
|
256
|
-
that
|
718
|
+
that `first` and `last` will return more predictable results.
|
257
719
|
|
258
720
|
Example:
|
259
721
|
|
@@ -323,7 +785,7 @@
|
|
323
785
|
|
324
786
|
*Sean Griffin*
|
325
787
|
|
326
|
-
* Add support for hash and
|
788
|
+
* Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
|
327
789
|
|
328
790
|
````
|
329
791
|
User.connected_to(database: { writing: "postgres://foo" }) do
|
@@ -399,10 +861,10 @@
|
|
399
861
|
|
400
862
|
* Enum raises on invalid definition values
|
401
863
|
|
402
|
-
When defining a Hash enum it can be easy to use [] instead of {}
|
864
|
+
When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
|
403
865
|
commit checks that only valid definition values are provided, those can
|
404
866
|
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
405
|
-
raises an ArgumentError
|
867
|
+
raises an `ArgumentError`.
|
406
868
|
|
407
869
|
Fixes #33961
|
408
870
|
|
@@ -496,7 +958,7 @@
|
|
496
958
|
*Darwin Wu*
|
497
959
|
|
498
960
|
* Configuration item `config.filter_parameters` could also filter out
|
499
|
-
sensitive values of database columns when
|
961
|
+
sensitive values of database columns when calling `#inspect`.
|
500
962
|
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
501
963
|
specify sensitive attributes to specific model.
|
502
964
|
|