activerecord 6.0.0.beta1 → 6.0.0

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.

Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +455 -9
  3. data/README.rdoc +3 -1
  4. data/lib/active_record/associations/association.rb +18 -1
  5. data/lib/active_record/associations/builder/association.rb +14 -18
  6. data/lib/active_record/associations/builder/belongs_to.rb +5 -2
  7. data/lib/active_record/associations/builder/collection_association.rb +5 -15
  8. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +1 -1
  9. data/lib/active_record/associations/builder/has_many.rb +2 -0
  10. data/lib/active_record/associations/builder/has_one.rb +35 -1
  11. data/lib/active_record/associations/builder/singular_association.rb +2 -0
  12. data/lib/active_record/associations/collection_association.rb +5 -6
  13. data/lib/active_record/associations/collection_proxy.rb +13 -42
  14. data/lib/active_record/associations/has_many_association.rb +1 -9
  15. data/lib/active_record/associations/has_many_through_association.rb +4 -11
  16. data/lib/active_record/associations/join_dependency/join_association.rb +21 -7
  17. data/lib/active_record/associations/join_dependency.rb +10 -9
  18. data/lib/active_record/associations/preloader/association.rb +37 -34
  19. data/lib/active_record/associations/preloader/through_association.rb +48 -39
  20. data/lib/active_record/associations/preloader.rb +11 -6
  21. data/lib/active_record/associations.rb +3 -2
  22. data/lib/active_record/attribute_methods/before_type_cast.rb +4 -1
  23. data/lib/active_record/attribute_methods/dirty.rb +47 -14
  24. data/lib/active_record/attribute_methods/primary_key.rb +7 -15
  25. data/lib/active_record/attribute_methods/query.rb +2 -3
  26. data/lib/active_record/attribute_methods/read.rb +3 -9
  27. data/lib/active_record/attribute_methods/write.rb +6 -12
  28. data/lib/active_record/attribute_methods.rb +3 -53
  29. data/lib/active_record/attributes.rb +13 -0
  30. data/lib/active_record/autosave_association.rb +15 -5
  31. data/lib/active_record/base.rb +0 -1
  32. data/lib/active_record/callbacks.rb +3 -3
  33. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +124 -23
  34. data/lib/active_record/connection_adapters/abstract/database_limits.rb +8 -4
  35. data/lib/active_record/connection_adapters/abstract/database_statements.rb +101 -70
  36. data/lib/active_record/connection_adapters/abstract/query_cache.rb +11 -5
  37. data/lib/active_record/connection_adapters/abstract/quoting.rb +63 -6
  38. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +5 -2
  39. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +51 -40
  40. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -1
  41. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +95 -30
  42. data/lib/active_record/connection_adapters/abstract/transaction.rb +17 -6
  43. data/lib/active_record/connection_adapters/abstract_adapter.rb +108 -39
  44. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +93 -134
  45. data/lib/active_record/connection_adapters/column.rb +17 -13
  46. data/lib/active_record/connection_adapters/connection_specification.rb +1 -1
  47. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +3 -3
  48. data/lib/active_record/connection_adapters/mysql/database_statements.rb +45 -7
  49. data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
  50. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +40 -32
  51. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +14 -6
  52. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +66 -5
  53. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
  54. data/lib/active_record/connection_adapters/mysql2_adapter.rb +18 -5
  55. data/lib/active_record/connection_adapters/postgresql/column.rb +17 -30
  56. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +5 -1
  57. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
  58. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +1 -1
  59. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +6 -3
  60. data/lib/active_record/connection_adapters/postgresql/quoting.rb +40 -3
  61. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +36 -0
  62. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +98 -89
  63. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +47 -63
  64. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +23 -27
  65. data/lib/active_record/connection_adapters/postgresql_adapter.rb +91 -24
  66. data/lib/active_record/connection_adapters/schema_cache.rb +32 -14
  67. data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
  68. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +118 -0
  69. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +38 -2
  70. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +28 -2
  71. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +69 -118
  72. data/lib/active_record/connection_handling.rb +32 -16
  73. data/lib/active_record/core.rb +27 -20
  74. data/lib/active_record/database_configurations/hash_config.rb +11 -11
  75. data/lib/active_record/database_configurations/url_config.rb +21 -16
  76. data/lib/active_record/database_configurations.rb +99 -50
  77. data/lib/active_record/dynamic_matchers.rb +1 -1
  78. data/lib/active_record/enum.rb +15 -0
  79. data/lib/active_record/errors.rb +18 -13
  80. data/lib/active_record/fixtures.rb +11 -6
  81. data/lib/active_record/gem_version.rb +1 -1
  82. data/lib/active_record/inheritance.rb +1 -1
  83. data/lib/active_record/insert_all.rb +179 -0
  84. data/lib/active_record/integration.rb +13 -1
  85. data/lib/active_record/internal_metadata.rb +5 -1
  86. data/lib/active_record/locking/optimistic.rb +3 -4
  87. data/lib/active_record/log_subscriber.rb +1 -1
  88. data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
  89. data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
  90. data/lib/active_record/middleware/database_selector.rb +75 -0
  91. data/lib/active_record/migration/command_recorder.rb +28 -14
  92. data/lib/active_record/migration/compatibility.rb +72 -63
  93. data/lib/active_record/migration.rb +62 -44
  94. data/lib/active_record/persistence.rb +212 -19
  95. data/lib/active_record/querying.rb +18 -14
  96. data/lib/active_record/railtie.rb +9 -1
  97. data/lib/active_record/railties/collection_cache_association_loading.rb +3 -3
  98. data/lib/active_record/railties/databases.rake +124 -25
  99. data/lib/active_record/reflection.rb +18 -32
  100. data/lib/active_record/relation/calculations.rb +40 -44
  101. data/lib/active_record/relation/delegation.rb +23 -31
  102. data/lib/active_record/relation/finder_methods.rb +13 -13
  103. data/lib/active_record/relation/merger.rb +11 -16
  104. data/lib/active_record/relation/query_attribute.rb +5 -3
  105. data/lib/active_record/relation/query_methods.rb +217 -68
  106. data/lib/active_record/relation/spawn_methods.rb +1 -1
  107. data/lib/active_record/relation/where_clause.rb +10 -10
  108. data/lib/active_record/relation.rb +184 -35
  109. data/lib/active_record/sanitization.rb +33 -4
  110. data/lib/active_record/schema.rb +1 -1
  111. data/lib/active_record/schema_dumper.rb +10 -1
  112. data/lib/active_record/schema_migration.rb +1 -1
  113. data/lib/active_record/scoping/default.rb +7 -15
  114. data/lib/active_record/scoping/named.rb +10 -2
  115. data/lib/active_record/scoping.rb +6 -7
  116. data/lib/active_record/statement_cache.rb +2 -2
  117. data/lib/active_record/store.rb +48 -0
  118. data/lib/active_record/table_metadata.rb +9 -13
  119. data/lib/active_record/tasks/database_tasks.rb +109 -6
  120. data/lib/active_record/tasks/mysql_database_tasks.rb +3 -1
  121. data/lib/active_record/test_databases.rb +1 -16
  122. data/lib/active_record/test_fixtures.rb +2 -2
  123. data/lib/active_record/timestamp.rb +35 -19
  124. data/lib/active_record/touch_later.rb +4 -2
  125. data/lib/active_record/transactions.rb +55 -45
  126. data/lib/active_record/type_caster/connection.rb +16 -10
  127. data/lib/active_record/validations/uniqueness.rb +4 -4
  128. data/lib/active_record/validations.rb +1 -0
  129. data/lib/active_record.rb +7 -1
  130. data/lib/arel/insert_manager.rb +3 -3
  131. data/lib/arel/nodes/and.rb +1 -1
  132. data/lib/arel/nodes/case.rb +1 -1
  133. data/lib/arel/nodes/comment.rb +29 -0
  134. data/lib/arel/nodes/select_core.rb +16 -12
  135. data/lib/arel/nodes/unary.rb +1 -0
  136. data/lib/arel/nodes/values_list.rb +2 -17
  137. data/lib/arel/nodes.rb +2 -1
  138. data/lib/arel/select_manager.rb +10 -10
  139. data/lib/arel/visitors/depth_first.rb +7 -2
  140. data/lib/arel/visitors/dot.rb +7 -2
  141. data/lib/arel/visitors/ibm_db.rb +13 -0
  142. data/lib/arel/visitors/informix.rb +6 -0
  143. data/lib/arel/visitors/mssql.rb +15 -1
  144. data/lib/arel/visitors/oracle12.rb +4 -5
  145. data/lib/arel/visitors/postgresql.rb +4 -10
  146. data/lib/arel/visitors/to_sql.rb +107 -131
  147. data/lib/arel/visitors/visitor.rb +9 -5
  148. data/lib/arel.rb +7 -0
  149. data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -1
  150. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
  151. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
  152. data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
  153. data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
  154. metadata +17 -13
  155. data/lib/active_record/collection_cache_key.rb +0 -53
  156. data/lib/arel/nodes/values.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c6ced19e10b6f6d4eb33ac9745ce89e3b4ee124c02080e582abe07b9e5ac9a6
4
- data.tar.gz: d0267bc9be2b86eea525eebd296a3eba6dd098ae154c6ec6b91978164e91a898
3
+ metadata.gz: ed17e948626d108075b2951ac71abbac3075ef55b055abe64e2b352e91755fd9
4
+ data.tar.gz: 2c031642e021041f9fdf278888b580fd446879008a23f12d33c8b33aafbddc59
5
5
  SHA512:
6
- metadata.gz: 0fa88cf19b4df3cafcb246c31b104bc0df9a231f131d8c046fa20adb20f06285da1379a55ee82b3ef18e313212b4ae88f8f35752ae99bffcd0e669ca6f255b1d
7
- data.tar.gz: 37f5229326765cb0c16f1501c4f3ade8594166a7999402f1016e23dfc9ec01ca009fa6abaf6e0751e288d533393592fe1db64fd0301c1ae1e1bfe5ff4c08d010
6
+ metadata.gz: 6b208a5cbee77c2a057649b762a92ec4ca5be3b8fbd1b2123caf485579abbc602bcb2aee455a503b74f33efa9ce364ab644dc8958b9e1edd94fee3397bf17cc8
7
+ data.tar.gz: 751ecf72279d478887665f6a3efc5ad366b70284fb3f4ef6d2f3b072faf7c325be660116a7d3ac9427ac44dcf6f8c345e145921692d0465e24a70f1c2ca3b1bd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,449 @@
1
+ ## Rails 6.0.0 (August 16, 2019) ##
2
+
3
+ * Preserve user supplied joins order as much as possible.
4
+
5
+ Fixes #36761, #34328, #24281, #12953.
6
+
7
+ *Ryuta Kamizono*
8
+
9
+ * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
10
+
11
+ *John Crepezzi*, *Eileen Uchitelle*
12
+
13
+ * Add a warning for enum elements with 'not_' prefix.
14
+
15
+ class Foo
16
+ enum status: [:sent, :not_sent]
17
+ end
18
+
19
+ *Edu Depetris*
20
+
21
+ * Make currency symbols optional for money column type in PostgreSQL
22
+
23
+ *Joel Schneider*
24
+
25
+
26
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
27
+
28
+ * Add database_exists? method to connection adapters to check if a database exists.
29
+
30
+ *Guilherme Mansur*
31
+
32
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
33
+
34
+ Fixes #36022.
35
+
36
+ *Ryuta Kamizono*
37
+
38
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
39
+
40
+ Fixes #36465.
41
+
42
+ *Jeff Doering*
43
+
44
+ * Fix sqlite3 collation parsing when using decimal columns.
45
+
46
+ *Martin R. Schuster*
47
+
48
+ * Fix invalid schema when primary key column has a comment.
49
+
50
+ Fixes #29966.
51
+
52
+ *Guilherme Goettems Schneider*
53
+
54
+ * Fix table comment also being applied to the primary key column.
55
+
56
+ *Guilherme Goettems Schneider*
57
+
58
+ * Fix merging left_joins to maintain its own `join_type` context.
59
+
60
+ Fixes #36103.
61
+
62
+ *Ryuta Kamizono*
63
+
64
+
65
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
66
+
67
+ * Add `touch` option to `has_one` association.
68
+
69
+ *Abhay Nikam*
70
+
71
+ * Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
72
+
73
+ ```ruby
74
+ all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
75
+ assert_equal all, PriceEstimate.all.map(&:estimate_of)
76
+ ```
77
+
78
+ In Rails 6.0:
79
+
80
+ ```ruby
81
+ sapphire = treasures(:sapphire)
82
+
83
+ nor = all.reject { |e|
84
+ e.estimate_of_type == sapphire.class.polymorphic_name
85
+ }.reject { |e|
86
+ e.estimate_of_id == sapphire.id
87
+ }
88
+ assert_equal [cars(:honda)], nor
89
+
90
+ without_sapphire = PriceEstimate.where.not(
91
+ estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
92
+ )
93
+ assert_equal nor, without_sapphire.map(&:estimate_of)
94
+ ```
95
+
96
+ In Rails 6.1:
97
+
98
+ ```ruby
99
+ sapphire = treasures(:sapphire)
100
+
101
+ nand = all - [sapphire]
102
+ assert_equal [treasures(:diamond), cars(:honda)], nand
103
+
104
+ without_sapphire = PriceEstimate.where.not(
105
+ estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
106
+ )
107
+ assert_equal nand, without_sapphire.map(&:estimate_of)
108
+ ```
109
+
110
+ *Ryuta Kamizono*
111
+
112
+ * Fix dirty tracking after rollback.
113
+
114
+ Fixes #15018, #30167, #33868.
115
+
116
+ *Ryuta Kamizono*
117
+
118
+ * Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
119
+ the versioned entries in `ActiveSupport::Cache`. This also means that
120
+ `ActiveRecord::Relation#cache_key` will now return a stable key that does not
121
+ include the max timestamp or count any more.
122
+
123
+ NOTE: This feature is turned off by default, and `cache_key` will still return
124
+ cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
125
+ That's the setting for all new apps on Rails 6.0+
126
+
127
+ *Lachlan Sylvester*
128
+
129
+ * Fix dirty tracking for `touch` to track saved changes.
130
+
131
+ Fixes #33429.
132
+
133
+ *Ryuta Kamzono*
134
+
135
+ * `change_column_comment` and `change_table_comment` are invertible only if
136
+ `to` and `from` options are specified.
137
+
138
+ *Yoshiyuki Kinjo*
139
+
140
+ * Don't call commit/rollback callbacks when a record isn't saved.
141
+
142
+ Fixes #29747.
143
+
144
+ *Ryuta Kamizono*
145
+
146
+ * Fix circular `autosave: true` causes invalid records to be saved.
147
+
148
+ Prior to the fix, when there was a circular series of `autosave: true`
149
+ associations, the callback for a `has_many` association was run while
150
+ another instance of the same callback on the same association hadn't
151
+ finished running. When control returned to the first instance of the
152
+ callback, the instance variable had changed, and subsequent associated
153
+ records weren't saved correctly. Specifically, the ID field for the
154
+ `belongs_to` corresponding to the `has_many` was `nil`.
155
+
156
+ Fixes #28080.
157
+
158
+ *Larry Reid*
159
+
160
+ * Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
161
+
162
+ Before:
163
+
164
+ ```ruby
165
+ add_column :items, :attr1, :binary, size: 10 # => ArgumentError
166
+ add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
167
+ add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
168
+ add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
169
+ ```
170
+
171
+ After:
172
+
173
+ ```ruby
174
+ add_column :items, :attr1, :binary, size: 10 # => ArgumentError
175
+ add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
176
+ add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
177
+ add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
178
+ ```
179
+
180
+ *Ryuta Kamizono*
181
+
182
+ * Association loading isn't to be affected by scoping consistently
183
+ whether preloaded / eager loaded or not, with the exception of `unscoped`.
184
+
185
+ Before:
186
+
187
+ ```ruby
188
+ Post.where("1=0").scoping do
189
+ Comment.find(1).post # => nil
190
+ Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
191
+ Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
192
+ end
193
+ ```
194
+
195
+ After:
196
+
197
+ ```ruby
198
+ Post.where("1=0").scoping do
199
+ Comment.find(1).post # => #<Post id: 1, ...>
200
+ Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
201
+ Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
202
+ end
203
+ ```
204
+
205
+ Fixes #34638, #35398.
206
+
207
+ *Ryuta Kamizono*
208
+
209
+ * Add `rails db:prepare` to migrate or setup a database.
210
+
211
+ Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
212
+
213
+ *Roberto Miranda*
214
+
215
+ * Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
216
+
217
+ *DHH*
218
+
219
+ * Assign all attributes before calling `build` to ensure the child record is visible in
220
+ `before_add` and `after_add` callbacks for `has_many :through` associations.
221
+
222
+ Fixes #33249.
223
+
224
+ *Ryan H. Kerr*
225
+
226
+ * Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
227
+
228
+ ```
229
+ account.memberships.extract_associated(:user)
230
+ # => Returns collection of User records
231
+ ```
232
+
233
+ *DHH*
234
+
235
+ * Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
236
+
237
+ For example:
238
+
239
+ ```
240
+ Post.where(id: 123).annotate("this is a comment").to_sql
241
+ # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
242
+ ```
243
+
244
+ This can be useful in instrumentation or other analysis of issued queries.
245
+
246
+ *Matt Yoho*
247
+
248
+ * Support Optimizer Hints.
249
+
250
+ In most databases, a way to control the optimizer is by using optimizer hints,
251
+ which can be specified within individual statements.
252
+
253
+ Example (for MySQL):
254
+
255
+ Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
256
+ # SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
257
+
258
+ Example (for PostgreSQL with pg_hint_plan):
259
+
260
+ Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
261
+ # SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
262
+
263
+ See also:
264
+
265
+ * https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
266
+ * https://pghintplan.osdn.jp/pg_hint_plan.html
267
+ * https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
268
+ * https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
269
+ * https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
270
+
271
+ *Ryuta Kamizono*
272
+
273
+ * Fix query attribute method on user-defined attribute to be aware of typecasted value.
274
+
275
+ For example, the following code no longer return false as casted non-empty string:
276
+
277
+ ```
278
+ class Post < ActiveRecord::Base
279
+ attribute :user_defined_text, :text
280
+ end
281
+
282
+ Post.new(user_defined_text: "false").user_defined_text? # => true
283
+ ```
284
+
285
+ *Yuji Kamijima*
286
+
287
+ * Quote empty ranges like other empty enumerables.
288
+
289
+ *Patrick Rebsch*
290
+
291
+ * Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
292
+ allowing bulk inserts akin to the bulk updates provided by `update_all` and
293
+ bulk deletes by `delete_all`.
294
+
295
+ Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
296
+ for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
297
+ for MySQL.
298
+
299
+ *Bob Lail*
300
+
301
+ * Add `rails db:seed:replant` that truncates tables of each database
302
+ for current environment and loads the seeds.
303
+
304
+ *bogdanvlviv*, *DHH*
305
+
306
+ * Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
307
+
308
+ *bogdanvlviv*
309
+
310
+ * Deprecate mismatched collation comparison for uniqueness validator.
311
+
312
+ Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
313
+ To continue case sensitive comparison on the case insensitive column,
314
+ pass `case_sensitive: true` option explicitly to the uniqueness validator.
315
+
316
+ *Ryuta Kamizono*
317
+
318
+ * Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
319
+
320
+ Fixes #27340.
321
+
322
+ *Willian Gustavo Veiga*
323
+
324
+ * Add negative scopes for all enum values.
325
+
326
+ Example:
327
+
328
+ class Post < ActiveRecord::Base
329
+ enum status: %i[ drafted active trashed ]
330
+ end
331
+
332
+ Post.not_drafted # => where.not(status: :drafted)
333
+ Post.not_active # => where.not(status: :active)
334
+ Post.not_trashed # => where.not(status: :trashed)
335
+
336
+ *DHH*
337
+
338
+ * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
339
+
340
+ Fixes #35214.
341
+
342
+ *Juani Villarejo*
343
+
344
+
345
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
346
+
347
+ * No changes.
348
+
349
+
350
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
351
+
352
+ * Fix prepared statements caching to be enabled even when query caching is enabled.
353
+
354
+ *Ryuta Kamizono*
355
+
356
+ * Ensure `update_all` series cares about optimistic locking.
357
+
358
+ *Ryuta Kamizono*
359
+
360
+ * Don't allow `where` with non numeric string matches to 0 values.
361
+
362
+ *Ryuta Kamizono*
363
+
364
+ * Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
365
+
366
+ `destroy_by` allows relation to find all the records matching the condition and perform
367
+ `destroy_all` on the matched records.
368
+
369
+ Example:
370
+
371
+ Person.destroy_by(name: 'David')
372
+ Person.destroy_by(name: 'David', rating: 4)
373
+
374
+ david = Person.find_by(name: 'David')
375
+ david.posts.destroy_by(id: [1, 2, 3])
376
+
377
+ `delete_by` allows relation to find all the records matching the condition and perform
378
+ `delete_all` on the matched records.
379
+
380
+ Example:
381
+
382
+ Person.delete_by(name: 'David')
383
+ Person.delete_by(name: 'David', rating: 4)
384
+
385
+ david = Person.find_by(name: 'David')
386
+ david.posts.delete_by(id: [1, 2, 3])
387
+
388
+ *Abhay Nikam*
389
+
390
+ * Don't allow `where` with invalid value matches to nil values.
391
+
392
+ Fixes #33624.
393
+
394
+ *Ryuta Kamizono*
395
+
396
+ * SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
397
+
398
+ *Ryuta Kamizono*
399
+
400
+ * Deprecate using class level querying methods if the receiver scope
401
+ regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
402
+
403
+ *Ryuta Kamizono*
404
+
405
+ * Allow applications to automatically switch connections.
406
+
407
+ Adds a middleware and configuration options that can be used in your
408
+ application to automatically switch between the writing and reading
409
+ database connections.
410
+
411
+ `GET` and `HEAD` requests will read from the replica unless there was
412
+ a write in the last 2 seconds, otherwise they will read from the primary.
413
+ Non-get requests will always write to the primary. The middleware accepts
414
+ an argument for a Resolver class and an Operations class where you are able
415
+ to change how the auto-switcher works to be most beneficial for your
416
+ application.
417
+
418
+ To use the middleware in your application you can use the following
419
+ configuration options:
420
+
421
+ ```
422
+ config.active_record.database_selector = { delay: 2.seconds }
423
+ config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
424
+ config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
425
+ ```
426
+
427
+ To change the database selection strategy, pass a custom class to the
428
+ configuration options:
429
+
430
+ ```
431
+ config.active_record.database_selector = { delay: 10.seconds }
432
+ config.active_record.database_resolver = MyResolver
433
+ config.active_record.database_resolver_context = MyResolver::MyCookies
434
+ ```
435
+
436
+ *Eileen M. Uchitelle*
437
+
438
+ * MySQL: Support `:size` option to change text and blob size.
439
+
440
+ *Ryuta Kamizono*
441
+
442
+ * Make `t.timestamps` with precision by default.
443
+
444
+ *Ryuta Kamizono*
445
+
446
+
1
447
  ## Rails 6.0.0.beta1 (January 18, 2019) ##
2
448
 
3
449
  * Remove deprecated `#set_state` from the transaction object.
@@ -120,7 +566,7 @@
120
566
 
121
567
  *Gannon McGibbon*
122
568
 
123
- * Cached columns_hash fields should be excluded from ResultSet#column_types
569
+ * Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
124
570
 
125
571
  PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
126
572
  was passing for SQLite and MySQL, but failed for PostgreSQL:
@@ -151,12 +597,12 @@
151
597
 
152
598
  * Make the implicit order column configurable.
153
599
 
154
- When calling ordered finder methods such as +first+ or +last+ without an
600
+ When calling ordered finder methods such as `first` or `last` without an
155
601
  explicit order clause, ActiveRecord sorts records by primary key. This can
156
602
  result in unpredictable and surprising behaviour when the primary key is
157
603
  not an auto-incrementing integer, for example when it's a UUID. This change
158
604
  makes it possible to override the column used for implicit ordering such
159
- that +first+ and +last+ will return more predictable results.
605
+ that `first` and `last` will return more predictable results.
160
606
 
161
607
  Example:
162
608
 
@@ -226,7 +672,7 @@
226
672
 
227
673
  *Sean Griffin*
228
674
 
229
- * Add support for hash and url configs in database hash of `ActiveRecord::Base.connected_to`.
675
+ * Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
230
676
 
231
677
  ````
232
678
  User.connected_to(database: { writing: "postgres://foo" }) do
@@ -302,10 +748,10 @@
302
748
 
303
749
  * Enum raises on invalid definition values
304
750
 
305
- When defining a Hash enum it can be easy to use [] instead of {}. This
751
+ When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
306
752
  commit checks that only valid definition values are provided, those can
307
753
  be a Hash, an array of Symbols or an array of Strings. Otherwise it
308
- raises an ArgumentError.
754
+ raises an `ArgumentError`.
309
755
 
310
756
  Fixes #33961
311
757
 
@@ -399,7 +845,7 @@
399
845
  *Darwin Wu*
400
846
 
401
847
  * Configuration item `config.filter_parameters` could also filter out
402
- sensitive values of database columns when call `#inspect`.
848
+ sensitive values of database columns when calling `#inspect`.
403
849
  We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
404
850
  specify sensitive attributes to specific model.
405
851
 
@@ -454,8 +900,8 @@
454
900
 
455
901
  Iterating over the database configurations has also changed. Instead of
456
902
  calling hash methods on the `configurations` hash directly, a new method `configs_for` has
457
- been provided that allows you to select the correct configuration. `env_name`, and
458
- `spec_name` arguments are optional. For example these return an array of
903
+ been provided that allows you to select the correct configuration. `env_name` and
904
+ `spec_name` arguments are optional. For example, these return an array of
459
905
  database config objects for the requested environment and a single database config object
460
906
  will be returned for the requested environment and specification name respectively.
461
907
 
data/README.rdoc CHANGED
@@ -13,6 +13,8 @@ columns. Although these mappings can be defined explicitly, it's recommended
13
13
  to follow naming conventions, especially when getting started with the
14
14
  library.
15
15
 
16
+ You can read more about Active Record in the {Active Record Basics}[https://edgeguides.rubyonrails.org/active_record_basics.html] guide.
17
+
16
18
  A short rundown of some of the major features:
17
19
 
18
20
  * Automated mapping between classes and tables, attributes and columns.
@@ -206,7 +208,7 @@ Active Record is released under the MIT license:
206
208
 
207
209
  API documentation is at:
208
210
 
209
- * http://api.rubyonrails.org
211
+ * https://api.rubyonrails.org
210
212
 
211
213
  Bug reports for the Ruby on Rails project can be filed here:
212
214
 
@@ -17,6 +17,23 @@ module ActiveRecord
17
17
  # CollectionAssociation
18
18
  # HasManyAssociation + ForeignAssociation
19
19
  # HasManyThroughAssociation + ThroughAssociation
20
+ #
21
+ # Associations in Active Record are middlemen between the object that
22
+ # holds the association, known as the <tt>owner</tt>, and the associated
23
+ # result set, known as the <tt>target</tt>. Association metadata is available in
24
+ # <tt>reflection</tt>, which is an instance of <tt>ActiveRecord::Reflection::AssociationReflection</tt>.
25
+ #
26
+ # For example, given
27
+ #
28
+ # class Blog < ActiveRecord::Base
29
+ # has_many :posts
30
+ # end
31
+ #
32
+ # blog = Blog.first
33
+ #
34
+ # The association of <tt>blog.posts</tt> has the object +blog+ as its
35
+ # <tt>owner</tt>, the collection of its posts as <tt>target</tt>, and
36
+ # the <tt>reflection</tt> object represents a <tt>:has_many</tt> macro.
20
37
  class Association #:nodoc:
21
38
  attr_reader :owner, :target, :reflection
22
39
 
@@ -208,7 +225,7 @@ module ActiveRecord
208
225
  # Can be overridden (i.e. in ThroughAssociation) to merge in other scopes (i.e. the
209
226
  # through association's scope)
210
227
  def target_scope
211
- AssociationRelation.create(klass, self).merge!(klass.all)
228
+ AssociationRelation.create(klass, self).merge!(klass.scope_for_association)
212
229
  end
213
230
 
214
231
  def scope_for_create
@@ -27,40 +27,32 @@ module ActiveRecord::Associations::Builder # :nodoc:
27
27
  "Please choose a different association name."
28
28
  end
29
29
 
30
- extension = define_extensions model, name, &block
31
- reflection = create_reflection model, name, scope, options, extension
30
+ reflection = create_reflection(model, name, scope, options, &block)
32
31
  define_accessors model, reflection
33
32
  define_callbacks model, reflection
34
33
  define_validations model, reflection
35
34
  reflection
36
35
  end
37
36
 
38
- def self.create_reflection(model, name, scope, options, extension = nil)
37
+ def self.create_reflection(model, name, scope, options, &block)
39
38
  raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol)
40
39
 
41
40
  validate_options(options)
42
41
 
43
- scope = build_scope(scope, extension)
42
+ extension = define_extensions(model, name, &block)
43
+ options[:extend] = [*options[:extend], extension] if extension
44
+
45
+ scope = build_scope(scope)
44
46
 
45
47
  ActiveRecord::Reflection.create(macro, name, scope, options, model)
46
48
  end
47
49
 
48
- def self.build_scope(scope, extension)
49
- new_scope = scope
50
-
50
+ def self.build_scope(scope)
51
51
  if scope && scope.arity == 0
52
- new_scope = proc { instance_exec(&scope) }
53
- end
54
-
55
- if extension
56
- new_scope = wrap_scope new_scope, extension
52
+ proc { instance_exec(&scope) }
53
+ else
54
+ scope
57
55
  end
58
-
59
- new_scope
60
- end
61
-
62
- def self.wrap_scope(scope, extension)
63
- scope
64
56
  end
65
57
 
66
58
  def self.macro
@@ -136,5 +128,9 @@ module ActiveRecord::Associations::Builder # :nodoc:
136
128
  name = reflection.name
137
129
  model.before_destroy lambda { |o| o.association(name).handle_dependency }
138
130
  end
131
+
132
+ private_class_method :build_scope, :macro, :valid_options, :validate_options, :define_extensions,
133
+ :define_callbacks, :define_accessors, :define_readers, :define_writers, :define_validations,
134
+ :valid_dependent_options, :check_dependent_options, :add_destroy_callbacks
139
135
  end
140
136
  end
@@ -74,11 +74,11 @@ module ActiveRecord::Associations::Builder # :nodoc:
74
74
 
75
75
  def self.add_touch_callbacks(model, reflection)
76
76
  foreign_key = reflection.foreign_key
77
- n = reflection.name
77
+ name = reflection.name
78
78
  touch = reflection.options[:touch]
79
79
 
80
80
  callback = lambda { |changes_method| lambda { |record|
81
- BelongsTo.touch_record(record, record.send(changes_method), foreign_key, n, touch, belongs_to_touch_method)
81
+ BelongsTo.touch_record(record, record.send(changes_method), foreign_key, name, touch, belongs_to_touch_method)
82
82
  }}
83
83
 
84
84
  if reflection.counter_cache_column
@@ -123,5 +123,8 @@ module ActiveRecord::Associations::Builder # :nodoc:
123
123
  model.validates_presence_of reflection.name, message: :required
124
124
  end
125
125
  end
126
+
127
+ private_class_method :macro, :valid_options, :valid_dependent_options, :define_callbacks, :define_validations,
128
+ :add_counter_cache_callbacks, :add_touch_callbacks, :add_default_callbacks, :add_destroy_callbacks
126
129
  end
127
130
  end
@@ -20,11 +20,11 @@ module ActiveRecord::Associations::Builder # :nodoc:
20
20
  }
21
21
  end
22
22
 
23
- def self.define_extensions(model, name)
23
+ def self.define_extensions(model, name, &block)
24
24
  if block_given?
25
- extension_module_name = "#{model.name.demodulize}#{name.to_s.camelize}AssociationExtension"
26
- extension = Module.new(&Proc.new)
27
- model.module_parent.const_set(extension_module_name, extension)
25
+ extension_module_name = "#{name.to_s.camelize}AssociationExtension"
26
+ extension = Module.new(&block)
27
+ model.const_set(extension_module_name, extension)
28
28
  end
29
29
  end
30
30
 
@@ -67,16 +67,6 @@ module ActiveRecord::Associations::Builder # :nodoc:
67
67
  CODE
68
68
  end
69
69
 
70
- def self.wrap_scope(scope, mod)
71
- if scope
72
- if scope.arity > 0
73
- proc { |owner| instance_exec(owner, &scope).extending(mod) }
74
- else
75
- proc { instance_exec(&scope).extending(mod) }
76
- end
77
- else
78
- proc { extending(mod) }
79
- end
80
- end
70
+ private_class_method :valid_options, :define_callback, :define_extensions, :define_readers, :define_writers
81
71
  end
82
72
  end