activerecord 5.2.3 → 6.0.0.rc2

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