activerecord 5.2.4.4 → 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 (268) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +611 -590
  3. data/MIT-LICENSE +3 -1
  4. data/README.rdoc +4 -2
  5. data/examples/performance.rb +1 -1
  6. data/lib/active_record.rb +9 -2
  7. data/lib/active_record/aggregations.rb +4 -2
  8. data/lib/active_record/associations.rb +19 -14
  9. data/lib/active_record/associations/association.rb +52 -19
  10. data/lib/active_record/associations/association_scope.rb +4 -6
  11. data/lib/active_record/associations/belongs_to_association.rb +36 -42
  12. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +0 -4
  13. data/lib/active_record/associations/builder/association.rb +14 -18
  14. data/lib/active_record/associations/builder/belongs_to.rb +19 -52
  15. data/lib/active_record/associations/builder/collection_association.rb +3 -13
  16. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -38
  17. data/lib/active_record/associations/builder/has_many.rb +2 -0
  18. data/lib/active_record/associations/builder/has_one.rb +35 -1
  19. data/lib/active_record/associations/builder/singular_association.rb +2 -0
  20. data/lib/active_record/associations/collection_association.rb +6 -21
  21. data/lib/active_record/associations/collection_proxy.rb +12 -15
  22. data/lib/active_record/associations/foreign_association.rb +7 -0
  23. data/lib/active_record/associations/has_many_association.rb +2 -10
  24. data/lib/active_record/associations/has_many_through_association.rb +14 -14
  25. data/lib/active_record/associations/has_one_association.rb +28 -30
  26. data/lib/active_record/associations/has_one_through_association.rb +5 -5
  27. data/lib/active_record/associations/join_dependency.rb +24 -28
  28. data/lib/active_record/associations/join_dependency/join_association.rb +9 -10
  29. data/lib/active_record/associations/join_dependency/join_part.rb +2 -2
  30. data/lib/active_record/associations/preloader.rb +40 -32
  31. data/lib/active_record/associations/preloader/association.rb +38 -36
  32. data/lib/active_record/associations/preloader/through_association.rb +48 -39
  33. data/lib/active_record/associations/singular_association.rb +2 -16
  34. data/lib/active_record/attribute_assignment.rb +7 -10
  35. data/lib/active_record/attribute_methods.rb +28 -100
  36. data/lib/active_record/attribute_methods/before_type_cast.rb +4 -1
  37. data/lib/active_record/attribute_methods/dirty.rb +111 -40
  38. data/lib/active_record/attribute_methods/primary_key.rb +15 -22
  39. data/lib/active_record/attribute_methods/query.rb +2 -3
  40. data/lib/active_record/attribute_methods/read.rb +15 -53
  41. data/lib/active_record/attribute_methods/serialization.rb +1 -1
  42. data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
  43. data/lib/active_record/attribute_methods/write.rb +17 -24
  44. data/lib/active_record/attributes.rb +13 -0
  45. data/lib/active_record/autosave_association.rb +5 -9
  46. data/lib/active_record/base.rb +2 -3
  47. data/lib/active_record/callbacks.rb +5 -19
  48. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +94 -16
  49. data/lib/active_record/connection_adapters/abstract/database_limits.rb +17 -4
  50. data/lib/active_record/connection_adapters/abstract/database_statements.rb +95 -123
  51. data/lib/active_record/connection_adapters/abstract/query_cache.rb +17 -8
  52. data/lib/active_record/connection_adapters/abstract/quoting.rb +68 -17
  53. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +19 -12
  54. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +76 -48
  55. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -3
  56. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +132 -53
  57. data/lib/active_record/connection_adapters/abstract/transaction.rb +96 -56
  58. data/lib/active_record/connection_adapters/abstract_adapter.rb +180 -47
  59. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +128 -194
  60. data/lib/active_record/connection_adapters/column.rb +17 -13
  61. data/lib/active_record/connection_adapters/connection_specification.rb +52 -42
  62. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +6 -10
  63. data/lib/active_record/connection_adapters/mysql/database_statements.rb +73 -13
  64. data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
  65. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +3 -4
  66. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +40 -32
  67. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +14 -6
  68. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +129 -13
  69. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
  70. data/lib/active_record/connection_adapters/mysql2_adapter.rb +26 -9
  71. data/lib/active_record/connection_adapters/postgresql/column.rb +17 -31
  72. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +20 -1
  73. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
  74. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
  75. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -1
  76. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +1 -1
  77. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
  78. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +1 -1
  79. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +1 -1
  80. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
  81. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +6 -3
  82. data/lib/active_record/connection_adapters/postgresql/quoting.rb +44 -7
  83. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +12 -1
  84. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
  85. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +55 -53
  86. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +24 -27
  87. data/lib/active_record/connection_adapters/postgresql_adapter.rb +160 -74
  88. data/lib/active_record/connection_adapters/schema_cache.rb +37 -14
  89. data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
  90. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +118 -0
  91. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -6
  92. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +42 -11
  93. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +125 -141
  94. data/lib/active_record/connection_handling.rb +149 -27
  95. data/lib/active_record/core.rb +100 -60
  96. data/lib/active_record/counter_cache.rb +4 -29
  97. data/lib/active_record/database_configurations.rb +233 -0
  98. data/lib/active_record/database_configurations/database_config.rb +37 -0
  99. data/lib/active_record/database_configurations/hash_config.rb +50 -0
  100. data/lib/active_record/database_configurations/url_config.rb +79 -0
  101. data/lib/active_record/dynamic_matchers.rb +1 -1
  102. data/lib/active_record/enum.rb +37 -7
  103. data/lib/active_record/errors.rb +15 -7
  104. data/lib/active_record/explain.rb +1 -1
  105. data/lib/active_record/fixture_set/model_metadata.rb +33 -0
  106. data/lib/active_record/fixture_set/render_context.rb +17 -0
  107. data/lib/active_record/fixture_set/table_row.rb +153 -0
  108. data/lib/active_record/fixture_set/table_rows.rb +47 -0
  109. data/lib/active_record/fixtures.rb +145 -472
  110. data/lib/active_record/gem_version.rb +4 -4
  111. data/lib/active_record/inheritance.rb +13 -3
  112. data/lib/active_record/insert_all.rb +179 -0
  113. data/lib/active_record/integration.rb +68 -16
  114. data/lib/active_record/internal_metadata.rb +10 -2
  115. data/lib/active_record/locking/optimistic.rb +5 -6
  116. data/lib/active_record/locking/pessimistic.rb +3 -3
  117. data/lib/active_record/log_subscriber.rb +7 -26
  118. data/lib/active_record/middleware/database_selector.rb +75 -0
  119. data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
  120. data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
  121. data/lib/active_record/migration.rb +100 -81
  122. data/lib/active_record/migration/command_recorder.rb +50 -6
  123. data/lib/active_record/migration/compatibility.rb +76 -49
  124. data/lib/active_record/model_schema.rb +30 -9
  125. data/lib/active_record/nested_attributes.rb +2 -2
  126. data/lib/active_record/no_touching.rb +7 -0
  127. data/lib/active_record/persistence.rb +228 -24
  128. data/lib/active_record/query_cache.rb +11 -4
  129. data/lib/active_record/querying.rb +32 -20
  130. data/lib/active_record/railtie.rb +80 -43
  131. data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
  132. data/lib/active_record/railties/controller_runtime.rb +30 -35
  133. data/lib/active_record/railties/databases.rake +196 -46
  134. data/lib/active_record/reflection.rb +32 -30
  135. data/lib/active_record/relation.rb +310 -80
  136. data/lib/active_record/relation/batches.rb +13 -10
  137. data/lib/active_record/relation/calculations.rb +53 -47
  138. data/lib/active_record/relation/delegation.rb +26 -43
  139. data/lib/active_record/relation/finder_methods.rb +13 -26
  140. data/lib/active_record/relation/merger.rb +11 -20
  141. data/lib/active_record/relation/predicate_builder.rb +4 -6
  142. data/lib/active_record/relation/predicate_builder/array_handler.rb +5 -4
  143. data/lib/active_record/relation/predicate_builder/association_query_value.rb +1 -4
  144. data/lib/active_record/relation/predicate_builder/base_handler.rb +1 -2
  145. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
  146. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -4
  147. data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
  148. data/lib/active_record/relation/query_attribute.rb +13 -8
  149. data/lib/active_record/relation/query_methods.rb +189 -63
  150. data/lib/active_record/relation/spawn_methods.rb +1 -1
  151. data/lib/active_record/relation/where_clause.rb +14 -10
  152. data/lib/active_record/relation/where_clause_factory.rb +1 -2
  153. data/lib/active_record/result.rb +30 -11
  154. data/lib/active_record/sanitization.rb +32 -40
  155. data/lib/active_record/schema.rb +2 -11
  156. data/lib/active_record/schema_dumper.rb +22 -7
  157. data/lib/active_record/schema_migration.rb +5 -1
  158. data/lib/active_record/scoping.rb +8 -8
  159. data/lib/active_record/scoping/default.rb +4 -5
  160. data/lib/active_record/scoping/named.rb +19 -15
  161. data/lib/active_record/statement_cache.rb +30 -3
  162. data/lib/active_record/store.rb +87 -8
  163. data/lib/active_record/table_metadata.rb +10 -17
  164. data/lib/active_record/tasks/database_tasks.rb +194 -25
  165. data/lib/active_record/tasks/mysql_database_tasks.rb +5 -5
  166. data/lib/active_record/tasks/postgresql_database_tasks.rb +5 -7
  167. data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -8
  168. data/lib/active_record/test_databases.rb +23 -0
  169. data/lib/active_record/test_fixtures.rb +224 -0
  170. data/lib/active_record/timestamp.rb +39 -25
  171. data/lib/active_record/touch_later.rb +4 -2
  172. data/lib/active_record/transactions.rb +57 -66
  173. data/lib/active_record/translation.rb +1 -1
  174. data/lib/active_record/type.rb +3 -4
  175. data/lib/active_record/type/adapter_specific_registry.rb +1 -8
  176. data/lib/active_record/type_caster/connection.rb +15 -14
  177. data/lib/active_record/type_caster/map.rb +1 -4
  178. data/lib/active_record/validations.rb +1 -0
  179. data/lib/active_record/validations/uniqueness.rb +15 -27
  180. data/lib/arel.rb +51 -0
  181. data/lib/arel/alias_predication.rb +9 -0
  182. data/lib/arel/attributes.rb +22 -0
  183. data/lib/arel/attributes/attribute.rb +37 -0
  184. data/lib/arel/collectors/bind.rb +24 -0
  185. data/lib/arel/collectors/composite.rb +31 -0
  186. data/lib/arel/collectors/plain_string.rb +20 -0
  187. data/lib/arel/collectors/sql_string.rb +20 -0
  188. data/lib/arel/collectors/substitute_binds.rb +28 -0
  189. data/lib/arel/crud.rb +42 -0
  190. data/lib/arel/delete_manager.rb +18 -0
  191. data/lib/arel/errors.rb +9 -0
  192. data/lib/arel/expressions.rb +29 -0
  193. data/lib/arel/factory_methods.rb +49 -0
  194. data/lib/arel/insert_manager.rb +49 -0
  195. data/lib/arel/math.rb +45 -0
  196. data/lib/arel/nodes.rb +68 -0
  197. data/lib/arel/nodes/and.rb +32 -0
  198. data/lib/arel/nodes/ascending.rb +23 -0
  199. data/lib/arel/nodes/binary.rb +52 -0
  200. data/lib/arel/nodes/bind_param.rb +36 -0
  201. data/lib/arel/nodes/case.rb +55 -0
  202. data/lib/arel/nodes/casted.rb +50 -0
  203. data/lib/arel/nodes/comment.rb +29 -0
  204. data/lib/arel/nodes/count.rb +12 -0
  205. data/lib/arel/nodes/delete_statement.rb +45 -0
  206. data/lib/arel/nodes/descending.rb +23 -0
  207. data/lib/arel/nodes/equality.rb +18 -0
  208. data/lib/arel/nodes/extract.rb +24 -0
  209. data/lib/arel/nodes/false.rb +16 -0
  210. data/lib/arel/nodes/full_outer_join.rb +8 -0
  211. data/lib/arel/nodes/function.rb +44 -0
  212. data/lib/arel/nodes/grouping.rb +8 -0
  213. data/lib/arel/nodes/in.rb +8 -0
  214. data/lib/arel/nodes/infix_operation.rb +80 -0
  215. data/lib/arel/nodes/inner_join.rb +8 -0
  216. data/lib/arel/nodes/insert_statement.rb +37 -0
  217. data/lib/arel/nodes/join_source.rb +20 -0
  218. data/lib/arel/nodes/matches.rb +18 -0
  219. data/lib/arel/nodes/named_function.rb +23 -0
  220. data/lib/arel/nodes/node.rb +50 -0
  221. data/lib/arel/nodes/node_expression.rb +13 -0
  222. data/lib/arel/nodes/outer_join.rb +8 -0
  223. data/lib/arel/nodes/over.rb +15 -0
  224. data/lib/arel/nodes/regexp.rb +16 -0
  225. data/lib/arel/nodes/right_outer_join.rb +8 -0
  226. data/lib/arel/nodes/select_core.rb +67 -0
  227. data/lib/arel/nodes/select_statement.rb +41 -0
  228. data/lib/arel/nodes/sql_literal.rb +16 -0
  229. data/lib/arel/nodes/string_join.rb +11 -0
  230. data/lib/arel/nodes/table_alias.rb +27 -0
  231. data/lib/arel/nodes/terminal.rb +16 -0
  232. data/lib/arel/nodes/true.rb +16 -0
  233. data/lib/arel/nodes/unary.rb +45 -0
  234. data/lib/arel/nodes/unary_operation.rb +20 -0
  235. data/lib/arel/nodes/unqualified_column.rb +22 -0
  236. data/lib/arel/nodes/update_statement.rb +41 -0
  237. data/lib/arel/nodes/values_list.rb +9 -0
  238. data/lib/arel/nodes/window.rb +126 -0
  239. data/lib/arel/nodes/with.rb +11 -0
  240. data/lib/arel/order_predications.rb +13 -0
  241. data/lib/arel/predications.rb +257 -0
  242. data/lib/arel/select_manager.rb +271 -0
  243. data/lib/arel/table.rb +110 -0
  244. data/lib/arel/tree_manager.rb +72 -0
  245. data/lib/arel/update_manager.rb +34 -0
  246. data/lib/arel/visitors.rb +20 -0
  247. data/lib/arel/visitors/depth_first.rb +204 -0
  248. data/lib/arel/visitors/dot.rb +297 -0
  249. data/lib/arel/visitors/ibm_db.rb +34 -0
  250. data/lib/arel/visitors/informix.rb +62 -0
  251. data/lib/arel/visitors/mssql.rb +157 -0
  252. data/lib/arel/visitors/mysql.rb +83 -0
  253. data/lib/arel/visitors/oracle.rb +159 -0
  254. data/lib/arel/visitors/oracle12.rb +66 -0
  255. data/lib/arel/visitors/postgresql.rb +110 -0
  256. data/lib/arel/visitors/sqlite.rb +39 -0
  257. data/lib/arel/visitors/to_sql.rb +889 -0
  258. data/lib/arel/visitors/visitor.rb +46 -0
  259. data/lib/arel/visitors/where_sql.rb +23 -0
  260. data/lib/arel/window_predications.rb +9 -0
  261. data/lib/rails/generators/active_record/migration.rb +14 -1
  262. data/lib/rails/generators/active_record/migration/migration_generator.rb +2 -5
  263. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
  264. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
  265. data/lib/rails/generators/active_record/model/model_generator.rb +1 -0
  266. data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
  267. metadata +108 -26
  268. data/lib/active_record/collection_cache_key.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b371eab07ad19fdba3131ea0100df91b8b6b86cc95456d9a3499a6b872a2cd47
4
- data.tar.gz: 83e774333487bd4f05ca4b33bcba5d3856a76deb08a1b9e8a2ab15a6dada07b6
3
+ metadata.gz: ed17e948626d108075b2951ac71abbac3075ef55b055abe64e2b352e91755fd9
4
+ data.tar.gz: 2c031642e021041f9fdf278888b580fd446879008a23f12d33c8b33aafbddc59
5
5
  SHA512:
6
- metadata.gz: f90b220a5a56487c855b7ce357103e81933cbf8526aa5d166c89eb245d310a8e878104e553d6026881471c1d1fd79aad212651dc3a2f3a2b9d538c848156d175
7
- data.tar.gz: def00b3f9d09476467c13b4df9ee720264f542b828a520f220688a3d1368d948cf2feba8a06ea4df87de0fbc617104e1928ab1ffa9e1c022cd86f97818feb031
6
+ metadata.gz: 6b208a5cbee77c2a057649b762a92ec4ca5be3b8fbd1b2123caf485579abbc602bcb2aee455a503b74f33efa9ce364ab644dc8958b9e1edd94fee3397bf17cc8
7
+ data.tar.gz: 751ecf72279d478887665f6a3efc5ad366b70284fb3f4ef6d2f3b072faf7c325be660116a7d3ac9427ac44dcf6f8c345e145921692d0465e24a70f1c2ca3b1bd
@@ -1,33 +1,33 @@
1
- ## Rails 5.2.4.4 (September 09, 2020) ##
1
+ ## Rails 6.0.0 (August 16, 2019) ##
2
2
 
3
- * No changes.
3
+ * Preserve user supplied joins order as much as possible.
4
4
 
5
+ Fixes #36761, #34328, #24281, #12953.
5
6
 
6
- ## Rails 5.2.4.3 (May 18, 2020) ##
7
+ *Ryuta Kamizono*
7
8
 
8
- * No changes.
9
+ * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
9
10
 
11
+ *John Crepezzi*, *Eileen Uchitelle*
10
12
 
11
- ## Rails 5.2.4.1 (December 18, 2019) ##
13
+ * Add a warning for enum elements with 'not_' prefix.
12
14
 
13
- * No changes.
15
+ class Foo
16
+ enum status: [:sent, :not_sent]
17
+ end
14
18
 
19
+ *Edu Depetris*
15
20
 
16
- ## Rails 5.2.4 (November 27, 2019) ##
21
+ * Make currency symbols optional for money column type in PostgreSQL
17
22
 
18
- * Fix circular `autosave: true` causes invalid records to be saved.
23
+ *Joel Schneider*
19
24
 
20
- Prior to the fix, when there was a circular series of `autosave: true`
21
- associations, the callback for a `has_many` association was run while
22
- another instance of the same callback on the same association hadn't
23
- finished running. When control returned to the first instance of the
24
- callback, the instance variable had changed, and subsequent associated
25
- records weren't saved correctly. Specifically, the ID field for the
26
- `belongs_to` corresponding to the `has_many` was `nil`.
27
25
 
28
- Fixes #28080.
26
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
29
27
 
30
- *Larry Reid*
28
+ * Add database_exists? method to connection adapters to check if a database exists.
29
+
30
+ *Guilherme Mansur*
31
31
 
32
32
  * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
33
33
 
@@ -35,958 +35,979 @@
35
35
 
36
36
  *Ryuta Kamizono*
37
37
 
38
- * Fix sqlite3 collation parsing when using decimal columns.
39
-
40
- *Martin R. Schuster*
41
-
42
38
  * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
43
39
 
44
40
  Fixes #36465.
45
41
 
46
42
  *Jeff Doering*
47
43
 
48
- * Assign all attributes before calling `build` to ensure the child record is visible in
49
- `before_add` and `after_add` callbacks for `has_many :through` associations.
50
-
51
- Fixes #33249.
52
-
53
- *Ryan H. Kerr*
54
-
44
+ * Fix sqlite3 collation parsing when using decimal columns.
55
45
 
56
- ## Rails 5.2.3 (March 27, 2019) ##
46
+ *Martin R. Schuster*
57
47
 
58
- * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
48
+ * Fix invalid schema when primary key column has a comment.
59
49
 
60
- Fixes #35214.
50
+ Fixes #29966.
61
51
 
62
- *Juani Villarejo*
52
+ *Guilherme Goettems Schneider*
63
53
 
64
- * Fix prepared statements caching to be enabled even when query caching is enabled.
54
+ * Fix table comment also being applied to the primary key column.
65
55
 
66
- *Ryuta Kamizono*
56
+ *Guilherme Goettems Schneider*
67
57
 
68
- * Don't allow `where` with invalid value matches to nil values.
58
+ * Fix merging left_joins to maintain its own `join_type` context.
69
59
 
70
- Fixes #33624.
60
+ Fixes #36103.
71
61
 
72
62
  *Ryuta Kamizono*
73
63
 
74
- * Restore an ability that class level `update` without giving ids.
75
64
 
76
- Fixes #34743.
65
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
77
66
 
78
- *Ryuta Kamizono*
67
+ * Add `touch` option to `has_one` association.
79
68
 
80
- * Fix join table column quoting with SQLite.
69
+ *Abhay Nikam*
81
70
 
82
- *Gannon McGibbon*
71
+ * Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
83
72
 
84
- * Ensure that `delete_all` on collection proxy returns affected count.
73
+ ```ruby
74
+ all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
75
+ assert_equal all, PriceEstimate.all.map(&:estimate_of)
76
+ ```
85
77
 
86
- *Ryuta Kamizono*
78
+ In Rails 6.0:
87
79
 
88
- * Reset scope after delete on collection association to clear stale offsets of removed records.
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
+ ```
89
95
 
90
- *Gannon McGibbon*
96
+ In Rails 6.1:
91
97
 
98
+ ```ruby
99
+ sapphire = treasures(:sapphire)
92
100
 
93
- ## Rails 5.2.2.1 (March 11, 2019) ##
101
+ nand = all - [sapphire]
102
+ assert_equal [treasures(:diamond), cars(:honda)], nand
94
103
 
95
- * No changes.
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
+ ```
96
109
 
110
+ *Ryuta Kamizono*
97
111
 
98
- ## Rails 5.2.2 (December 04, 2018) ##
112
+ * Fix dirty tracking after rollback.
99
113
 
100
- * Do not ignore the scoping with query methods in the scope block.
114
+ Fixes #15018, #30167, #33868.
101
115
 
102
116
  *Ryuta Kamizono*
103
117
 
104
- * Allow aliased attributes to be used in `#update_columns` and `#update`.
105
-
106
- *Gannon McGibbon*
107
-
108
- * Allow spaces in postgres table names.
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.
109
122
 
110
- Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres
111
- adapter.
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+
112
126
 
113
- *Gannon McGibbon*
127
+ *Lachlan Sylvester*
114
128
 
115
- * Cached columns_hash fields should be excluded from ResultSet#column_types
129
+ * Fix dirty tracking for `touch` to track saved changes.
116
130
 
117
- PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
118
- was passing for SQLite and MySQL, but failed for PostgreSQL:
131
+ Fixes #33429.
119
132
 
120
- ```ruby
121
- class DeveloperName < ActiveRecord::Type::String
122
- def deserialize(value)
123
- "Developer: #{value}"
124
- end
125
- end
133
+ *Ryuta Kamzono*
126
134
 
127
- class AttributedDeveloper < ActiveRecord::Base
128
- self.table_name = "developers"
135
+ * `change_column_comment` and `change_table_comment` are invertible only if
136
+ `to` and `from` options are specified.
129
137
 
130
- attribute :name, DeveloperName.new
138
+ *Yoshiyuki Kinjo*
131
139
 
132
- self.ignored_columns += ["name"]
133
- end
140
+ * Don't call commit/rollback callbacks when a record isn't saved.
134
141
 
135
- developer = AttributedDeveloper.create
136
- developer.update_column :name, "name"
142
+ Fixes #29747.
137
143
 
138
- loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
139
- puts loaded_developer.name # should be "Developer: name" but it's just "name"
140
- ```
144
+ *Ryuta Kamizono*
141
145
 
142
- *Dmitry Tsepelev*
146
+ * Fix circular `autosave: true` causes invalid records to be saved.
143
147
 
144
- * Values of enum are frozen, raising an error when attempting to modify them.
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`.
145
155
 
146
- *Emmanuel Byrd*
156
+ Fixes #28080.
147
157
 
148
- * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
149
- if the attribute does not exist.
158
+ *Larry Reid*
150
159
 
151
- *Sean Griffin*
160
+ * Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
152
161
 
153
- * Do not use prepared statement in queries that have a large number of binds.
162
+ Before:
154
163
 
155
- *Ryuta Kamizono*
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
+ ```
156
170
 
157
- * Fix query cache to load before first request.
171
+ After:
158
172
 
159
- *Eileen M. Uchitelle*
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
+ ```
160
179
 
161
- * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
180
+ *Ryuta Kamizono*
162
181
 
163
- Fixes #33056.
182
+ * Association loading isn't to be affected by scoping consistently
183
+ whether preloaded / eager loaded or not, with the exception of `unscoped`.
164
184
 
165
- *Federico Martinez*
185
+ Before:
166
186
 
167
- * Fix duplicated record creation when using nested attributes with `create_with`.
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
+ ```
168
194
 
169
- *Darwin Wu*
195
+ After:
170
196
 
171
- * Fix regression setting children record in parent `before_save` callback.
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
+ ```
172
204
 
173
- *Guo Xiang Tan*
205
+ Fixes #34638, #35398.
174
206
 
175
- * Prevent leaking of user's DB credentials on `rails db:create` failure.
207
+ *Ryuta Kamizono*
176
208
 
177
- *bogdanvlviv*
209
+ * Add `rails db:prepare` to migrate or setup a database.
178
210
 
179
- * Clear mutation tracker before continuing the around callbacks.
211
+ Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
180
212
 
181
- *Yuya Tanaka*
213
+ *Roberto Miranda*
182
214
 
183
- * Prevent deadlocks when waiting for connection from pool.
215
+ * Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
184
216
 
185
- *Brent Wheeldon*
217
+ *DHH*
186
218
 
187
- * Avoid extra scoping when using `Relation#update` that was causing this method to change the current scope.
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.
188
221
 
189
- *Ryuta Kamizono*
222
+ Fixes #33249.
190
223
 
191
- * Fix numericality validator not to be affected by custom getter.
224
+ *Ryan H. Kerr*
192
225
 
193
- *Ryuta Kamizono*
226
+ * Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
194
227
 
195
- * Fix bulk change table ignores comment option on PostgreSQL.
228
+ ```
229
+ account.memberships.extract_associated(:user)
230
+ # => Returns collection of User records
231
+ ```
196
232
 
197
- *Yoshiyuki Kinjo*
233
+ *DHH*
198
234
 
235
+ * Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
199
236
 
200
- ## Rails 5.2.1.1 (November 27, 2018) ##
237
+ For example:
201
238
 
202
- * No changes.
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
+ ```
203
243
 
244
+ This can be useful in instrumentation or other analysis of issued queries.
204
245
 
205
- ## Rails 5.2.1 (August 07, 2018) ##
246
+ *Matt Yoho*
206
247
 
207
- * PostgreSQL: Support new relkind for partitioned tables.
248
+ * Support Optimizer Hints.
208
249
 
209
- Fixes #33008.
250
+ In most databases, a way to control the optimizer is by using optimizer hints,
251
+ which can be specified within individual statements.
210
252
 
211
- *Yannick Schutz*
253
+ Example (for MySQL):
212
254
 
213
- * Rollback parent transaction when children fails to update.
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`
214
257
 
215
- *Guillaume Malette*
258
+ Example (for PostgreSQL with pg_hint_plan):
216
259
 
217
- * Fix default value for MySQL time types with specified precision.
260
+ Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
261
+ # SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
218
262
 
219
- *Nikolay Kondratyev*
263
+ See also:
220
264
 
221
- * Fix `touch` option to behave consistently with `Persistence#touch` method.
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
222
270
 
223
271
  *Ryuta Kamizono*
224
272
 
225
- * Fix `save` in `after_create_commit` won't invoke extra `after_create_commit`.
273
+ * Fix query attribute method on user-defined attribute to be aware of typecasted value.
226
274
 
227
- Fixes #32831.
275
+ For example, the following code no longer return false as casted non-empty string:
228
276
 
229
- *Ryuta Kamizono*
277
+ ```
278
+ class Post < ActiveRecord::Base
279
+ attribute :user_defined_text, :text
280
+ end
230
281
 
231
- * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
282
+ Post.new(user_defined_text: "false").user_defined_text? # => true
283
+ ```
232
284
 
233
- *Brian Durand*
285
+ *Yuji Kamijima*
234
286
 
235
- * Fix parent record should not get saved with duplicate children records.
287
+ * Quote empty ranges like other empty enumerables.
236
288
 
237
- Fixes #32940.
289
+ *Patrick Rebsch*
238
290
 
239
- *Santosh Wadghule*
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`.
240
294
 
241
- * Fix that association's after_touch is not called with counter cache.
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.
242
298
 
243
- Fixes #31559.
299
+ *Bob Lail*
244
300
 
245
- *Ryuta Kamizono*
301
+ * Add `rails db:seed:replant` that truncates tables of each database
302
+ for current environment and loads the seeds.
246
303
 
247
- * `becomes` should clear the mutation tracker which is created in `after_initialize`.
304
+ *bogdanvlviv*, *DHH*
248
305
 
249
- Fixes #32867.
306
+ * Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
250
307
 
251
- *Ryuta Kamizono*
308
+ *bogdanvlviv*
252
309
 
253
- * Allow a belonging to parent object to be created from a new record.
310
+ * Deprecate mismatched collation comparison for uniqueness validator.
254
311
 
255
- *Jolyon Pawlyn*
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.
256
315
 
257
- * Fix that building record with assigning multiple has_one associations
258
- wrongly persists through record.
316
+ *Ryuta Kamizono*
259
317
 
260
- Fixes #32511.
318
+ * Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
261
319
 
262
- *Sam DeCesare*
320
+ Fixes #27340.
263
321
 
264
- * Fix relation merging when one of the relations is going to skip the
265
- query cache.
322
+ *Willian Gustavo Veiga*
266
323
 
267
- *James Williams*
324
+ * Add negative scopes for all enum values.
268
325
 
326
+ Example:
269
327
 
270
- ## Rails 5.2.0 (April 09, 2018) ##
328
+ class Post < ActiveRecord::Base
329
+ enum status: %i[ drafted active trashed ]
330
+ end
271
331
 
272
- * MySQL: Support mysql2 0.5.x.
332
+ Post.not_drafted # => where.not(status: :drafted)
333
+ Post.not_active # => where.not(status: :active)
334
+ Post.not_trashed # => where.not(status: :trashed)
273
335
 
274
- *Aaron Stone*
336
+ *DHH*
275
337
 
276
- * Apply time column precision on assignment.
338
+ * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
277
339
 
278
- PR #20317 changed the behavior of datetime columns so that when they
279
- have a specified precision then on assignment the value is rounded to
280
- that precision. This behavior is now applied to time columns as well.
340
+ Fixes #35214.
281
341
 
282
- Fixes #30301.
342
+ *Juani Villarejo*
283
343
 
284
- *Andrew White*
285
344
 
286
- * Normalize time column values for SQLite database.
345
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
287
346
 
288
- For legacy reasons, time columns in SQLite are stored as full datetimes
289
- because until #24542 the quoting for time columns didn't remove the date
290
- component. To ensure that values are consistent we now normalize the
291
- date component to 2001-01-01 on reading and writing.
347
+ * No changes.
292
348
 
293
- *Andrew White*
294
349
 
295
- * Ensure that the date component is removed when quoting times.
350
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
296
351
 
297
- PR #24542 altered the quoting for time columns so that the date component
298
- was removed however it only removed it when it was 2001-01-01. Now the
299
- date component is removed irrespective of what the date is.
352
+ * Fix prepared statements caching to be enabled even when query caching is enabled.
300
353
 
301
- *Andrew White*
354
+ *Ryuta Kamizono*
302
355
 
303
- * Fix `dependent: :destroy` issue for has_one/belongs_to relationship where
304
- the parent class was getting deleted when the child was not.
356
+ * Ensure `update_all` series cares about optimistic locking.
305
357
 
306
- Fixes #32022.
358
+ *Ryuta Kamizono*
307
359
 
308
- *Fernando Gorodscy*
360
+ * Don't allow `where` with non numeric string matches to 0 values.
309
361
 
310
- * Whitelist `NULLS FIRST` and `NULLS LAST` in order clauses too.
362
+ *Ryuta Kamizono*
311
363
 
312
- *Xavier Noria*
364
+ * Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
313
365
 
314
- * Fix that after commit callbacks on update does not triggered when optimistic locking is enabled.
366
+ `destroy_by` allows relation to find all the records matching the condition and perform
367
+ `destroy_all` on the matched records.
315
368
 
316
- *Ryuta Kamizono*
369
+ Example:
317
370
 
318
- * Fix `#columns_for_distinct` of MySQL and PostgreSQL to make
319
- `ActiveRecord::FinderMethods#limited_ids_for` use correct primary key values
320
- even if `ORDER BY` columns include other table's primary key.
371
+ Person.destroy_by(name: 'David')
372
+ Person.destroy_by(name: 'David', rating: 4)
321
373
 
322
- Fixes #28364.
374
+ david = Person.find_by(name: 'David')
375
+ david.posts.destroy_by(id: [1, 2, 3])
323
376
 
324
- *Takumi Kagiyama*
377
+ `delete_by` allows relation to find all the records matching the condition and perform
378
+ `delete_all` on the matched records.
325
379
 
326
- * Make `reflection.klass` raise if `polymorphic?` not to be misused.
380
+ Example:
327
381
 
328
- Fixes #31876.
382
+ Person.delete_by(name: 'David')
383
+ Person.delete_by(name: 'David', rating: 4)
329
384
 
330
- *Ryuta Kamizono*
385
+ david = Person.find_by(name: 'David')
386
+ david.posts.delete_by(id: [1, 2, 3])
331
387
 
332
- * PostgreSQL: Allow pg-1.0 gem to be used with Active Record.
388
+ *Abhay Nikam*
333
389
 
334
- *Lars Kanis*
390
+ * Don't allow `where` with invalid value matches to nil values.
335
391
 
336
- * Deprecate `expand_hash_conditions_for_aggregates` without replacement.
337
- Using a `Relation` for performing queries is the prefered API.
392
+ Fixes #33624.
338
393
 
339
394
  *Ryuta Kamizono*
340
395
 
341
- * Fix not expanded problem when passing an Array object as argument to the where method using `composed_of` column.
342
-
343
- ```
344
- david_balance = customers(:david).balance
345
- Customer.where(balance: [david_balance]).to_sql
396
+ * SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
346
397
 
347
- # Before: WHERE `customers`.`balance` = NULL
348
- # After : WHERE `customers`.`balance` = 50
349
- ```
398
+ *Ryuta Kamizono*
350
399
 
351
- Fixes #31723.
400
+ * Deprecate using class level querying methods if the receiver scope
401
+ regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
352
402
 
353
- *Yutaro Kanagawa*
403
+ *Ryuta Kamizono*
354
404
 
355
- * Fix `count(:all)` with eager loading and having an order other than the driving table.
405
+ * Allow applications to automatically switch connections.
356
406
 
357
- Fixes #31783.
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.
358
410
 
359
- *Ryuta Kamizono*
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.
360
417
 
361
- * Clear the transaction state when an Active Record object is duped.
418
+ To use the middleware in your application you can use the following
419
+ configuration options:
362
420
 
363
- Fixes #31670.
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
+ ```
364
426
 
365
- *Yuriy Ustushenko*
427
+ To change the database selection strategy, pass a custom class to the
428
+ configuration options:
366
429
 
367
- * Support for PostgreSQL foreign tables.
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
+ ```
368
435
 
369
- *fatkodima*
436
+ *Eileen M. Uchitelle*
370
437
 
371
- * Fix relation merger issue with `left_outer_joins`.
438
+ * MySQL: Support `:size` option to change text and blob size.
372
439
 
373
- *Mehmet Emin İNAÇ*
440
+ *Ryuta Kamizono*
374
441
 
375
- * Don't allow destroyed object mutation after `save` or `save!` is called.
442
+ * Make `t.timestamps` with precision by default.
376
443
 
377
444
  *Ryuta Kamizono*
378
445
 
379
- * Take into account association conditions when deleting through records.
380
446
 
381
- Fixes #18424.
447
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
382
448
 
383
- *Piotr Jakubowski*
449
+ * Remove deprecated `#set_state` from the transaction object.
384
450
 
385
- * Fix nested `has_many :through` associations on unpersisted parent instances.
451
+ *Rafael Mendonça França*
386
452
 
387
- For example, if you have
453
+ * Remove deprecated `#supports_statement_cache?` from the database adapters.
388
454
 
389
- class Post < ActiveRecord::Base
390
- belongs_to :author
391
- has_many :books, through: :author
392
- has_many :subscriptions, through: :books
393
- end
455
+ *Rafael Mendonça França*
394
456
 
395
- class Author < ActiveRecord::Base
396
- has_one :post
397
- has_many :books
398
- has_many :subscriptions, through: :books
399
- end
457
+ * Remove deprecated `#insert_fixtures` from the database adapters.
400
458
 
401
- class Book < ActiveRecord::Base
402
- belongs_to :author
403
- has_many :subscriptions
404
- end
459
+ *Rafael Mendonça França*
405
460
 
406
- class Subscription < ActiveRecord::Base
407
- belongs_to :book
408
- end
461
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
409
462
 
410
- Before:
463
+ *Rafael Mendonça França*
411
464
 
412
- If `post` is not persisted, then `post.subscriptions` will be empty.
465
+ * Do not allow passing the column name to `sum` when a block is passed.
413
466
 
414
- After:
467
+ *Rafael Mendonça França*
415
468
 
416
- If `post` is not persisted, then `post.subscriptions` can be set and used
417
- just like it would if `post` were persisted.
469
+ * Do not allow passing the column name to `count` when a block is passed.
418
470
 
419
- Fixes #16313.
471
+ *Rafael Mendonça França*
420
472
 
421
- *Zoltan Kiss*
473
+ * Remove delegation of missing methods in a relation to arel.
422
474
 
423
- * Fixed inconsistency with `first(n)` when used with `limit()`.
424
- The `first(n)` finder now respects the `limit()`, making it consistent
425
- with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
475
+ *Rafael Mendonça França*
426
476
 
427
- Fixes #23979.
477
+ * Remove delegation of missing methods in a relation to private methods of the class.
428
478
 
429
- *Brian Christian*
479
+ *Rafael Mendonça França*
430
480
 
431
- * Use `count(:all)` in `HasManyAssociation#count_records` to prevent invalid
432
- SQL queries for association counting.
481
+ * Deprecate `config.activerecord.sqlite3.represent_boolean_as_integer`.
433
482
 
434
- *Klas Eskilson*
483
+ *Rafael Mendonça França*
435
484
 
436
- * Fix to invoke callbacks when using `update_attribute`.
485
+ * Change `SQLite3Adapter` to always represent boolean values as integers.
437
486
 
438
- *Mike Busch*
487
+ *Rafael Mendonça França*
439
488
 
440
- * Fix `count(:all)` to correctly work `distinct` with custom SELECT list.
489
+ * Remove ability to specify a timestamp name for `#cache_key`.
441
490
 
442
- *Ryuta Kamizono*
491
+ *Rafael Mendonça França*
443
492
 
444
- * Using subselect for `delete_all` with `limit` or `offset`.
493
+ * Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
445
494
 
446
- *Ryuta Kamizono*
495
+ *Rafael Mendonça França*
447
496
 
448
- * Undefine attribute methods on descendants when resetting column
449
- information.
497
+ * Remove deprecated `expand_hash_conditions_for_aggregates`.
450
498
 
451
- *Chris Salzberg*
499
+ *Rafael Mendonça França*
452
500
 
453
- * Log database query callers.
501
+ * Set polymorphic type column to NULL on `dependent: :nullify` strategy.
454
502
 
455
- Add `verbose_query_logs` configuration option to display the caller
456
- of database queries in the log to facilitate N+1 query resolution
457
- and other debugging.
503
+ On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
458
504
 
459
- Enabled in development only for new and upgraded applications. Not
460
- recommended for use in the production environment since it relies
461
- on Ruby's `Kernel#caller_locations` which is fairly slow.
505
+ *Laerti Papa*
462
506
 
463
- *Olivier Lacan*
507
+ * Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
464
508
 
465
- * Fix conflicts `counter_cache` with `touch: true` by optimistic locking.
509
+ *Gannon McGibbon*
466
510
 
467
- ```
468
- # create_table :posts do |t|
469
- # t.integer :comments_count, default: 0
470
- # t.integer :lock_version
471
- # t.timestamps
472
- # end
473
- class Post < ApplicationRecord
474
- end
511
+ * Add support for endless ranges introduces in Ruby 2.6.
475
512
 
476
- # create_table :comments do |t|
477
- # t.belongs_to :post
478
- # end
479
- class Comment < ApplicationRecord
480
- belongs_to :post, touch: true, counter_cache: true
481
- end
482
- ```
513
+ *Greg Navis*
483
514
 
484
- Before:
485
- ```
486
- post = Post.create!
487
- # => begin transaction
488
- INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
489
- VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
490
- commit transaction
515
+ * Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
491
516
 
492
- comment = Comment.create!(post: post)
493
- # => begin transaction
494
- INSERT INTO "comments" ("post_id") VALUES (1)
517
+ *Ryuta Kamizono*
495
518
 
496
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
497
- "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
519
+ * MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
498
520
 
499
- UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
500
- "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
501
- rollback transaction
502
- # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
521
+ Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
522
+ format for InnoDB tables. The default setting is `DYNAMIC`.
523
+ The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
503
524
 
504
- Comment.take.destroy!
505
- # => begin transaction
506
- DELETE FROM "comments" WHERE "comments"."id" = 1
525
+ *Ryuta Kamizono*
507
526
 
508
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
509
- "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
527
+ * Fix join table column quoting with SQLite.
510
528
 
511
- UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
512
- "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
513
- rollback transaction
514
- # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
515
- ```
529
+ *Gannon McGibbon*
516
530
 
517
- After:
518
- ```
519
- post = Post.create!
520
- # => begin transaction
521
- INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
522
- VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
523
- commit transaction
531
+ * Allow disabling scopes generated by `ActiveRecord.enum`.
524
532
 
525
- comment = Comment.create!(post: post)
526
- # => begin transaction
527
- INSERT INTO "comments" ("post_id") VALUES (1)
533
+ *Alfred Dominic*
528
534
 
529
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
530
- "lock_version" = COALESCE("lock_version", 0) + 1,
531
- "updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
532
- commit transaction
535
+ * Ensure that `delete_all` on collection proxy returns affected count.
533
536
 
534
- comment.destroy!
535
- # => begin transaction
536
- DELETE FROM "comments" WHERE "comments"."id" = 1
537
+ *Ryuta Kamizono*
537
538
 
538
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
539
- "lock_version" = COALESCE("lock_version", 0) + 1,
540
- "updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
541
- commit transaction
542
- ```
539
+ * Reset scope after delete on collection association to clear stale offsets of removed records.
543
540
 
544
- Fixes #31199.
541
+ *Gannon McGibbon*
545
542
 
546
- *bogdanvlviv*
543
+ * Add the ability to prevent writes to a database for the duration of a block.
547
544
 
548
- * Add support for PostgreSQL operator classes to `add_index`.
545
+ Allows the application to prevent writes to a database. This can be useful when
546
+ you're building out multiple databases and want to make sure you're not sending
547
+ writes when you want a read.
549
548
 
550
- Example:
549
+ If `while_preventing_writes` is called and the query is considered a write
550
+ query the database will raise an exception regardless of whether the database
551
+ user is able to write.
551
552
 
552
- add_index :users, :name, using: :gist, opclass: { name: :gist_trgm_ops }
553
+ This is not meant to be a catch-all for write queries but rather a way to enforce
554
+ read-only queries without opening a second connection. One purpose of this is to
555
+ catch accidental writes, not all writes.
553
556
 
554
- *Greg Navis*
557
+ *Eileen M. Uchitelle*
555
558
 
556
- * Don't allow scopes to be defined which conflict with instance methods on `Relation`.
559
+ * Allow aliased attributes to be used in `#update_columns` and `#update`.
557
560
 
558
- Fixes #31120.
561
+ *Gannon McGibbon*
559
562
 
560
- *kinnrot*
563
+ * Allow spaces in postgres table names.
561
564
 
562
- * Add new error class `QueryCanceled` which will be raised
563
- when canceling statement due to user request.
565
+ Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
564
566
 
565
- *Ryuta Kamizono*
567
+ *Gannon McGibbon*
566
568
 
567
- * Add `#up_only` to database migrations for code that is only relevant when
568
- migrating up, e.g. populating a new column.
569
+ * Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
569
570
 
570
- *Rich Daley*
571
+ PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
572
+ was passing for SQLite and MySQL, but failed for PostgreSQL:
571
573
 
572
- * Require raw SQL fragments to be explicitly marked when used in
573
- relation query methods.
574
+ ```ruby
575
+ class DeveloperName < ActiveRecord::Type::String
576
+ def deserialize(value)
577
+ "Developer: #{value}"
578
+ end
579
+ end
574
580
 
575
- Before:
576
- ```
577
- Article.order("LENGTH(title)")
578
- ```
581
+ class AttributedDeveloper < ActiveRecord::Base
582
+ self.table_name = "developers"
579
583
 
580
- After:
581
- ```
582
- Article.order(Arel.sql("LENGTH(title)"))
583
- ```
584
+ attribute :name, DeveloperName.new
584
585
 
585
- This prevents SQL injection if applications use the [strongly
586
- discouraged] form `Article.order(params[:my_order])`, under the
587
- mistaken belief that only column names will be accepted.
586
+ self.ignored_columns += ["name"]
587
+ end
588
588
 
589
- Raw SQL strings will now cause a deprecation warning, which will
590
- become an UnknownAttributeReference error in Rails 6.0. Applications
591
- can opt in to the future behavior by setting `allow_unsafe_raw_sql`
592
- to `:disabled`.
589
+ developer = AttributedDeveloper.create
590
+ developer.update_column :name, "name"
593
591
 
594
- Common and judged-safe string values (such as simple column
595
- references) are unaffected:
596
- ```
597
- Article.order("title DESC")
592
+ loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
593
+ puts loaded_developer.name # should be "Developer: name" but it's just "name"
598
594
  ```
599
595
 
600
- *Ben Toews*
601
-
602
- * `update_all` will now pass its values to `Type#cast` before passing them to
603
- `Type#serialize`. This means that `update_all(foo: 'true')` will properly
604
- persist a boolean.
605
-
606
- *Sean Griffin*
607
-
608
- * Add new error class `StatementTimeout` which will be raised
609
- when statement timeout exceeded.
610
-
611
- *Ryuta Kamizono*
612
-
613
- * Fix `bin/rails db:migrate` with specified `VERSION`.
614
- `bin/rails db:migrate` with empty VERSION behaves as without `VERSION`.
615
- Check a format of `VERSION`: Allow a migration version number
616
- or name of a migration file. Raise error if format of `VERSION` is invalid.
617
- Raise error if target migration doesn't exist.
618
-
619
- *bogdanvlviv*
596
+ *Dmitry Tsepelev*
620
597
 
621
- * Fixed a bug where column orders for an index weren't written to
622
- `db/schema.rb` when using the sqlite adapter.
598
+ * Make the implicit order column configurable.
623
599
 
624
- Fixes #30902.
600
+ When calling ordered finder methods such as `first` or `last` without an
601
+ explicit order clause, ActiveRecord sorts records by primary key. This can
602
+ result in unpredictable and surprising behaviour when the primary key is
603
+ not an auto-incrementing integer, for example when it's a UUID. This change
604
+ makes it possible to override the column used for implicit ordering such
605
+ that `first` and `last` will return more predictable results.
625
606
 
626
- *Paul Kuruvilla*
607
+ Example:
627
608
 
628
- * Remove deprecated method `#sanitize_conditions`.
609
+ class Project < ActiveRecord::Base
610
+ self.implicit_order_column = "created_at"
611
+ end
629
612
 
630
- *Rafael Mendonça França*
613
+ *Tekin Suleyman*
631
614
 
632
- * Remove deprecated method `#scope_chain`.
615
+ * Bump minimum PostgreSQL version to 9.3.
633
616
 
634
- *Rafael Mendonça França*
617
+ *Yasuo Honda*
635
618
 
636
- * Remove deprecated configuration `.error_on_ignored_order_or_limit`.
619
+ * Values of enum are frozen, raising an error when attempting to modify them.
637
620
 
638
- *Rafael Mendonça França*
621
+ *Emmanuel Byrd*
639
622
 
640
- * Remove deprecated arguments from `#verify!`.
623
+ * Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
641
624
 
642
- *Rafael Mendonça França*
625
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
643
626
 
644
- * Remove deprecated argument `name` from `#indexes`.
627
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
645
628
 
646
- *Rafael Mendonça França*
629
+ Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
647
630
 
648
- * Remove deprecated method `ActiveRecord::Migrator.schema_migrations_table_name`.
631
+ Example:
649
632
 
650
- *Rafael Mendonça França*
633
+ ```
634
+ class MySubclassedError < ActiveRecord::StatementInvalid
635
+ def initialize(message, sql:, binds:)
636
+ super(message, sql: sql, binds: binds)
637
+ end
638
+ end
639
+ ```
651
640
 
652
- * Remove deprecated method `supports_primary_key?`.
641
+ *Gannon McGibbon*
653
642
 
654
- *Rafael Mendonça França*
643
+ * Add an `:if_not_exists` option to `create_table`.
655
644
 
656
- * Remove deprecated method `supports_migrations?`.
645
+ Example:
657
646
 
658
- *Rafael Mendonça França*
647
+ create_table :posts, if_not_exists: true do |t|
648
+ t.string :title
649
+ end
659
650
 
660
- * Remove deprecated methods `initialize_schema_migrations_table` and `initialize_internal_metadata_table`.
651
+ That would execute:
661
652
 
662
- *Rafael Mendonça França*
653
+ CREATE TABLE IF NOT EXISTS posts (
654
+ ...
655
+ )
663
656
 
664
- * Raises when calling `lock!` in a dirty record.
657
+ If the table already exists, `if_not_exists: false` (the default) raises an
658
+ exception whereas `if_not_exists: true` does nothing.
665
659
 
666
- *Rafael Mendonça França*
660
+ *fatkodima*, *Stefan Kanev*
667
661
 
668
- * Remove deprecated support to passing a class to `:class_name` on associations.
662
+ * Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
669
663
 
670
- *Rafael Mendonça França*
664
+ *Christophe Maximin*
671
665
 
672
- * Remove deprecated argument `default` from `index_name_exists?`.
666
+ * Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
673
667
 
674
- *Rafael Mendonça França*
668
+ *Gannon McGibbon*
675
669
 
676
- * Remove deprecated support to `quoted_id` when typecasting an Active Record object.
670
+ * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
671
+ if the attribute does not exist.
677
672
 
678
- *Rafael Mendonça França*
673
+ *Sean Griffin*
679
674
 
680
- * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
681
- ar_internal_metadata's data for a test database.
675
+ * Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
682
676
 
683
- Before:
684
- ```
685
- $ RAILS_ENV=test rails dbconsole
686
- > SELECT * FROM ar_internal_metadata;
687
- key|value|created_at|updated_at
688
- environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
689
- ```
677
+ ````
678
+ User.connected_to(database: { writing: "postgres://foo" }) do
679
+ User.create!(name: "Gannon")
680
+ end
690
681
 
691
- After:
692
- ```
693
- $ RAILS_ENV=test rails dbconsole
694
- > SELECT * FROM ar_internal_metadata;
695
- key|value|created_at|updated_at
696
- environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
697
- ```
682
+ config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
683
+ User.connected_to(database: { reading: config }) do
684
+ User.count
685
+ end
686
+ ````
698
687
 
699
- Fixes #26731.
688
+ *Gannon McGibbon*
700
689
 
701
- *bogdanvlviv*
690
+ * Support default expression for MySQL.
702
691
 
703
- * Fix longer sequence name detection for serial columns.
692
+ MySQL 8.0.13 and higher supports default value to be a function or expression.
704
693
 
705
- Fixes #28332.
694
+ https://dev.mysql.com/doc/refman/8.0/en/create-table.html
706
695
 
707
696
  *Ryuta Kamizono*
708
697
 
709
- * MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`.
710
-
711
- Fixes #30894.
698
+ * Support expression indexes for MySQL.
712
699
 
713
- *Ryuta Kamizono*
714
-
715
- * Fix `COUNT(DISTINCT ...)` for `GROUP BY` with `ORDER BY` and `LIMIT`.
700
+ MySQL 8.0.13 and higher supports functional key parts that index
701
+ expression values rather than column or column prefix values.
716
702
 
717
- Fixes #30886.
703
+ https://dev.mysql.com/doc/refman/8.0/en/create-index.html
718
704
 
719
705
  *Ryuta Kamizono*
720
706
 
721
- * PostgreSQL `tsrange` now preserves subsecond precision.
722
-
723
- PostgreSQL 9.1+ introduced range types, and Rails added support for using
724
- this datatype in Active Record. However, the serialization of
725
- `PostgreSQL::OID::Range` was incomplete, because it did not properly
726
- cast the bounds that make up the range. This led to subseconds being
727
- dropped in SQL commands:
707
+ * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
728
708
 
729
- Before:
709
+ Fixes #33056.
730
710
 
731
- connection.type_cast(tsrange.serialize(range_value))
732
- # => "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
711
+ *Federico Martinez*
733
712
 
734
- Now:
713
+ * Add basic API for connection switching to support multiple databases.
735
714
 
736
- connection.type_cast(tsrange.serialize(range_value))
737
- # => "[2010-01-01 13:30:00.670277,2011-02-02 19:30:00.745125)"
715
+ 1) Adds a `connects_to` method for models to connect to multiple databases. Example:
738
716
 
739
- *Thomas Cannon*
717
+ ```
718
+ class AnimalsModel < ApplicationRecord
719
+ self.abstract_class = true
740
720
 
741
- * Passing a `Set` to `Relation#where` now behaves the same as passing an
742
- array.
721
+ connects_to database: { writing: :animals_primary, reading: :animals_replica }
722
+ end
743
723
 
744
- *Sean Griffin*
724
+ class Dog < AnimalsModel
725
+ # connected to both the animals_primary db for writing and the animals_replica for reading
726
+ end
727
+ ```
745
728
 
746
- * Use given algorithm while removing index from database.
729
+ 2) Adds a `connected_to` block method for switching connection roles or connecting to
730
+ a database that the model didn't connect to. Connecting to the database in this block is
731
+ useful when you have another defined connection, for example `slow_replica` that you don't
732
+ want to connect to by default but need in the console, or a specific code block.
747
733
 
748
- Fixes #24190.
734
+ ```
735
+ ActiveRecord::Base.connected_to(role: :reading) do
736
+ Dog.first # finds dog from replica connected to AnimalsBase
737
+ Book.first # doesn't have a reading connection, will raise an error
738
+ end
739
+ ```
749
740
 
750
- *Mehmet Emin İNAÇ*
741
+ ```
742
+ ActiveRecord::Base.connected_to(database: :slow_replica) do
743
+ SlowReplicaModel.first # if the db config has a slow_replica configuration this will be used to do the lookup, otherwise this will throw an exception
744
+ end
745
+ ```
751
746
 
752
- * Update payload names for `sql.active_record` instrumentation to be
753
- more descriptive.
747
+ *Eileen M. Uchitelle*
754
748
 
755
- Fixes #30586.
749
+ * Enum raises on invalid definition values
756
750
 
757
- *Jeremy Green*
751
+ When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
752
+ commit checks that only valid definition values are provided, those can
753
+ be a Hash, an array of Symbols or an array of Strings. Otherwise it
754
+ raises an `ArgumentError`.
758
755
 
759
- * Add new error class `LockWaitTimeout` which will be raised
760
- when lock wait timeout exceeded.
756
+ Fixes #33961
761
757
 
762
- *Gabriel Courtemanche*
758
+ *Alberto Almagro*
763
759
 
764
- * Remove deprecated `#migration_keys`.
760
+ * Reloading associations now clears the Query Cache like `Persistence#reload` does.
765
761
 
766
- *Ryuta Kamizono*
762
+ ```
763
+ class Post < ActiveRecord::Base
764
+ has_one :category
765
+ belongs_to :author
766
+ has_many :comments
767
+ end
767
768
 
768
- * Automatically guess the inverse associations for STI.
769
+ # Each of the following will now clear the query cache.
770
+ post.reload_category
771
+ post.reload_author
772
+ post.comments.reload
773
+ ```
769
774
 
770
- *Yuichiro Kaneko*
775
+ *Christophe Maximin*
771
776
 
772
- * Ensure `sum` honors `distinct` on `has_many :through` associations.
777
+ * Added `index` option for `change_table` migration helpers.
778
+ With this change you can create indexes while adding new
779
+ columns into the existing tables.
773
780
 
774
- Fixes #16791.
781
+ Example:
775
782
 
776
- *Aaron Wortham*
783
+ change_table(:languages) do |t|
784
+ t.string :country_code, index: true
785
+ end
777
786
 
778
- * Add `binary` fixture helper method.
787
+ *Mehmet Emin İNAÇ*
779
788
 
780
- *Atsushi Yoshida*
789
+ * Fix `transaction` reverting for migrations.
781
790
 
782
- * When using `Relation#or`, extract the common conditions and put them before the OR condition.
791
+ Before: Commands inside a `transaction` in a reverted migration ran uninverted.
792
+ Now: This change fixes that by reverting commands inside `transaction` block.
783
793
 
784
- *Maxime Handfield Lapointe*
794
+ *fatkodima*, *David Verhasselt*
785
795
 
786
- * `Relation#or` now accepts two relations who have different values for
787
- `references` only, as `references` can be implicitly called by `where`.
796
+ * Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
788
797
 
789
- Fixes #29411.
798
+ *Gannon McGibbon*, *Max Albrecht*
790
799
 
791
- *Sean Griffin*
800
+ * Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
792
801
 
793
- * `ApplicationRecord` is no longer generated when generating models. If you
794
- need to generate it, it can be created with `rails g application_record`.
802
+ *Gannon McGibbon*
795
803
 
796
- *Lisa Ugray*
804
+ * Don't update counter cache unless the record is actually saved.
797
805
 
798
- * Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT` to keep the existing select list.
806
+ Fixes #31493, #33113, #33117.
799
807
 
800
808
  *Ryuta Kamizono*
801
809
 
802
- * When a `has_one` association is destroyed by `dependent: destroy`,
803
- `destroyed_by_association` will now be set to the reflection, matching the
804
- behaviour of `has_many` associations.
805
-
806
- *Lisa Ugray*
810
+ * Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
807
811
 
808
- * Fix `unscoped(where: [columns])` removing the wrong bind values.
812
+ *Gannon McGibbon*, *Kevin Cheng*
809
813
 
810
- When the `where` is called on a relation after a `or`, unscoping the column of that later `where` removed
811
- bind values used by the `or` instead. (possibly other cases too)
814
+ * SQLite3 adapter supports expression indexes.
812
815
 
813
816
  ```
814
- Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).to_sql
815
- # Currently:
816
- # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 2 OR "posts"."id" = 3)
817
- # With fix:
818
- # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1 OR "posts"."id" = 2)
817
+ create_table :users do |t|
818
+ t.string :email
819
+ end
820
+
821
+ add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
819
822
  ```
820
823
 
821
- *Maxime Handfield Lapointe*
824
+ *Gray Kemmey*
822
825
 
823
- * Values constructed using multi-parameter assignment will now use the
824
- post-type-cast value for rendering in single-field form inputs.
826
+ * Allow subclasses to redefine autosave callbacks for associated records.
825
827
 
826
- *Sean Griffin*
828
+ Fixes #33305.
827
829
 
828
- * `Relation#joins` is no longer affected by the target model's
829
- `current_scope`, with the exception of `unscoped`.
830
+ *Andrey Subbota*
830
831
 
831
- Fixes #29338.
832
+ * Bump minimum MySQL version to 5.5.8.
832
833
 
833
- *Sean Griffin*
834
+ *Yasuo Honda*
834
835
 
835
- * Change sqlite3 boolean serialization to use 1 and 0.
836
+ * Use MySQL utf8mb4 character set by default.
836
837
 
837
- SQLite natively recognizes 1 and 0 as true and false, but does not natively
838
- recognize 't' and 'f' as was previously serialized.
838
+ `utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
839
+ The previous default 3-Byte encoding character set `utf8` is not enough to support them.
839
840
 
840
- This change in serialization requires a migration of stored boolean data
841
- for SQLite databases, so it's implemented behind a configuration flag
842
- whose default false value is deprecated.
841
+ *Yasuo Honda*
843
842
 
844
- *Lisa Ugray*
843
+ * Fix duplicated record creation when using nested attributes with `create_with`.
845
844
 
846
- * Skip query caching when working with batches of records (`find_each`, `find_in_batches`,
847
- `in_batches`).
845
+ *Darwin Wu*
848
846
 
849
- Previously, records would be fetched in batches, but all records would be retained in memory
850
- until the end of the request or job.
847
+ * Configuration item `config.filter_parameters` could also filter out
848
+ sensitive values of database columns when calling `#inspect`.
849
+ We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
850
+ specify sensitive attributes to specific model.
851
851
 
852
- *Eugene Kenny*
852
+ ```
853
+ Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
854
+ Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
855
+ SecureAccount.filter_attributes += [:name]
856
+ SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
857
+ ```
853
858
 
854
- * Prevent errors raised by `sql.active_record` notification subscribers from being converted into
855
- `ActiveRecord::StatementInvalid` exceptions.
859
+ *Zhang Kang*, *Yoshiyuki Kinjo*
856
860
 
857
- *Dennis Taylor*
861
+ * Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
862
+ `indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
863
+ and `joins_per_query` methods in `DatabaseLimits`.
858
864
 
859
- * Fix eager loading/preloading association with scope including joins.
865
+ *Ryuta Kamizono*
860
866
 
861
- Fixes #28324.
867
+ * `ActiveRecord::Base.configurations` now returns an object.
862
868
 
863
- *Ryuta Kamizono*
869
+ `ActiveRecord::Base.configurations` used to return a hash, but this
870
+ is an inflexible data model. In order to improve multiple-database
871
+ handling in Rails, we've changed this to return an object. Some methods
872
+ are provided to make the object behave hash-like in order to ease the
873
+ transition process. Since most applications don't manipulate the hash
874
+ we've decided to add backwards-compatible functionality that will throw
875
+ a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
876
+ will use the new version internally and externally.
864
877
 
865
- * Fix transactions to apply state to child transactions.
878
+ For example, the following `database.yml`:
866
879
 
867
- Previously, if you had a nested transaction and the outer transaction was rolledback, the record from the
868
- inner transaction would still be marked as persisted.
880
+ ```
881
+ development:
882
+ adapter: sqlite3
883
+ database: db/development.sqlite3
884
+ ```
869
885
 
870
- This change fixes that by applying the state of the parent transaction to the child transaction when the
871
- parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
886
+ Used to become a hash:
872
887
 
873
- *Eileen M. Uchitelle*, *Aaron Patterson*
888
+ ```
889
+ { "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
890
+ ```
874
891
 
875
- * Deprecate `set_state` method in `TransactionState`.
892
+ Is now converted into the following object:
876
893
 
877
- Deprecated the `set_state` method in favor of setting the state via specific methods. If you need to mark the
878
- state of the transaction you can now use `rollback!`, `commit!` or `nullify!` instead of
879
- `set_state(:rolledback)`, `set_state(:committed)`, or `set_state(nil)`.
894
+ ```
895
+ #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
896
+ #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
897
+ @spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
898
+ ]
899
+ ```
880
900
 
881
- *Eileen M. Uchitelle*, *Aaron Patterson*
901
+ Iterating over the database configurations has also changed. Instead of
902
+ calling hash methods on the `configurations` hash directly, a new method `configs_for` has
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
905
+ database config objects for the requested environment and a single database config object
906
+ will be returned for the requested environment and specification name respectively.
882
907
 
883
- * Deprecate delegating to `arel` in `Relation`.
908
+ ```
909
+ ActiveRecord::Base.configurations.configs_for(env_name: "development")
910
+ ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
911
+ ```
884
912
 
885
- *Ryuta Kamizono*
913
+ *Eileen M. Uchitelle*, *Aaron Patterson*
914
+
915
+ * Add database configuration to disable advisory locks.
886
916
 
887
- * Query cache was unavailable when entering the `ActiveRecord::Base.cache` block
888
- without being connected.
917
+ ```
918
+ production:
919
+ adapter: postgresql
920
+ advisory_locks: false
921
+ ```
889
922
 
890
- *Tsukasa Oishi*
923
+ *Guo Xiang*
891
924
 
892
- * Previously, when building records using a `has_many :through` association,
893
- if the child records were deleted before the parent was saved, they would
894
- still be persisted. Now, if child records are deleted before the parent is saved
895
- on a `has_many :through` association, the child records will not be persisted.
925
+ * SQLite3 adapter `alter_table` method restores foreign keys.
896
926
 
897
- *Tobias Kraze*
927
+ *Yasuo Honda*
898
928
 
899
- * Merging two relations representing nested joins no longer transforms the joins of
900
- the merged relation into LEFT OUTER JOIN.
929
+ * Allow `:to_table` option to `invert_remove_foreign_key`.
901
930
 
902
931
  Example:
903
932
 
904
- ```
905
- Author.joins(:posts).merge(Post.joins(:comments))
906
- # Before the change:
907
- #=> SELECT ... FROM authors INNER JOIN posts ON ... LEFT OUTER JOIN comments ON...
933
+ remove_foreign_key :accounts, to_table: :owners
908
934
 
909
- # After the change:
910
- #=> SELECT ... FROM authors INNER JOIN posts ON ... INNER JOIN comments ON...
911
- ```
935
+ *Nikolay Epifanov*, *Rich Chen*
912
936
 
913
- *Maxime Handfield Lapointe*
937
+ * Add environment & load_config dependency to `bin/rake db:seed` to enable
938
+ seed load in environments without Rails and custom DB configuration
914
939
 
915
- * `ActiveRecord::Persistence#touch` does not work well when optimistic locking enabled and
916
- `locking_column`, without default value, is null in the database.
940
+ *Tobias Bielohlawek*
917
941
 
918
- *bogdanvlviv*
942
+ * Fix default value for mysql time types with specified precision.
919
943
 
920
- * Fix destroying existing object does not work well when optimistic locking enabled and
921
- `locking_column` is null in the database.
944
+ *Nikolay Kondratyev*
922
945
 
923
- *bogdanvlviv*
946
+ * Fix `touch` option to behave consistently with `Persistence#touch` method.
924
947
 
925
- * Use bulk INSERT to insert fixtures for better performance.
948
+ *Ryuta Kamizono*
926
949
 
927
- *Kir Shatrov*
950
+ * Migrations raise when duplicate column definition.
928
951
 
929
- * Prevent creation of bind param if casted value is nil.
952
+ Fixes #33024.
930
953
 
931
- *Ryuta Kamizono*
954
+ *Federico Martinez*
932
955
 
933
- * Deprecate passing arguments and block at the same time to `count` and `sum` in `ActiveRecord::Calculations`.
956
+ * Bump minimum SQLite version to 3.8
934
957
 
935
- *Ryuta Kamizono*
958
+ *Yasuo Honda*
936
959
 
937
- * Loading model schema from database is now thread-safe.
960
+ * Fix parent record should not get saved with duplicate children records.
938
961
 
939
- Fixes #28589.
962
+ Fixes #32940.
940
963
 
941
- *Vikrant Chaudhary*, *David Abdemoulaie*
964
+ *Santosh Wadghule*
942
965
 
943
- * Add `ActiveRecord::Base#cache_version` to support recyclable cache keys via the new versioned entries
944
- in `ActiveSupport::Cache`. This also means that `ActiveRecord::Base#cache_key` will now return a stable key
945
- that does not include a timestamp any more.
966
+ * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
946
967
 
947
- NOTE: This feature is turned off by default, and `#cache_key` will still return cache keys with timestamps
948
- until you set `ActiveRecord::Base.cache_versioning = true`. That's the setting for all new apps on Rails 5.2+
968
+ *Brian Durand*
949
969
 
950
- *DHH*
970
+ * Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
971
+ use loaded association ids if present.
951
972
 
952
- * Respect `SchemaDumper.ignore_tables` in rake tasks for databases structure dump.
973
+ *Graham Turner*
953
974
 
954
- *Rusty Geldmacher*, *Guillermo Iguaran*
975
+ * Add support to preload associations of polymorphic associations when not all the records have the requested associations.
955
976
 
956
- * Add type caster to `RuntimeReflection#alias_name`.
977
+ *Dana Sherson*
957
978
 
958
- Fixes #28959.
979
+ * Add `touch_all` method to `ActiveRecord::Relation`.
959
980
 
960
- *Jon Moss*
981
+ Example:
961
982
 
962
- * Deprecate `supports_statement_cache?`.
983
+ Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
963
984
 
964
- *Ryuta Kamizono*
985
+ *fatkodima*, *duggiefresh*
965
986
 
966
- * Raise error `UnknownMigrationVersionError` on the movement of migrations
967
- when the current migration does not exist.
987
+ * Add `ActiveRecord::Base.base_class?` predicate.
968
988
 
969
- *bogdanvlviv*
989
+ *Bogdan Gusiev*
970
990
 
971
- * Fix `bin/rails db:forward` first migration.
991
+ * Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
972
992
 
973
- *bogdanvlviv*
993
+ *Tan Huynh*, *Yukio Mizuta*
974
994
 
975
- * Support Descending Indexes for MySQL.
995
+ * Rails 6 requires Ruby 2.5.0 or newer.
976
996
 
977
- MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored.
978
- See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
997
+ *Jeremy Daer*, *Kasper Timm Hansen*
979
998
 
980
- *Ryuta Kamizono*
999
+ * Deprecate `update_attributes`/`!` in favor of `update`/`!`.
981
1000
 
982
- * Fix inconsistency with changed attributes when overriding Active Record attribute reader.
1001
+ *Eddie Lebow*
983
1002
 
984
- *bogdanvlviv*
1003
+ * Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
1004
+ `ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
985
1005
 
986
- * When calling the dynamic fixture accessor method with no arguments, it now returns all fixtures of this type.
987
- Previously this method always returned an empty array.
1006
+ *DHH*
988
1007
 
989
- *Kevin McPhillips*
1008
+ * Add `Relation#pick` as short-hand for single-value plucks.
1009
+
1010
+ *DHH*
990
1011
 
991
1012
 
992
- Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activerecord/CHANGELOG.md) for previous changes.
1013
+ Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.