activerecord 5.1.7 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

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