activerecord 5.1.6.2 → 5.2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +635 -650
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +5 -5
  5. data/examples/performance.rb +2 -0
  6. data/examples/simple.rb +2 -0
  7. data/lib/active_record/aggregations.rb +6 -5
  8. data/lib/active_record/association_relation.rb +7 -5
  9. data/lib/active_record/associations/alias_tracker.rb +19 -27
  10. data/lib/active_record/associations/association.rb +41 -37
  11. data/lib/active_record/associations/association_scope.rb +38 -50
  12. data/lib/active_record/associations/belongs_to_association.rb +28 -9
  13. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -8
  14. data/lib/active_record/associations/builder/association.rb +4 -7
  15. data/lib/active_record/associations/builder/belongs_to.rb +14 -5
  16. data/lib/active_record/associations/builder/collection_association.rb +3 -3
  17. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +3 -1
  18. data/lib/active_record/associations/builder/has_many.rb +2 -0
  19. data/lib/active_record/associations/builder/has_one.rb +2 -0
  20. data/lib/active_record/associations/builder/singular_association.rb +2 -0
  21. data/lib/active_record/associations/collection_association.rb +59 -47
  22. data/lib/active_record/associations/collection_proxy.rb +20 -49
  23. data/lib/active_record/associations/foreign_association.rb +2 -0
  24. data/lib/active_record/associations/has_many_association.rb +12 -1
  25. data/lib/active_record/associations/has_many_through_association.rb +36 -30
  26. data/lib/active_record/associations/has_one_association.rb +12 -1
  27. data/lib/active_record/associations/has_one_through_association.rb +13 -8
  28. data/lib/active_record/associations/join_dependency/join_association.rb +39 -63
  29. data/lib/active_record/associations/join_dependency/join_base.rb +9 -8
  30. data/lib/active_record/associations/join_dependency/join_part.rb +9 -9
  31. data/lib/active_record/associations/join_dependency.rb +48 -93
  32. data/lib/active_record/associations/preloader/association.rb +45 -61
  33. data/lib/active_record/associations/preloader/through_association.rb +71 -79
  34. data/lib/active_record/associations/preloader.rb +18 -38
  35. data/lib/active_record/associations/singular_association.rb +14 -16
  36. data/lib/active_record/associations/through_association.rb +26 -11
  37. data/lib/active_record/associations.rb +40 -63
  38. data/lib/active_record/attribute_assignment.rb +2 -5
  39. data/lib/active_record/attribute_decorators.rb +3 -2
  40. data/lib/active_record/attribute_methods/before_type_cast.rb +2 -0
  41. data/lib/active_record/attribute_methods/dirty.rb +32 -216
  42. data/lib/active_record/attribute_methods/primary_key.rb +7 -6
  43. data/lib/active_record/attribute_methods/query.rb +2 -0
  44. data/lib/active_record/attribute_methods/read.rb +9 -3
  45. data/lib/active_record/attribute_methods/serialization.rb +23 -0
  46. data/lib/active_record/attribute_methods/time_zone_conversion.rb +6 -8
  47. data/lib/active_record/attribute_methods/write.rb +21 -9
  48. data/lib/active_record/attribute_methods.rb +65 -24
  49. data/lib/active_record/attributes.rb +6 -5
  50. data/lib/active_record/autosave_association.rb +35 -19
  51. data/lib/active_record/base.rb +2 -0
  52. data/lib/active_record/callbacks.rb +12 -6
  53. data/lib/active_record/coders/json.rb +2 -0
  54. data/lib/active_record/coders/yaml_column.rb +15 -1
  55. data/lib/active_record/collection_cache_key.rb +12 -8
  56. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +142 -42
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +7 -0
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +174 -33
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +15 -5
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +14 -31
  61. data/lib/active_record/connection_adapters/abstract/savepoints.rb +2 -0
  62. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +14 -5
  63. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +64 -6
  64. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +31 -53
  65. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +152 -81
  66. data/lib/active_record/connection_adapters/abstract/transaction.rb +66 -21
  67. data/lib/active_record/connection_adapters/abstract_adapter.rb +84 -97
  68. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +110 -173
  69. data/lib/active_record/connection_adapters/column.rb +3 -1
  70. data/lib/active_record/connection_adapters/connection_specification.rb +17 -3
  71. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +13 -2
  72. data/lib/active_record/connection_adapters/mysql/column.rb +2 -0
  73. data/lib/active_record/connection_adapters/mysql/database_statements.rb +47 -2
  74. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +2 -0
  75. data/lib/active_record/connection_adapters/mysql/quoting.rb +9 -10
  76. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +5 -3
  77. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +7 -10
  78. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +30 -30
  79. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +106 -1
  80. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +2 -0
  81. data/lib/active_record/connection_adapters/mysql2_adapter.rb +8 -2
  82. data/lib/active_record/connection_adapters/postgresql/column.rb +2 -0
  83. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +6 -0
  84. data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +2 -0
  85. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +13 -1
  86. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +2 -0
  87. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
  88. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +2 -0
  89. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +2 -0
  90. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
  91. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +2 -0
  92. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +2 -0
  93. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +2 -0
  94. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +2 -0
  95. data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
  96. data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -1
  97. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +2 -0
  98. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +5 -3
  99. data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +2 -0
  100. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +2 -0
  101. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +8 -2
  102. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +2 -0
  103. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +4 -2
  104. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +3 -1
  105. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +2 -0
  106. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +2 -0
  107. data/lib/active_record/connection_adapters/postgresql/oid.rb +3 -1
  108. data/lib/active_record/connection_adapters/postgresql/quoting.rb +18 -0
  109. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +19 -25
  110. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +50 -0
  111. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +24 -11
  112. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +20 -13
  113. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +233 -111
  114. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +2 -0
  115. data/lib/active_record/connection_adapters/postgresql/utils.rb +3 -1
  116. data/lib/active_record/connection_adapters/postgresql_adapter.rb +66 -74
  117. data/lib/active_record/connection_adapters/schema_cache.rb +4 -2
  118. data/lib/active_record/connection_adapters/sql_type_metadata.rb +2 -0
  119. data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +2 -0
  120. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +23 -0
  121. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +2 -0
  122. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +6 -15
  123. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +3 -2
  124. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +75 -1
  125. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +82 -95
  126. data/lib/active_record/connection_adapters/statement_pool.rb +2 -0
  127. data/lib/active_record/connection_handling.rb +4 -2
  128. data/lib/active_record/core.rb +51 -61
  129. data/lib/active_record/counter_cache.rb +20 -15
  130. data/lib/active_record/define_callbacks.rb +5 -3
  131. data/lib/active_record/dynamic_matchers.rb +9 -9
  132. data/lib/active_record/enum.rb +18 -13
  133. data/lib/active_record/errors.rb +60 -15
  134. data/lib/active_record/explain.rb +3 -1
  135. data/lib/active_record/explain_registry.rb +2 -0
  136. data/lib/active_record/explain_subscriber.rb +2 -0
  137. data/lib/active_record/fixture_set/file.rb +2 -0
  138. data/lib/active_record/fixtures.rb +67 -60
  139. data/lib/active_record/gem_version.rb +5 -3
  140. data/lib/active_record/inheritance.rb +49 -19
  141. data/lib/active_record/integration.rb +58 -19
  142. data/lib/active_record/internal_metadata.rb +2 -0
  143. data/lib/active_record/legacy_yaml_adapter.rb +3 -1
  144. data/lib/active_record/locking/optimistic.rb +14 -17
  145. data/lib/active_record/locking/pessimistic.rb +9 -6
  146. data/lib/active_record/log_subscriber.rb +43 -0
  147. data/lib/active_record/migration/command_recorder.rb +11 -9
  148. data/lib/active_record/migration/compatibility.rb +47 -9
  149. data/lib/active_record/migration/join_table.rb +2 -0
  150. data/lib/active_record/migration.rb +189 -139
  151. data/lib/active_record/model_schema.rb +16 -21
  152. data/lib/active_record/nested_attributes.rb +18 -6
  153. data/lib/active_record/no_touching.rb +3 -1
  154. data/lib/active_record/null_relation.rb +2 -0
  155. data/lib/active_record/persistence.rb +169 -17
  156. data/lib/active_record/query_cache.rb +6 -8
  157. data/lib/active_record/querying.rb +4 -2
  158. data/lib/active_record/railtie.rb +80 -6
  159. data/lib/active_record/railties/console_sandbox.rb +2 -0
  160. data/lib/active_record/railties/controller_runtime.rb +2 -0
  161. data/lib/active_record/railties/databases.rake +46 -36
  162. data/lib/active_record/readonly_attributes.rb +3 -2
  163. data/lib/active_record/reflection.rb +108 -194
  164. data/lib/active_record/relation/batches/batch_enumerator.rb +2 -0
  165. data/lib/active_record/relation/batches.rb +20 -5
  166. data/lib/active_record/relation/calculations.rb +45 -19
  167. data/lib/active_record/relation/delegation.rb +45 -27
  168. data/lib/active_record/relation/finder_methods.rb +77 -78
  169. data/lib/active_record/relation/from_clause.rb +2 -8
  170. data/lib/active_record/relation/merger.rb +53 -23
  171. data/lib/active_record/relation/predicate_builder/array_handler.rb +10 -7
  172. data/lib/active_record/relation/predicate_builder/association_query_value.rb +46 -0
  173. data/lib/active_record/relation/predicate_builder/base_handler.rb +2 -2
  174. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +12 -1
  175. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +56 -0
  176. data/lib/active_record/relation/predicate_builder/range_handler.rb +26 -9
  177. data/lib/active_record/relation/predicate_builder/relation_handler.rb +6 -0
  178. data/lib/active_record/relation/predicate_builder.rb +60 -79
  179. data/lib/active_record/relation/query_attribute.rb +28 -2
  180. data/lib/active_record/relation/query_methods.rb +129 -100
  181. data/lib/active_record/relation/record_fetch_warning.rb +2 -0
  182. data/lib/active_record/relation/spawn_methods.rb +4 -2
  183. data/lib/active_record/relation/where_clause.rb +65 -68
  184. data/lib/active_record/relation/where_clause_factory.rb +5 -48
  185. data/lib/active_record/relation.rb +120 -214
  186. data/lib/active_record/result.rb +2 -0
  187. data/lib/active_record/runtime_registry.rb +2 -0
  188. data/lib/active_record/sanitization.rb +129 -121
  189. data/lib/active_record/schema.rb +4 -2
  190. data/lib/active_record/schema_dumper.rb +36 -26
  191. data/lib/active_record/schema_migration.rb +2 -0
  192. data/lib/active_record/scoping/default.rb +8 -9
  193. data/lib/active_record/scoping/named.rb +23 -7
  194. data/lib/active_record/scoping.rb +9 -8
  195. data/lib/active_record/secure_token.rb +2 -0
  196. data/lib/active_record/serialization.rb +2 -0
  197. data/lib/active_record/statement_cache.rb +23 -13
  198. data/lib/active_record/store.rb +3 -1
  199. data/lib/active_record/suppressor.rb +2 -0
  200. data/lib/active_record/table_metadata.rb +12 -3
  201. data/lib/active_record/tasks/database_tasks.rb +26 -15
  202. data/lib/active_record/tasks/mysql_database_tasks.rb +9 -48
  203. data/lib/active_record/tasks/postgresql_database_tasks.rb +10 -2
  204. data/lib/active_record/tasks/sqlite_database_tasks.rb +25 -3
  205. data/lib/active_record/timestamp.rb +13 -6
  206. data/lib/active_record/touch_later.rb +2 -0
  207. data/lib/active_record/transactions.rb +33 -28
  208. data/lib/active_record/translation.rb +2 -0
  209. data/lib/active_record/type/adapter_specific_registry.rb +2 -0
  210. data/lib/active_record/type/date.rb +2 -0
  211. data/lib/active_record/type/date_time.rb +2 -0
  212. data/lib/active_record/type/decimal_without_scale.rb +2 -0
  213. data/lib/active_record/type/hash_lookup_type_map.rb +2 -0
  214. data/lib/active_record/type/internal/timezone.rb +2 -0
  215. data/lib/active_record/type/json.rb +30 -0
  216. data/lib/active_record/type/serialized.rb +6 -0
  217. data/lib/active_record/type/text.rb +2 -0
  218. data/lib/active_record/type/time.rb +2 -0
  219. data/lib/active_record/type/type_map.rb +2 -0
  220. data/lib/active_record/type/unsigned_integer.rb +2 -0
  221. data/lib/active_record/type.rb +4 -1
  222. data/lib/active_record/type_caster/connection.rb +2 -0
  223. data/lib/active_record/type_caster/map.rb +3 -1
  224. data/lib/active_record/type_caster.rb +2 -0
  225. data/lib/active_record/validations/absence.rb +2 -0
  226. data/lib/active_record/validations/associated.rb +2 -0
  227. data/lib/active_record/validations/length.rb +2 -0
  228. data/lib/active_record/validations/presence.rb +2 -0
  229. data/lib/active_record/validations/uniqueness.rb +35 -5
  230. data/lib/active_record/validations.rb +2 -0
  231. data/lib/active_record/version.rb +2 -0
  232. data/lib/active_record.rb +11 -4
  233. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +27 -0
  234. data/lib/rails/generators/active_record/migration/migration_generator.rb +3 -1
  235. data/lib/rails/generators/active_record/migration.rb +2 -0
  236. data/lib/rails/generators/active_record/model/model_generator.rb +2 -23
  237. data/lib/rails/generators/active_record.rb +3 -1
  238. metadata +26 -39
  239. data/lib/active_record/associations/preloader/belongs_to.rb +0 -15
  240. data/lib/active_record/associations/preloader/collection_association.rb +0 -17
  241. data/lib/active_record/associations/preloader/has_many.rb +0 -15
  242. data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
  243. data/lib/active_record/associations/preloader/has_one.rb +0 -15
  244. data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
  245. data/lib/active_record/associations/preloader/singular_association.rb +0 -18
  246. data/lib/active_record/attribute/user_provided_default.rb +0 -30
  247. data/lib/active_record/attribute.rb +0 -240
  248. data/lib/active_record/attribute_mutation_tracker.rb +0 -114
  249. data/lib/active_record/attribute_set/builder.rb +0 -126
  250. data/lib/active_record/attribute_set/yaml_encoder.rb +0 -41
  251. data/lib/active_record/attribute_set.rb +0 -113
  252. data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -10
  253. data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
  254. data/lib/active_record/relation/predicate_builder/association_query_handler.rb +0 -88
  255. data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +0 -59
  256. data/lib/active_record/type/internal/abstract_json.rb +0 -37
  257. /data/lib/rails/generators/active_record/{model/templates/application_record.rb → application_record/templates/application_record.rb.tt} +0 -0
  258. /data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +0 -0
  259. /data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +0 -0
  260. /data/lib/rails/generators/active_record/model/templates/{model.rb → model.rb.tt} +0 -0
  261. /data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
data/CHANGELOG.md CHANGED
@@ -1,1099 +1,1084 @@
1
- ## Rails 5.1.6.2 (March 11, 2019) ##
1
+ ## Rails 5.2.8.1 (July 12, 2022) ##
2
+
3
+ * Change ActiveRecord::Coders::YAMLColumn default to safe_load
4
+
5
+ This adds two new configuration options The configuration options are as
6
+ follows:
7
+
8
+ * `config.active_storage.use_yaml_unsafe_load`
9
+
10
+ When set to true, this configuration option tells Rails to use the old
11
+ "unsafe" YAML loading strategy, maintaining the existing behavior but leaving
12
+ the possible escalation vulnerability in place. Setting this option to true
13
+ is *not* recommended, but can aid in upgrading.
14
+
15
+ * `config.active_record.yaml_column_permitted_classes`
16
+
17
+ The "safe YAML" loading method does not allow all classes to be deserialized
18
+ by default. This option allows you to specify classes deemed "safe" in your
19
+ application. For example, if your application uses Symbol and Time in
20
+ serialized data, you can add Symbol and Time to the allowed list as follows:
21
+
22
+ ```
23
+ config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
24
+ ```
2
25
 
3
- * No changes.
26
+ [CVE-2022-32224]
4
27
 
5
28
 
6
- ## Rails 5.1.6.1 (November 27, 2018) ##
29
+ ## Rails 5.2.8 (May 09, 2022) ##
7
30
 
8
31
  * No changes.
9
32
 
10
33
 
11
- ## Rails 5.1.6 (March 29, 2018) ##
34
+ ## Rails 5.2.7.1 (April 26, 2022) ##
12
35
 
13
- * MySQL: Support mysql2 0.5.x.
36
+ * No changes.
14
37
 
15
- *Aaron Stone*
16
38
 
17
- * Apply time column precision on assignment.
39
+ ## Rails 5.2.7 (March 10, 2022) ##
18
40
 
19
- PR #20317 changed the behavior of datetime columns so that when they
20
- have a specified precision then on assignment the value is rounded to
21
- that precision. This behavior is now applied to time columns as well.
41
+ * No changes.
22
42
 
23
- Fixes #30301.
24
43
 
25
- *Andrew White*
44
+ ## Rails 5.2.6.3 (March 08, 2022) ##
26
45
 
27
- * Normalize time column values for SQLite database.
46
+ * No changes.
28
47
 
29
- For legacy reasons, time columns in SQLite are stored as full datetimes
30
- because until #24542 the quoting for time columns didn't remove the date
31
- component. To ensure that values are consistent we now normalize the
32
- date component to 2001-01-01 on reading and writing.
33
48
 
34
- *Andrew White*
49
+ ## Rails 5.2.6.2 (February 11, 2022) ##
35
50
 
36
- * Ensure that the date component is removed when quoting times.
51
+ * No changes.
37
52
 
38
- PR #24542 altered the quoting for time columns so that the date component
39
- was removed however it only removed it when it was 2001-01-01. Now the
40
- date component is removed irrespective of what the date is.
41
53
 
42
- *Andrew White*
54
+ ## Rails 5.2.6.1 (February 11, 2022) ##
43
55
 
44
- * Fix that after commit callbacks on update does not triggered when optimistic locking is enabled.
56
+ * No changes.
45
57
 
46
- *Ryuta Kamizono*
47
58
 
48
- * `ActiveRecord::Persistence#touch` does not work well when optimistic locking enabled and
49
- `locking_column`, without default value, is null in the database.
59
+ ## Rails 5.2.6 (May 05, 2021) ##
50
60
 
51
- *bogdanvlviv*
61
+ * No changes.
52
62
 
53
- * Fix destroying existing object does not work well when optimistic locking enabled and
54
- `locking column` is null in the database.
55
63
 
56
- *bogdanvlviv*
64
+ ## Rails 5.2.5 (March 26, 2021) ##
57
65
 
66
+ * No changes.
58
67
 
59
- ## Rails 5.1.5 (February 14, 2018) ##
60
68
 
61
- * PostgreSQL: Allow pg-1.0 gem to be used with Active Record.
69
+ ## Rails 5.2.4.6 (May 05, 2021) ##
62
70
 
63
- *Lars Kanis*
71
+ * No changes.
64
72
 
65
- * Fix `count(:all)` with eager loading and having an order other than the driving table.
66
73
 
67
- Fixes #31783.
74
+ ## Rails 5.2.4.5 (February 10, 2021) ##
68
75
 
69
- *Ryuta Kamizono*
76
+ * Fix possible DoS vector in PostgreSQL money type
70
77
 
71
- * Use `count(:all)` in `HasManyAssociation#count_records` to prevent invalid
72
- SQL queries for association counting.
78
+ Carefully crafted input can cause a DoS via the regular expressions used
79
+ for validating the money format in the PostgreSQL adapter. This patch
80
+ fixes the regexp.
73
81
 
74
- *Klas Eskilson*
82
+ Thanks to @dee-see from Hackerone for this patch!
75
83
 
76
- * Fix to invoke callbacks when using `update_attribute`.
84
+ [CVE-2021-22880]
77
85
 
78
- *Mike Busch*
86
+ *Aaron Patterson*
79
87
 
80
- * Fix `count(:all)` to correctly work `distinct` with custom SELECT list.
81
88
 
82
- *Ryuta Kamizono*
89
+ ## Rails 5.2.4.4 (September 09, 2020) ##
83
90
 
84
- * Fix conflicts `counter_cache` with `touch: true` by optimistic locking.
91
+ * No changes.
85
92
 
86
- ```
87
- # create_table :posts do |t|
88
- # t.integer :comments_count, default: 0
89
- # t.integer :lock_version
90
- # t.timestamps
91
- # end
92
- class Post < ApplicationRecord
93
- end
94
93
 
95
- # create_table :comments do |t|
96
- # t.belongs_to :post
97
- # end
98
- class Comment < ApplicationRecord
99
- belongs_to :post, touch: true, counter_cache: true
100
- end
101
- ```
94
+ ## Rails 5.2.4.3 (May 18, 2020) ##
102
95
 
103
- Before:
104
- ```
105
- post = Post.create!
106
- # => begin transaction
107
- INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
108
- VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
109
- commit transaction
96
+ * No changes.
110
97
 
111
- comment = Comment.create!(post: post)
112
- # => begin transaction
113
- INSERT INTO "comments" ("post_id") VALUES (1)
98
+ ## Rails 5.2.4.2 (March 19, 2020) ##
114
99
 
115
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
116
- "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
100
+ * No changes.
117
101
 
118
- UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
119
- "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
120
- rollback transaction
121
- # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
122
102
 
123
- Comment.take.destroy!
124
- # => begin transaction
125
- DELETE FROM "comments" WHERE "comments"."id" = 1
103
+ ## Rails 5.2.4.1 (December 18, 2019) ##
126
104
 
127
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
128
- "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
105
+ * No changes.
129
106
 
130
- UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
131
- "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
132
- rollback transaction
133
- # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
134
- ```
135
107
 
136
- After:
137
- ```
138
- post = Post.create!
139
- # => begin transaction
140
- INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
141
- VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
142
- commit transaction
108
+ ## Rails 5.2.4 (November 27, 2019) ##
143
109
 
144
- comment = Comment.create!(post: post)
145
- # => begin transaction
146
- INSERT INTO "comments" ("post_id") VALUES (1)
110
+ * Fix circular `autosave: true` causes invalid records to be saved.
147
111
 
148
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
149
- "lock_version" = COALESCE("lock_version", 0) + 1,
150
- "updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
151
- commit transaction
112
+ Prior to the fix, when there was a circular series of `autosave: true`
113
+ associations, the callback for a `has_many` association was run while
114
+ another instance of the same callback on the same association hadn't
115
+ finished running. When control returned to the first instance of the
116
+ callback, the instance variable had changed, and subsequent associated
117
+ records weren't saved correctly. Specifically, the ID field for the
118
+ `belongs_to` corresponding to the `has_many` was `nil`.
152
119
 
153
- comment.destroy!
154
- # => begin transaction
155
- DELETE FROM "comments" WHERE "comments"."id" = 1
120
+ Fixes #28080.
156
121
 
157
- UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
158
- "lock_version" = COALESCE("lock_version", 0) + 1,
159
- "updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
160
- commit transaction
161
- ```
122
+ *Larry Reid*
162
123
 
163
- Fixes #31199.
124
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
164
125
 
165
- *bogdanvlviv*
126
+ Fixes #36022.
166
127
 
167
- * Query cache was unavailable when entering the `ActiveRecord::Base.cache` block
168
- without being connected.
128
+ *Ryuta Kamizono*
169
129
 
170
- *Tsukasa Oishi*
130
+ * Fix sqlite3 collation parsing when using decimal columns.
171
131
 
172
- * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
173
- ar_internal_metadata's data for a test database.
132
+ *Martin R. Schuster*
174
133
 
175
- Before:
176
- ```
177
- $ RAILS_ENV=test rails dbconsole
178
- > SELECT * FROM ar_internal_metadata;
179
- key|value|created_at|updated_at
180
- environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
181
- ```
134
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
182
135
 
183
- After:
184
- ```
185
- $ RAILS_ENV=test rails dbconsole
186
- > SELECT * FROM ar_internal_metadata;
187
- key|value|created_at|updated_at
188
- environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
189
- ```
136
+ Fixes #36465.
190
137
 
191
- Fixes #26731.
138
+ *Jeff Doering*
192
139
 
193
- *bogdanvlviv*
140
+ * Assign all attributes before calling `build` to ensure the child record is visible in
141
+ `before_add` and `after_add` callbacks for `has_many :through` associations.
194
142
 
195
- * Fix longer sequence name detection for serial columns.
143
+ Fixes #33249.
196
144
 
197
- Fixes #28332.
145
+ *Ryan H. Kerr*
198
146
 
199
- *Ryuta Kamizono*
200
147
 
201
- * MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`.
148
+ ## Rails 5.2.3 (March 27, 2019) ##
202
149
 
203
- Fixes #30894.
150
+ * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
204
151
 
205
- *Ryuta Kamizono*
152
+ Fixes #35214.
206
153
 
207
- * Fix `COUNT(DISTINCT ...)` for `GROUP BY` with `ORDER BY` and `LIMIT`.
154
+ *Juani Villarejo*
208
155
 
209
- Fixes #30886.
156
+ * Fix prepared statements caching to be enabled even when query caching is enabled.
210
157
 
211
158
  *Ryuta Kamizono*
212
159
 
160
+ * Don't allow `where` with invalid value matches to nil values.
213
161
 
214
- ## Rails 5.1.4 (September 07, 2017) ##
215
-
216
- * No changes.
217
-
162
+ Fixes #33624.
218
163
 
219
- ## Rails 5.1.4.rc1 (August 24, 2017) ##
220
-
221
- * Ensure `sum` honors `distinct` on `has_many :through` associations
222
-
223
- Fixes #16791
164
+ *Ryuta Kamizono*
224
165
 
225
- *Aaron Wortham
166
+ * Restore an ability that class level `update` without giving ids.
226
167
 
227
- * Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT` to keep the existing select list.
168
+ Fixes #34743.
228
169
 
229
170
  *Ryuta Kamizono*
230
171
 
231
- * Fix `unscoped(where: [columns])` removing the wrong bind values
172
+ * Fix join table column quoting with SQLite.
232
173
 
233
- When the `where` is called on a relation after a `or`, unscoping the column of that later `where`, it removed
234
- bind values used by the `or` instead.
174
+ *Gannon McGibbon*
235
175
 
236
- ```
237
- Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).to_sql
238
- # Currently:
239
- # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 2 OR "posts"."id" = 3)
240
- # With fix:
241
- # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1 OR "posts"."id" = 2)
242
- ```
176
+ * Ensure that `delete_all` on collection proxy returns affected count.
243
177
 
244
- *Maxime Handfield Lapointe*
178
+ *Ryuta Kamizono*
245
179
 
246
- * When a `has_one` association is destroyed by `dependent: destroy`,
247
- `destroyed_by_association` will now be set to the reflection, matching the
248
- behaviour of `has_many` associations.
180
+ * Reset scope after delete on collection association to clear stale offsets of removed records.
249
181
 
250
- *Lisa Ugray*
182
+ *Gannon McGibbon*
251
183
 
252
184
 
253
- ## Rails 5.1.3 (August 03, 2017) ##
185
+ ## Rails 5.2.2.1 (March 11, 2019) ##
254
186
 
255
187
  * No changes.
256
188
 
257
189
 
258
- ## Rails 5.1.3.rc3 (July 31, 2017) ##
259
-
260
- * No changes.
190
+ ## Rails 5.2.2 (December 04, 2018) ##
261
191
 
192
+ * Do not ignore the scoping with query methods in the scope block.
262
193
 
263
- ## Rails 5.1.3.rc2 (July 25, 2017) ##
194
+ *Ryuta Kamizono*
264
195
 
265
- * No changes.
196
+ * Allow aliased attributes to be used in `#update_columns` and `#update`.
266
197
 
198
+ *Gannon McGibbon*
267
199
 
268
- ## Rails 5.1.3.rc1 (July 19, 2017) ##
200
+ * Allow spaces in postgres table names.
269
201
 
270
- * `Relation#joins` is no longer affected by the target model's
271
- `current_scope`, with the exception of `unscoped`.
202
+ Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres
203
+ adapter.
272
204
 
273
- Fixes #29338.
205
+ *Gannon McGibbon*
274
206
 
275
- *Sean Griffin*
207
+ * Cached columns_hash fields should be excluded from ResultSet#column_types
276
208
 
277
- * Previously, when building records using a `has_many :through` association,
278
- if the child records were deleted before the parent was saved, they would
279
- still be persisted. Now, if child records are deleted before the parent is saved
280
- on a `has_many :through` association, the child records will not be persisted.
209
+ PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
210
+ was passing for SQLite and MySQL, but failed for PostgreSQL:
281
211
 
282
- *Tobias Kraze*
212
+ ```ruby
213
+ class DeveloperName < ActiveRecord::Type::String
214
+ def deserialize(value)
215
+ "Developer: #{value}"
216
+ end
217
+ end
283
218
 
219
+ class AttributedDeveloper < ActiveRecord::Base
220
+ self.table_name = "developers"
284
221
 
285
- ## Rails 5.1.2 (June 26, 2017) ##
222
+ attribute :name, DeveloperName.new
286
223
 
287
- * Restore previous behavior of collection proxies: their values can have
288
- methods stubbed, and they respect extension modules applied by a default
289
- scope.
224
+ self.ignored_columns += ["name"]
225
+ end
290
226
 
291
- *Ryuta Kamizono*
227
+ developer = AttributedDeveloper.create
228
+ developer.update_column :name, "name"
292
229
 
293
- * Loading model schema from database is now thread-safe.
230
+ loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
231
+ puts loaded_developer.name # should be "Developer: name" but it's just "name"
232
+ ```
294
233
 
295
- Fixes #28589.
234
+ *Dmitry Tsepelev*
296
235
 
297
- *Vikrant Chaudhary*, *David Abdemoulaie*
236
+ * Values of enum are frozen, raising an error when attempting to modify them.
298
237
 
238
+ *Emmanuel Byrd*
299
239
 
300
- ## Rails 5.1.1 (May 12, 2017) ##
240
+ * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
241
+ if the attribute does not exist.
301
242
 
302
- * Add type caster to `RuntimeReflection#alias_name`
243
+ *Sean Griffin*
303
244
 
304
- Fixes #28959.
245
+ * Do not use prepared statement in queries that have a large number of binds.
305
246
 
306
- *Jon Moss*
247
+ *Ryuta Kamizono*
307
248
 
249
+ * Fix query cache to load before first request.
308
250
 
309
- ## Rails 5.1.0 (April 27, 2017) ##
251
+ *Eileen M. Uchitelle*
310
252
 
311
- * Quote database name in db:create grant statement (when database_user does not have access to create the database).
253
+ * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
312
254
 
313
- *Rune Philosof*
255
+ Fixes #33056.
314
256
 
315
- * When multiple threads are sharing a database connection inside a test using
316
- transactional fixtures, a nested transaction will temporarily lock the
317
- connection to the current thread, forcing others to wait.
257
+ *Federico Martinez*
318
258
 
319
- Fixes #28197.
259
+ * Fix duplicated record creation when using nested attributes with `create_with`.
320
260
 
321
- *Matthew Draper*
261
+ *Darwin Wu*
322
262
 
323
- * Load only needed records on `ActiveRecord::Relation#inspect`.
263
+ * Fix regression setting children record in parent `before_save` callback.
324
264
 
325
- Instead of loading all records and returning only a subset of those, just
326
- load the records as needed.
265
+ *Guo Xiang Tan*
327
266
 
328
- Fixes #25537.
267
+ * Prevent leaking of user's DB credentials on `rails db:create` failure.
329
268
 
330
- *Hendy Tanata*
269
+ *bogdanvlviv*
331
270
 
332
- * Remove comments from structure.sql when using postgresql adapter to avoid
333
- version-specific parts of the file.
271
+ * Clear mutation tracker before continuing the around callbacks.
334
272
 
335
- Fixes #28153.
273
+ *Yuya Tanaka*
336
274
 
337
- *Ari Pollak*
275
+ * Prevent deadlocks when waiting for connection from pool.
338
276
 
339
- * Add `:default` option to `belongs_to`.
277
+ *Brent Wheeldon*
340
278
 
341
- Use it to specify that an association should be initialized with a particular
342
- record before validation. For example:
279
+ * Avoid extra scoping when using `Relation#update` that was causing this method to change the current scope.
343
280
 
344
- # Before
345
- belongs_to :account
346
- before_validation -> { self.account ||= Current.account }
281
+ *Ryuta Kamizono*
347
282
 
348
- # After
349
- belongs_to :account, default: -> { Current.account }
283
+ * Fix numericality validator not to be affected by custom getter.
350
284
 
351
- *George Claghorn*
285
+ *Ryuta Kamizono*
352
286
 
353
- * Deprecate `Migrator.schema_migrations_table_name`.
287
+ * Fix bulk change table ignores comment option on PostgreSQL.
354
288
 
355
- *Ryuta Kamizono*
289
+ *Yoshiyuki Kinjo*
356
290
 
357
- * Fix select with block doesn't return newly built records in has_many association.
358
291
 
359
- Fixes #28348.
292
+ ## Rails 5.2.1.1 (November 27, 2018) ##
360
293
 
361
- *Ryuta Kamizono*
294
+ * No changes.
362
295
 
363
- * Check whether `Rails.application` defined before calling it
364
296
 
365
- In #27674 we changed the migration generator to generate migrations at the
366
- path defined in `Rails.application.config.paths` however the code checked
367
- for the presence of the `Rails` constant but not the `Rails.application`
368
- method which caused problems when using Active Record and generators outside
369
- of the context of a Rails application.
297
+ ## Rails 5.2.1 (August 07, 2018) ##
370
298
 
371
- Fixes #28325.
299
+ * PostgreSQL: Support new relkind for partitioned tables.
372
300
 
373
- *Andrew White*
301
+ Fixes #33008.
374
302
 
375
- * Fix `deserialize` with JSON array.
303
+ *Yannick Schutz*
376
304
 
377
- Fixes #28285.
305
+ * Rollback parent transaction when children fails to update.
378
306
 
379
- *Ryuta Kamizono*
307
+ *Guillaume Malette*
380
308
 
381
- * Fix `rake db:schema:load` with subdirectories.
309
+ * Fix default value for MySQL time types with specified precision.
382
310
 
383
- *Ryuta Kamizono*
311
+ *Nikolay Kondratyev*
384
312
 
385
- * Fix `rake db:migrate:status` with subdirectories.
313
+ * Fix `touch` option to behave consistently with `Persistence#touch` method.
386
314
 
387
315
  *Ryuta Kamizono*
388
316
 
389
- * Don't share options between reference id and type columns
317
+ * Fix `save` in `after_create_commit` won't invoke extra `after_create_commit`.
390
318
 
391
- When using a polymorphic reference column in a migration, sharing options
392
- between the two columns doesn't make sense since they are different types.
393
- The `reference_id` column is usually an integer and the `reference_type`
394
- column a string so options like `unsigned: true` will result in an invalid
395
- table definition.
319
+ Fixes #32831.
396
320
 
397
321
  *Ryuta Kamizono*
398
322
 
399
- * Use `max_identifier_length` for `index_name_length` in PostgreSQL adapter.
323
+ * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
400
324
 
401
- *Ryuta Kamizono*
325
+ *Brian Durand*
402
326
 
403
- * Deprecate `supports_migrations?` on connection adapters.
327
+ * Fix parent record should not get saved with duplicate children records.
404
328
 
405
- *Ryuta Kamizono*
329
+ Fixes #32940.
406
330
 
407
- * Fix regression of #1969 with SELECT aliases in HAVING clause.
331
+ *Santosh Wadghule*
408
332
 
409
- *Eugene Kenny*
333
+ * Fix that association's after_touch is not called with counter cache.
410
334
 
411
- * Deprecate using `#quoted_id` in quoting.
335
+ Fixes #31559.
412
336
 
413
337
  *Ryuta Kamizono*
414
338
 
415
- * Fix `wait_timeout` to configurable for mysql2 adapter.
339
+ * `becomes` should clear the mutation tracker which is created in `after_initialize`.
416
340
 
417
- Fixes #26556.
341
+ Fixes #32867.
418
342
 
419
343
  *Ryuta Kamizono*
420
344
 
421
- * Correctly dump native timestamp types for MySQL.
422
-
423
- The native timestamp type in MySQL is different from datetime type.
424
- Internal representation of the timestamp type is UNIX time, This means
425
- that timestamp columns are affected by time zone.
345
+ * Allow a belonging to parent object to be created from a new record.
426
346
 
427
- > SET time_zone = '+00:00';
428
- Query OK, 0 rows affected (0.00 sec)
347
+ *Jolyon Pawlyn*
429
348
 
430
- > INSERT INTO time_with_zone(ts,dt) VALUES (NOW(),NOW());
431
- Query OK, 1 row affected (0.02 sec)
349
+ * Fix that building record with assigning multiple has_one associations
350
+ wrongly persists through record.
432
351
 
433
- > SELECT * FROM time_with_zone;
434
- +---------------------+---------------------+
435
- | ts | dt |
436
- +---------------------+---------------------+
437
- | 2016-02-07 22:11:44 | 2016-02-07 22:11:44 |
438
- +---------------------+---------------------+
439
- 1 row in set (0.00 sec)
352
+ Fixes #32511.
440
353
 
441
- > SET time_zone = '-08:00';
442
- Query OK, 0 rows affected (0.00 sec)
354
+ *Sam DeCesare*
443
355
 
444
- > SELECT * FROM time_with_zone;
445
- +---------------------+---------------------+
446
- | ts | dt |
447
- +---------------------+---------------------+
448
- | 2016-02-07 14:11:44 | 2016-02-07 22:11:44 |
449
- +---------------------+---------------------+
450
- 1 row in set (0.00 sec)
356
+ * Fix relation merging when one of the relations is going to skip the
357
+ query cache.
451
358
 
452
- *Ryuta Kamizono*
453
-
454
- * All integer-like PKs are autoincrement unless they have an explicit default.
359
+ *James Williams*
455
360
 
456
- *Matthew Draper*
457
361
 
458
- * Omit redundant `using: :btree` for schema dumping.
362
+ ## Rails 5.2.0 (April 09, 2018) ##
459
363
 
460
- *Ryuta Kamizono*
364
+ * MySQL: Support mysql2 0.5.x.
461
365
 
462
- * Deprecate passing `default` to `index_name_exists?`.
366
+ *Aaron Stone*
463
367
 
464
- *Ryuta Kamizono*
368
+ * Apply time column precision on assignment.
465
369
 
466
- * PostgreSQL: schema dumping support for interval and OID columns.
370
+ PR #20317 changed the behavior of datetime columns so that when they
371
+ have a specified precision then on assignment the value is rounded to
372
+ that precision. This behavior is now applied to time columns as well.
467
373
 
468
- *Ryuta Kamizono*
374
+ Fixes #30301.
469
375
 
470
- * Deprecate `supports_primary_key?` on connection adapters since it's
471
- been long unused and unsupported.
376
+ *Andrew White*
472
377
 
473
- *Ryuta Kamizono*
378
+ * Normalize time column values for SQLite database.
474
379
 
475
- * Make `table_name=` reset current statement cache,
476
- so queries are not run against the previous table name.
380
+ For legacy reasons, time columns in SQLite are stored as full datetimes
381
+ because until #24542 the quoting for time columns didn't remove the date
382
+ component. To ensure that values are consistent we now normalize the
383
+ date component to 2001-01-01 on reading and writing.
477
384
 
478
- *namusyaka*
385
+ *Andrew White*
479
386
 
480
- * Allow `ActiveRecord::Base#as_json` to be passed a frozen Hash.
387
+ * Ensure that the date component is removed when quoting times.
481
388
 
482
- *Isaac Betesh*
389
+ PR #24542 altered the quoting for time columns so that the date component
390
+ was removed however it only removed it when it was 2001-01-01. Now the
391
+ date component is removed irrespective of what the date is.
483
392
 
484
- * Fix inspection behavior when the :id column is not primary key.
393
+ *Andrew White*
485
394
 
486
- *namusyaka*
395
+ * Fix `dependent: :destroy` issue for has_one/belongs_to relationship where
396
+ the parent class was getting deleted when the child was not.
487
397
 
488
- * Deprecate locking records with unpersisted changes.
398
+ Fixes #32022.
489
399
 
490
- *Marc Schütz*
400
+ *Fernando Gorodscy*
491
401
 
492
- * Remove deprecated behavior that halts callbacks when the return is false.
402
+ * Whitelist `NULLS FIRST` and `NULLS LAST` in order clauses too.
493
403
 
494
- *Rafael Mendonça França*
404
+ *Xavier Noria*
495
405
 
496
- * Deprecate `ColumnDumper#migration_keys`.
406
+ * Fix that after commit callbacks on update does not triggered when optimistic locking is enabled.
497
407
 
498
408
  *Ryuta Kamizono*
499
409
 
500
- * Fix `association_primary_key_type` for reflections with symbol primary key.
410
+ * Fix `#columns_for_distinct` of MySQL and PostgreSQL to make
411
+ `ActiveRecord::FinderMethods#limited_ids_for` use correct primary key values
412
+ even if `ORDER BY` columns include other table's primary key.
501
413
 
502
- Fixes #27864.
414
+ Fixes #28364.
503
415
 
504
- *Daniel Colson*
416
+ *Takumi Kagiyama*
505
417
 
506
- * Virtual/generated column support for MySQL 5.7.5+ and MariaDB 5.2.0+.
418
+ * Make `reflection.klass` raise if `polymorphic?` not to be misused.
507
419
 
508
- MySQL generated columns: https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html
509
- MariaDB virtual columns: https://mariadb.com/kb/en/mariadb/virtual-computed-columns/
420
+ Fixes #31876.
510
421
 
511
- Declare virtual columns with `t.virtual name, type: …, as: "expression"`.
512
- Pass `stored: true` to persist the generated value (false by default).
422
+ *Ryuta Kamizono*
513
423
 
514
- Example:
424
+ * PostgreSQL: Allow pg-1.0 gem to be used with Active Record.
515
425
 
516
- create_table :generated_columns do |t|
517
- t.string :name
518
- t.virtual :upper_name, type: :string, as: "UPPER(name)"
519
- t.virtual :name_length, type: :integer, as: "LENGTH(name)", stored: true
520
- t.index :name_length # May be indexed, too!
521
- end
426
+ *Lars Kanis*
427
+
428
+ * Deprecate `expand_hash_conditions_for_aggregates` without replacement.
429
+ Using a `Relation` for performing queries is the prefered API.
522
430
 
523
431
  *Ryuta Kamizono*
524
432
 
525
- * Deprecate `initialize_schema_migrations_table` and `initialize_internal_metadata_table`.
433
+ * Fix not expanded problem when passing an Array object as argument to the where method using `composed_of` column.
526
434
 
527
- *Ryuta Kamizono*
435
+ ```
436
+ david_balance = customers(:david).balance
437
+ Customer.where(balance: [david_balance]).to_sql
528
438
 
529
- * Support foreign key creation for SQLite3.
439
+ # Before: WHERE `customers`.`balance` = NULL
440
+ # After : WHERE `customers`.`balance` = 50
441
+ ```
530
442
 
531
- *Ryuta Kamizono*
443
+ Fixes #31723.
532
444
 
533
- * Place generated migrations into the path set by `config.paths["db/migrate"]`.
445
+ *Yutaro Kanagawa*
534
446
 
535
- *Kevin Glowacz*
447
+ * Fix `count(:all)` with eager loading and having an order other than the driving table.
536
448
 
537
- * Raise `ActiveRecord::InvalidForeignKey` when a foreign key constraint fails on SQLite3.
449
+ Fixes #31783.
538
450
 
539
451
  *Ryuta Kamizono*
540
452
 
541
- * Add the touch option to `#increment!` and `#decrement!`.
453
+ * Clear the transaction state when an Active Record object is duped.
542
454
 
543
- *Hiroaki Izu*
455
+ Fixes #31670.
544
456
 
545
- * Deprecate passing a class to the `class_name` because it eagerloads more classes than
546
- necessary and potentially creates circular dependencies.
457
+ *Yuriy Ustushenko*
547
458
 
548
- *Kir Shatrov*
459
+ * Support for PostgreSQL foreign tables.
549
460
 
550
- * Raise error when has_many through is defined before through association.
461
+ *fatkodima*
551
462
 
552
- Fixes #26834.
463
+ * Fix relation merger issue with `left_outer_joins`.
553
464
 
554
- *Chris Holmes*
465
+ *Mehmet Emin İNAÇ*
555
466
 
556
- * Deprecate passing `name` to `indexes`.
467
+ * Don't allow destroyed object mutation after `save` or `save!` is called.
557
468
 
558
469
  *Ryuta Kamizono*
559
470
 
560
- * Remove deprecated tasks: `db:test:clone`, `db:test:clone_schema`, `db:test:clone_structure`.
471
+ * Take into account association conditions when deleting through records.
561
472
 
562
- *Rafel Mendonça França*
473
+ Fixes #18424.
563
474
 
564
- * Compare deserialized values for `PostgreSQL::OID::Hstore` types when
565
- calling `ActiveRecord::Dirty#changed_in_place?`.
475
+ *Piotr Jakubowski*
566
476
 
567
- Fixes #27502.
477
+ * Fix nested `has_many :through` associations on unpersisted parent instances.
568
478
 
569
- *Jon Moss*
479
+ For example, if you have
570
480
 
571
- * Raise `ArgumentError` when passing an `ActiveRecord::Base` instance to `.find`,
572
- `.exists?` and `.update`.
481
+ class Post < ActiveRecord::Base
482
+ belongs_to :author
483
+ has_many :books, through: :author
484
+ has_many :subscriptions, through: :books
485
+ end
573
486
 
574
- *Rafael Mendonça França*
487
+ class Author < ActiveRecord::Base
488
+ has_one :post
489
+ has_many :books
490
+ has_many :subscriptions, through: :books
491
+ end
575
492
 
576
- * Respect precision option for arrays of timestamps.
493
+ class Book < ActiveRecord::Base
494
+ belongs_to :author
495
+ has_many :subscriptions
496
+ end
577
497
 
578
- Fixes #27514.
498
+ class Subscription < ActiveRecord::Base
499
+ belongs_to :book
500
+ end
579
501
 
580
- *Sean Griffin*
502
+ Before:
581
503
 
582
- * Optimize slow model instantiation when using STI and `store_full_sti_class = false` option.
504
+ If `post` is not persisted, then `post.subscriptions` will be empty.
583
505
 
584
- *Konstantin Lazarev*
506
+ After:
585
507
 
586
- * Add `touch` option to counter cache modifying methods.
508
+ If `post` is not persisted, then `post.subscriptions` can be set and used
509
+ just like it would if `post` were persisted.
587
510
 
588
- Works when updating, resetting, incrementing and decrementing counters:
511
+ Fixes #16313.
589
512
 
590
- # Touches `updated_at`/`updated_on`.
591
- Topic.increment_counter(:messages_count, 1, touch: true)
592
- Topic.decrement_counter(:messages_count, 1, touch: true)
513
+ *Zoltan Kiss*
593
514
 
594
- # Touches `last_discussed_at`.
595
- Topic.reset_counters(18, :messages, touch: :last_discussed_at)
515
+ * Fixed inconsistency with `first(n)` when used with `limit()`.
516
+ The `first(n)` finder now respects the `limit()`, making it consistent
517
+ with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
596
518
 
597
- # Touches `updated_at` and `last_discussed_at`.
598
- Topic.update_counters(18, messages_count: 5, touch: %i( updated_at last_discussed_at ))
519
+ Fixes #23979.
599
520
 
600
- Fixes #26724.
521
+ *Brian Christian*
601
522
 
602
- *Jarred Trost*
523
+ * Use `count(:all)` in `HasManyAssociation#count_records` to prevent invalid
524
+ SQL queries for association counting.
603
525
 
604
- * Remove deprecated `#uniq`, `#uniq!`, and `#uniq_value`.
526
+ *Klas Eskilson*
605
527
 
606
- *Ryuta Kamizono*
528
+ * Fix to invoke callbacks when using `update_attribute`.
607
529
 
608
- * Remove deprecated `#insert_sql`, `#update_sql`, and `#delete_sql`.
530
+ *Mike Busch*
609
531
 
610
- *Ryuta Kamizono*
532
+ * Fix `count(:all)` to correctly work `distinct` with custom SELECT list.
611
533
 
612
- * Remove deprecated `#use_transactional_fixtures` configuration.
534
+ *Ryuta Kamizono*
613
535
 
614
- *Rafael Mendonça França*
536
+ * Using subselect for `delete_all` with `limit` or `offset`.
615
537
 
616
- * Remove deprecated `#raise_in_transactional_callbacks` configuration.
538
+ *Ryuta Kamizono*
617
539
 
618
- *Rafael Mendonça França*
540
+ * Undefine attribute methods on descendants when resetting column
541
+ information.
619
542
 
620
- * Remove deprecated `#load_schema_for`.
543
+ *Chris Salzberg*
621
544
 
622
- *Rafael Mendonça França*
545
+ * Log database query callers.
623
546
 
624
- * Remove deprecated conditions parameter from `#destroy_all` and `#delete_all`.
547
+ Add `verbose_query_logs` configuration option to display the caller
548
+ of database queries in the log to facilitate N+1 query resolution
549
+ and other debugging.
625
550
 
626
- *Rafael Mendonça França*
551
+ Enabled in development only for new and upgraded applications. Not
552
+ recommended for use in the production environment since it relies
553
+ on Ruby's `Kernel#caller_locations` which is fairly slow.
627
554
 
628
- * Remove deprecated support to passing arguments to `#select` when a block is provided.
555
+ *Olivier Lacan*
629
556
 
630
- *Rafael Mendonça França*
557
+ * Fix conflicts `counter_cache` with `touch: true` by optimistic locking.
631
558
 
632
- * Remove deprecated support to query using commas on LIMIT.
559
+ ```
560
+ # create_table :posts do |t|
561
+ # t.integer :comments_count, default: 0
562
+ # t.integer :lock_version
563
+ # t.timestamps
564
+ # end
565
+ class Post < ApplicationRecord
566
+ end
633
567
 
634
- *Rafael Mendonça França*
568
+ # create_table :comments do |t|
569
+ # t.belongs_to :post
570
+ # end
571
+ class Comment < ApplicationRecord
572
+ belongs_to :post, touch: true, counter_cache: true
573
+ end
574
+ ```
635
575
 
636
- * Remove deprecated support to passing a class as a value in a query.
576
+ Before:
577
+ ```
578
+ post = Post.create!
579
+ # => begin transaction
580
+ INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
581
+ VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
582
+ commit transaction
637
583
 
638
- *Rafael Mendonça França*
584
+ comment = Comment.create!(post: post)
585
+ # => begin transaction
586
+ INSERT INTO "comments" ("post_id") VALUES (1)
639
587
 
640
- * Raise `ActiveRecord::IrreversibleOrderError` when using `last` with an irreversible
641
- order.
588
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
589
+ "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
642
590
 
643
- *Rafael Mendonça França*
591
+ UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
592
+ "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
593
+ rollback transaction
594
+ # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
644
595
 
645
- * Raise when a `has_many :through` association has an ambiguous reflection name.
596
+ Comment.take.destroy!
597
+ # => begin transaction
598
+ DELETE FROM "comments" WHERE "comments"."id" = 1
646
599
 
647
- *Rafael Mendonça França*
600
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
601
+ "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
648
602
 
649
- * Raise when `ActiveRecord::Migration` is inherited from directly.
603
+ UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
604
+ "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
605
+ rollback transaction
606
+ # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
607
+ ```
650
608
 
651
- *Rafael Mendonça França*
609
+ After:
610
+ ```
611
+ post = Post.create!
612
+ # => begin transaction
613
+ INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
614
+ VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
615
+ commit transaction
652
616
 
653
- * Remove deprecated `original_exception` argument in `ActiveRecord::StatementInvalid#initialize`
654
- and `ActiveRecord::StatementInvalid#original_exception`.
617
+ comment = Comment.create!(post: post)
618
+ # => begin transaction
619
+ INSERT INTO "comments" ("post_id") VALUES (1)
655
620
 
656
- *Rafael Mendonça França*
621
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
622
+ "lock_version" = COALESCE("lock_version", 0) + 1,
623
+ "updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
624
+ commit transaction
657
625
 
658
- * `#tables` and `#table_exists?` return only tables and not views.
626
+ comment.destroy!
627
+ # => begin transaction
628
+ DELETE FROM "comments" WHERE "comments"."id" = 1
659
629
 
660
- All the deprecations on those methods were removed.
630
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
631
+ "lock_version" = COALESCE("lock_version", 0) + 1,
632
+ "updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
633
+ commit transaction
634
+ ```
661
635
 
662
- *Rafael Mendonça França*
636
+ Fixes #31199.
663
637
 
664
- * Remove deprecated `name` argument from `#tables`.
638
+ *bogdanvlviv*
665
639
 
666
- *Rafael Mendonça França*
640
+ * Add support for PostgreSQL operator classes to `add_index`.
667
641
 
668
- * Remove deprecated support to passing a column to `#quote`.
642
+ Example:
669
643
 
670
- *Rafael Mendonça França*
644
+ add_index :users, :name, using: :gist, opclass: { name: :gist_trgm_ops }
671
645
 
672
- * Set `:time` as a timezone aware type and remove deprecation when
673
- `config.active_record.time_zone_aware_types` is not explicitly set.
646
+ *Greg Navis*
674
647
 
675
- *Rafael Mendonça França*
648
+ * Don't allow scopes to be defined which conflict with instance methods on `Relation`.
676
649
 
677
- * Remove deprecated force reload argument in singular and collection association readers.
650
+ Fixes #31120.
678
651
 
679
- *Rafael Mendonça França*
652
+ *kinnrot*
680
653
 
681
- * Remove deprecated `activerecord.errors.messages.restrict_dependent_destroy.one` and
682
- `activerecord.errors.messages.restrict_dependent_destroy.many` i18n scopes.
654
+ * Add new error class `QueryCanceled` which will be raised
655
+ when canceling statement due to user request.
683
656
 
684
- *Rafael Mendonça França*
657
+ *Ryuta Kamizono*
685
658
 
686
- * Allow passing extra flags to `db:structure:load` and `db:structure:dump`
659
+ * Add `#up_only` to database migrations for code that is only relevant when
660
+ migrating up, e.g. populating a new column.
687
661
 
688
- Introduces `ActiveRecord::Tasks::DatabaseTasks.structure_(load|dump)_flags` to customize the
689
- eventual commands run against the database, e.g. mysqldump/pg_dump.
662
+ *Rich Daley*
690
663
 
691
- *Kir Shatrov*
664
+ * Require raw SQL fragments to be explicitly marked when used in
665
+ relation query methods.
692
666
 
693
- * Notifications see frozen SQL string.
667
+ Before:
668
+ ```
669
+ Article.order("LENGTH(title)")
670
+ ```
694
671
 
695
- Fixes #23774.
672
+ After:
673
+ ```
674
+ Article.order(Arel.sql("LENGTH(title)"))
675
+ ```
696
676
 
697
- *Richard Monette*
677
+ This prevents SQL injection if applications use the [strongly
678
+ discouraged] form `Article.order(params[:my_order])`, under the
679
+ mistaken belief that only column names will be accepted.
698
680
 
699
- * RuntimeErrors are no longer translated to `ActiveRecord::StatementInvalid`.
681
+ Raw SQL strings will now cause a deprecation warning, which will
682
+ become an UnknownAttributeReference error in Rails 6.0. Applications
683
+ can opt in to the future behavior by setting `allow_unsafe_raw_sql`
684
+ to `:disabled`.
700
685
 
701
- *Richard Monette*
686
+ Common and judged-safe string values (such as simple column
687
+ references) are unaffected:
688
+ ```
689
+ Article.order("title DESC")
690
+ ```
702
691
 
703
- * Change the schema cache format to use YAML instead of Marshal.
692
+ *Ben Toews*
704
693
 
705
- *Kir Shatrov*
694
+ * `update_all` will now pass its values to `Type#cast` before passing them to
695
+ `Type#serialize`. This means that `update_all(foo: 'true')` will properly
696
+ persist a boolean.
706
697
 
707
- * Support index length and order options using both string and symbol
708
- column names.
698
+ *Sean Griffin*
709
699
 
710
- Fixes #27243.
700
+ * Add new error class `StatementTimeout` which will be raised
701
+ when statement timeout exceeded.
711
702
 
712
703
  *Ryuta Kamizono*
713
704
 
714
- * Raise `ActiveRecord::RangeError` when values that executed are out of range.
705
+ * Fix `bin/rails db:migrate` with specified `VERSION`.
706
+ `bin/rails db:migrate` with empty VERSION behaves as without `VERSION`.
707
+ Check a format of `VERSION`: Allow a migration version number
708
+ or name of a migration file. Raise error if format of `VERSION` is invalid.
709
+ Raise error if target migration doesn't exist.
715
710
 
716
- *Ryuta Kamizono*
711
+ *bogdanvlviv*
717
712
 
718
- * Raise `ActiveRecord::NotNullViolation` when a record cannot be inserted
719
- or updated because it would violate a not null constraint.
713
+ * Fixed a bug where column orders for an index weren't written to
714
+ `db/schema.rb` when using the sqlite adapter.
720
715
 
721
- *Ryuta Kamizono*
716
+ Fixes #30902.
722
717
 
723
- * Emulate db trigger behaviour for after_commit :destroy, :update.
718
+ *Paul Kuruvilla*
724
719
 
725
- Race conditions can occur when an ActiveRecord is destroyed
726
- twice or destroyed and updated. The callbacks should only be
727
- triggered once, similar to a SQL database trigger.
720
+ * Remove deprecated method `#sanitize_conditions`.
728
721
 
729
- *Stefan Budeanu*
722
+ *Rafael Mendonça França*
730
723
 
731
- * Moved `DecimalWithoutScale`, `Text`, and `UnsignedInteger` from Active Model to Active Record.
724
+ * Remove deprecated method `#scope_chain`.
732
725
 
733
- *Iain Beeston*
726
+ *Rafael Mendonça França*
734
727
 
735
- * Fix `write_attribute` method to check whether an attribute is aliased or not, and
736
- use the aliased attribute name if needed.
728
+ * Remove deprecated configuration `.error_on_ignored_order_or_limit`.
737
729
 
738
- *Prathamesh Sonpatki*
730
+ *Rafael Mendonça França*
739
731
 
740
- * Fix `read_attribute` method to check whether an attribute is aliased or not, and
741
- use the aliased attribute name if needed.
732
+ * Remove deprecated arguments from `#verify!`.
742
733
 
743
- Fixes #26417.
734
+ *Rafael Mendonça França*
744
735
 
745
- *Prathamesh Sonpatki*
736
+ * Remove deprecated argument `name` from `#indexes`.
746
737
 
747
- * PostgreSQL & MySQL: Use big integer as primary key type for new tables.
738
+ *Rafael Mendonça França*
748
739
 
749
- *Jon McCartie*, *Pavel Pravosud*
740
+ * Remove deprecated method `ActiveRecord::Migrator.schema_migrations_table_name`.
750
741
 
751
- * Change the type argument of `ActiveRecord::Base#attribute` to be optional.
752
- The default is now `ActiveRecord::Type::Value.new`, which provides no type
753
- casting behavior.
742
+ *Rafael Mendonça França*
754
743
 
755
- *Sean Griffin*
744
+ * Remove deprecated method `supports_primary_key?`.
756
745
 
757
- * Don't treat unsigned integers with zerofill as signed.
746
+ *Rafael Mendonça França*
758
747
 
759
- Fixes #27125.
748
+ * Remove deprecated method `supports_migrations?`.
760
749
 
761
- *Ryuta Kamizono*
750
+ *Rafael Mendonça França*
762
751
 
763
- * Fix the uniqueness validation scope with a polymorphic association.
752
+ * Remove deprecated methods `initialize_schema_migrations_table` and `initialize_internal_metadata_table`.
764
753
 
765
- *Sergey Alekseev*
754
+ *Rafael Mendonça França*
766
755
 
767
- * Raise `ActiveRecord::RecordNotFound` from collection `*_ids` setters
768
- for unknown IDs with a better error message.
756
+ * Raises when calling `lock!` in a dirty record.
769
757
 
770
- Changes the collection `*_ids` setters to cast provided IDs the data
771
- type of the primary key set in the association, not the model
772
- primary key.
758
+ *Rafael Mendonça França*
773
759
 
774
- *Dominic Cleal*
760
+ * Remove deprecated support to passing a class to `:class_name` on associations.
775
761
 
776
- * For PostgreSQL >= 9.4 use `pgcrypto`'s `gen_random_uuid()` instead of
777
- `uuid-ossp`'s UUID generation function.
762
+ *Rafael Mendonça França*
778
763
 
779
- *Yuji Yaginuma*, *Yaw Boakye*
764
+ * Remove deprecated argument `default` from `index_name_exists?`.
780
765
 
781
- * Introduce `Model#reload_<association>` to bring back the behavior
782
- of `Article.category(true)` where `category` is a singular
783
- association.
766
+ *Rafael Mendonça França*
784
767
 
785
- The force reloading of the association reader was deprecated
786
- in #20888. Unfortunately the suggested alternative of
787
- `article.reload.category` does not expose the same behavior.
768
+ * Remove deprecated support to `quoted_id` when typecasting an Active Record object.
788
769
 
789
- This patch adds a reader method with the prefix `reload_` for
790
- singular associations. This method has the same semantics as
791
- passing true to the association reader used to have.
770
+ *Rafael Mendonça França*
792
771
 
793
- *Yves Senn*
772
+ * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
773
+ ar_internal_metadata's data for a test database.
794
774
 
795
- * Make sure eager loading `ActiveRecord::Associations` also loads
796
- constants defined in `ActiveRecord::Associations::Preloader`.
775
+ Before:
776
+ ```
777
+ $ RAILS_ENV=test rails dbconsole
778
+ > SELECT * FROM ar_internal_metadata;
779
+ key|value|created_at|updated_at
780
+ environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
781
+ ```
797
782
 
798
- *Yves Senn*
783
+ After:
784
+ ```
785
+ $ RAILS_ENV=test rails dbconsole
786
+ > SELECT * FROM ar_internal_metadata;
787
+ key|value|created_at|updated_at
788
+ environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
789
+ ```
799
790
 
800
- * Allow `ActionController::Parameters`-like objects to be passed as
801
- values for Postgres HStore columns.
791
+ Fixes #26731.
802
792
 
803
- Fixes #26904.
793
+ *bogdanvlviv*
804
794
 
805
- *Jon Moss*
795
+ * Fix longer sequence name detection for serial columns.
806
796
 
807
- * Added `stat` method to `ActiveRecord::ConnectionAdapters::ConnectionPool`.
797
+ Fixes #28332.
808
798
 
809
- Example:
799
+ *Ryuta Kamizono*
800
+
801
+ * MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`.
810
802
 
811
- ActiveRecord::Base.connection_pool.stat # =>
812
- { size: 15, connections: 1, busy: 1, dead: 0, idle: 0, waiting: 0, checkout_timeout: 5 }
803
+ Fixes #30894.
813
804
 
814
- *Pavel Evstigneev*
805
+ *Ryuta Kamizono*
815
806
 
816
- * Avoid `unscope(:order)` when `limit_value` is presented for `count`
817
- and `exists?`.
807
+ * Fix `COUNT(DISTINCT ...)` for `GROUP BY` with `ORDER BY` and `LIMIT`.
818
808
 
819
- If `limit_value` is presented, records fetching order is very important
820
- for performance. We should not unscope the order in the case.
809
+ Fixes #30886.
821
810
 
822
811
  *Ryuta Kamizono*
823
812
 
824
- * Fix an Active Record `DateTime` field `NoMethodError` caused by incomplete
825
- datetime.
813
+ * PostgreSQL `tsrange` now preserves subsecond precision.
826
814
 
827
- Fixes #24195.
815
+ PostgreSQL 9.1+ introduced range types, and Rails added support for using
816
+ this datatype in Active Record. However, the serialization of
817
+ `PostgreSQL::OID::Range` was incomplete, because it did not properly
818
+ cast the bounds that make up the range. This led to subseconds being
819
+ dropped in SQL commands:
828
820
 
829
- *Sen Zhang*
821
+ Before:
822
+
823
+ connection.type_cast(tsrange.serialize(range_value))
824
+ # => "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
830
825
 
831
- * Allow `slice` to take an array of methods(without the need for splatting).
826
+ Now:
832
827
 
833
- *Cohen Carlisle*
828
+ connection.type_cast(tsrange.serialize(range_value))
829
+ # => "[2010-01-01 13:30:00.670277,2011-02-02 19:30:00.745125)"
834
830
 
835
- * Improved partial writes with HABTM and has many through associations
836
- to fire database query only if relation has been changed.
831
+ *Thomas Cannon*
837
832
 
838
- Fixes #19663.
833
+ * Passing a `Set` to `Relation#where` now behaves the same as passing an
834
+ array.
835
+
836
+ *Sean Griffin*
837
+
838
+ * Use given algorithm while removing index from database.
839
+
840
+ Fixes #24190.
839
841
 
840
842
  *Mehmet Emin İNAÇ*
841
843
 
842
- * Deprecate passing arguments and block at the same time to
843
- `ActiveRecord::QueryMethods#select`.
844
+ * Update payload names for `sql.active_record` instrumentation to be
845
+ more descriptive.
844
846
 
845
- *Prathamesh Sonpatki*
847
+ Fixes #30586.
846
848
 
847
- * Fixed: Optimistic locking does not work well with `null` in the database.
849
+ *Jeremy Green*
848
850
 
849
- Fixes #26024.
851
+ * Add new error class `LockWaitTimeout` which will be raised
852
+ when lock wait timeout exceeded.
850
853
 
851
- *bogdanvlviv*
854
+ *Gabriel Courtemanche*
852
855
 
853
- * Fixed support for case insensitive comparisons of `text` columns in
854
- PostgreSQL.
856
+ * Remove deprecated `#migration_keys`.
855
857
 
856
- *Edho Arief*
858
+ *Ryuta Kamizono*
857
859
 
858
- * Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`.
860
+ * Automatically guess the inverse associations for STI.
859
861
 
860
- *Trung Duc Tran*
862
+ *Yuichiro Kaneko*
861
863
 
862
- * Return `true` from `update_attribute` when the value of the attribute
863
- to be updated is unchanged.
864
+ * Ensure `sum` honors `distinct` on `has_many :through` associations.
864
865
 
865
- Fixes #26593.
866
+ Fixes #16791.
866
867
 
867
- *Prathamesh Sonpatki*
868
+ *Aaron Wortham*
868
869
 
869
- * Always store errors details information with symbols.
870
+ * Add `binary` fixture helper method.
870
871
 
871
- When the association is autosaved we were storing the details with
872
- string keys. This was creating inconsistency with other details that are
873
- added using the `Errors#add` method. It was also inconsistent with the
874
- `Errors#messages` storage.
872
+ *Atsushi Yoshida*
875
873
 
876
- To fix this inconsistency we are always storing with symbols. This will
877
- cause a small breaking change because in those cases the details could
878
- be accessed as strings keys but now it can not.
874
+ * When using `Relation#or`, extract the common conditions and put them before the OR condition.
879
875
 
880
- Fix #26499.
876
+ *Maxime Handfield Lapointe*
881
877
 
882
- *Rafael Mendonça França*, *Marcus Vieira*
878
+ * `Relation#or` now accepts two relations who have different values for
879
+ `references` only, as `references` can be implicitly called by `where`.
883
880
 
884
- * Calling `touch` on a model using optimistic locking will now leave the model
885
- in a non-dirty state with no attribute changes.
881
+ Fixes #29411.
886
882
 
887
- Fixes #26496.
883
+ *Sean Griffin*
888
884
 
889
- *Jakob Skjerning*
885
+ * `ApplicationRecord` is no longer generated when generating models. If you
886
+ need to generate it, it can be created with `rails g application_record`.
890
887
 
891
- * Using a mysql2 connection after it fails to reconnect will now have an error message
892
- saying the connection is closed rather than an undefined method error message.
888
+ *Lisa Ugray*
893
889
 
894
- *Dylan Thacker-Smith*
890
+ * Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT` to keep the existing select list.
895
891
 
896
- * PostgreSQL array columns will now respect the encoding of strings contained
897
- in the array.
892
+ *Ryuta Kamizono*
898
893
 
899
- Fixes #26326.
894
+ * When a `has_one` association is destroyed by `dependent: destroy`,
895
+ `destroyed_by_association` will now be set to the reflection, matching the
896
+ behaviour of `has_many` associations.
900
897
 
901
- *Sean Griffin*
898
+ *Lisa Ugray*
899
+
900
+ * Fix `unscoped(where: [columns])` removing the wrong bind values.
901
+
902
+ When the `where` is called on a relation after a `or`, unscoping the column of that later `where` removed
903
+ bind values used by the `or` instead. (possibly other cases too)
904
+
905
+ ```
906
+ Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).to_sql
907
+ # Currently:
908
+ # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 2 OR "posts"."id" = 3)
909
+ # With fix:
910
+ # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1 OR "posts"."id" = 2)
911
+ ```
902
912
 
903
- * Inverse association instances will now be set before `after_find` or
904
- `after_initialize` callbacks are run.
913
+ *Maxime Handfield Lapointe*
905
914
 
906
- Fixes #26320.
915
+ * Values constructed using multi-parameter assignment will now use the
916
+ post-type-cast value for rendering in single-field form inputs.
907
917
 
908
918
  *Sean Griffin*
909
919
 
910
- * Remove unnecessarily association load when a `belongs_to` association has already been
911
- loaded then the foreign key is changed directly and the record saved.
920
+ * `Relation#joins` is no longer affected by the target model's
921
+ `current_scope`, with the exception of `unscoped`.
912
922
 
913
- *James Coleman*
923
+ Fixes #29338.
914
924
 
915
- * Remove standardized column types/arguments spaces in schema dump.
925
+ *Sean Griffin*
916
926
 
917
- *Tim Petricola*
927
+ * Change sqlite3 boolean serialization to use 1 and 0.
918
928
 
919
- * Avoid loading records from database when they are already loaded using
920
- the `pluck` method on a collection.
929
+ SQLite natively recognizes 1 and 0 as true and false, but does not natively
930
+ recognize 't' and 'f' as was previously serialized.
921
931
 
922
- Fixes #25921.
932
+ This change in serialization requires a migration of stored boolean data
933
+ for SQLite databases, so it's implemented behind a configuration flag
934
+ whose default false value is deprecated.
923
935
 
924
- *Ryuta Kamizono*
936
+ *Lisa Ugray*
925
937
 
926
- * Remove text default treated as an empty string in non-strict mode for
927
- consistency with other types.
928
-
929
- Strict mode controls how MySQL handles invalid or missing values in
930
- data-change statements such as INSERT or UPDATE. If strict mode is not
931
- in effect, MySQL inserts adjusted values for invalid or missing values
932
- and produces warnings.
933
-
934
- def test_mysql_not_null_defaults_non_strict
935
- using_strict(false) do
936
- with_mysql_not_null_table do |klass|
937
- record = klass.new
938
- assert_nil record.non_null_integer
939
- assert_nil record.non_null_string
940
- assert_nil record.non_null_text
941
- assert_nil record.non_null_blob
942
-
943
- record.save!
944
- record.reload
945
-
946
- assert_equal 0, record.non_null_integer
947
- assert_equal "", record.non_null_string
948
- assert_equal "", record.non_null_text
949
- assert_equal "", record.non_null_blob
950
- end
951
- end
952
- end
938
+ * Skip query caching when working with batches of records (`find_each`, `find_in_batches`,
939
+ `in_batches`).
953
940
 
954
- https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict
941
+ Previously, records would be fetched in batches, but all records would be retained in memory
942
+ until the end of the request or job.
955
943
 
956
- *Ryuta Kamizono*
944
+ *Eugene Kenny*
957
945
 
958
- * SQLite3 migrations to add a column to an existing table can now be
959
- successfully rolled back when the column was given and invalid column
960
- type.
946
+ * Prevent errors raised by `sql.active_record` notification subscribers from being converted into
947
+ `ActiveRecord::StatementInvalid` exceptions.
961
948
 
962
- Fixes #26087.
949
+ *Dennis Taylor*
963
950
 
964
- *Travis O'Neill*
951
+ * Fix eager loading/preloading association with scope including joins.
965
952
 
966
- * Deprecate `sanitize_conditions`. Use `sanitize_sql` instead.
953
+ Fixes #28324.
967
954
 
968
955
  *Ryuta Kamizono*
969
956
 
970
- * Doing count on relations that contain LEFT OUTER JOIN Arel node no longer
971
- force a DISTINCT. This solves issues when using count after a left_joins.
957
+ * Fix transactions to apply state to child transactions.
972
958
 
973
- *Maxime Handfield Lapointe*
974
-
975
- * RecordNotFound raised by association.find exposes `id`, `primary_key` and
976
- `model` methods to be consistent with RecordNotFound raised by Record.find.
959
+ Previously, if you had a nested transaction and the outer transaction was rolledback, the record from the
960
+ inner transaction would still be marked as persisted.
977
961
 
978
- *Michel Pigassou*
962
+ This change fixes that by applying the state of the parent transaction to the child transaction when the
963
+ parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
979
964
 
980
- * Hashes can once again be passed to setters of `composed_of`, if all of the
981
- mapping methods are methods implemented on `Hash`.
965
+ *Eileen M. Uchitelle*, *Aaron Patterson*
982
966
 
983
- Fixes #25978.
967
+ * Deprecate `set_state` method in `TransactionState`.
984
968
 
985
- *Sean Griffin*
969
+ Deprecated the `set_state` method in favor of setting the state via specific methods. If you need to mark the
970
+ state of the transaction you can now use `rollback!`, `commit!` or `nullify!` instead of
971
+ `set_state(:rolledback)`, `set_state(:committed)`, or `set_state(nil)`.
986
972
 
987
- * Fix the SELECT statement in `#table_comment` for MySQL.
973
+ *Eileen M. Uchitelle*, *Aaron Patterson*
988
974
 
989
- *Takeshi Akima*
975
+ * Deprecate delegating to `arel` in `Relation`.
990
976
 
991
- * Virtual attributes will no longer raise when read on models loaded from the
992
- database.
977
+ *Ryuta Kamizono*
993
978
 
994
- *Sean Griffin*
979
+ * Query cache was unavailable when entering the `ActiveRecord::Base.cache` block
980
+ without being connected.
995
981
 
996
- * Support calling the method `merge` in `scope`'s lambda.
982
+ *Tsukasa Oishi*
997
983
 
998
- *Yasuhiro Sugino*
984
+ * Previously, when building records using a `has_many :through` association,
985
+ if the child records were deleted before the parent was saved, they would
986
+ still be persisted. Now, if child records are deleted before the parent is saved
987
+ on a `has_many :through` association, the child records will not be persisted.
999
988
 
1000
- * Fixes multi-parameter attributes conversion with invalid params.
989
+ *Tobias Kraze*
1001
990
 
1002
- *Hiroyuki Ishii*
991
+ * Merging two relations representing nested joins no longer transforms the joins of
992
+ the merged relation into LEFT OUTER JOIN.
1003
993
 
1004
- * Add newline between each migration in `structure.sql`.
994
+ Example:
1005
995
 
1006
- Keeps schema migration inserts as a single commit, but allows for easier
1007
- git diffing.
996
+ ```
997
+ Author.joins(:posts).merge(Post.joins(:comments))
998
+ # Before the change:
999
+ #=> SELECT ... FROM authors INNER JOIN posts ON ... LEFT OUTER JOIN comments ON...
1008
1000
 
1009
- Fixes #25504.
1001
+ # After the change:
1002
+ #=> SELECT ... FROM authors INNER JOIN posts ON ... INNER JOIN comments ON...
1003
+ ```
1010
1004
 
1011
- *Grey Baker*, *Norberto Lopes*
1005
+ *Maxime Handfield Lapointe*
1012
1006
 
1013
- * The flag `error_on_ignored_order_or_limit` has been deprecated in favor of
1014
- the current `error_on_ignored_order`.
1007
+ * `ActiveRecord::Persistence#touch` does not work well when optimistic locking enabled and
1008
+ `locking_column`, without default value, is null in the database.
1015
1009
 
1016
- *Xavier Noria*
1010
+ *bogdanvlviv*
1017
1011
 
1018
- * Batch processing methods support `limit`:
1012
+ * Fix destroying existing object does not work well when optimistic locking enabled and
1013
+ `locking_column` is null in the database.
1019
1014
 
1020
- Post.limit(10_000).find_each do |post|
1021
- # ...
1022
- end
1015
+ *bogdanvlviv*
1023
1016
 
1024
- It also works in `find_in_batches` and `in_batches`.
1017
+ * Use bulk INSERT to insert fixtures for better performance.
1025
1018
 
1026
- *Xavier Noria*
1019
+ *Kir Shatrov*
1027
1020
 
1028
- * Using `group` with an attribute that has a custom type will properly cast
1029
- the hash keys after calling a calculation method like `count`.
1021
+ * Prevent creation of bind param if casted value is nil.
1030
1022
 
1031
- Fixes #25595.
1023
+ *Ryuta Kamizono*
1032
1024
 
1033
- *Sean Griffin*
1025
+ * Deprecate passing arguments and block at the same time to `count` and `sum` in `ActiveRecord::Calculations`.
1034
1026
 
1035
- * Fix the generated `#to_param` method to use `omission: ''` so that
1036
- the resulting output is actually up to 20 characters, not
1037
- effectively 17 to leave room for the default "...".
1038
- Also call `#parameterize` before `#truncate` and make the
1039
- `separator: /-/` to maximize the information included in the
1040
- output.
1027
+ *Ryuta Kamizono*
1041
1028
 
1042
- Fixes #23635.
1029
+ * Loading model schema from database is now thread-safe.
1043
1030
 
1044
- *Rob Biedenharn*
1031
+ Fixes #28589.
1045
1032
 
1046
- * Ensure concurrent invocations of the connection reaper cannot allocate the
1047
- same connection to two threads.
1033
+ *Vikrant Chaudhary*, *David Abdemoulaie*
1048
1034
 
1049
- Fixes #25585.
1035
+ * Add `ActiveRecord::Base#cache_version` to support recyclable cache keys via the new versioned entries
1036
+ in `ActiveSupport::Cache`. This also means that `ActiveRecord::Base#cache_key` will now return a stable key
1037
+ that does not include a timestamp any more.
1050
1038
 
1051
- *Matthew Draper*
1039
+ NOTE: This feature is turned off by default, and `#cache_key` will still return cache keys with timestamps
1040
+ until you set `ActiveRecord::Base.cache_versioning = true`. That's the setting for all new apps on Rails 5.2+
1052
1041
 
1053
- * Inspecting an object with an associated array of over 10 elements no longer
1054
- truncates the array, preventing `inspect` from looping infinitely in some
1055
- cases.
1042
+ *DHH*
1056
1043
 
1057
- *Kevin McPhillips*
1044
+ * Respect `SchemaDumper.ignore_tables` in rake tasks for databases structure dump.
1058
1045
 
1059
- * Removed the unused methods `ActiveRecord::Base.connection_id` and
1060
- `ActiveRecord::Base.connection_id=`.
1046
+ *Rusty Geldmacher*, *Guillermo Iguaran*
1061
1047
 
1062
- *Sean Griffin*
1048
+ * Add type caster to `RuntimeReflection#alias_name`.
1063
1049
 
1064
- * Ensure hashes can be assigned to attributes created using `composed_of`.
1050
+ Fixes #28959.
1065
1051
 
1066
- Fixes #25210.
1052
+ *Jon Moss*
1067
1053
 
1068
- *Sean Griffin*
1054
+ * Deprecate `supports_statement_cache?`.
1069
1055
 
1070
- * Fix logging edge case where if an attribute was of the binary type and
1071
- was provided as a Hash.
1056
+ *Ryuta Kamizono*
1072
1057
 
1073
- *Jon Moss*
1058
+ * Raise error `UnknownMigrationVersionError` on the movement of migrations
1059
+ when the current migration does not exist.
1074
1060
 
1075
- * Handle JSON deserialization correctly if the column default from database
1076
- adapter returns `''` instead of `nil`.
1061
+ *bogdanvlviv*
1077
1062
 
1078
- *Johannes Opper*
1063
+ * Fix `bin/rails db:forward` first migration.
1079
1064
 
1080
- * Introduce new Active Record transaction error classes for catching
1081
- transaction serialization failures or deadlocks.
1065
+ *bogdanvlviv*
1082
1066
 
1083
- *Erol Fornoles*
1067
+ * Support Descending Indexes for MySQL.
1084
1068
 
1085
- * PostgreSQL: Fix `db:structure:load` silent failure on SQL error.
1069
+ MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored.
1070
+ See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
1086
1071
 
1087
- The command line flag `-v ON_ERROR_STOP=1` should be used
1088
- when invoking `psql` to make sure errors are not suppressed.
1072
+ *Ryuta Kamizono*
1089
1073
 
1090
- Example:
1074
+ * Fix inconsistency with changed attributes when overriding Active Record attribute reader.
1091
1075
 
1092
- psql -v ON_ERROR_STOP=1 -q -f awesome-file.sql my-app-db
1076
+ *bogdanvlviv*
1093
1077
 
1094
- Fixes #23818.
1078
+ * When calling the dynamic fixture accessor method with no arguments, it now returns all fixtures of this type.
1079
+ Previously this method always returned an empty array.
1095
1080
 
1096
- *Ralin Chimev*
1081
+ *Kevin McPhillips*
1097
1082
 
1098
1083
 
1099
- Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activerecord/CHANGELOG.md) for previous changes.
1084
+ Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activerecord/CHANGELOG.md) for previous changes.