activerecord 4.2.11 → 5.2.4.1

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 (274) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +580 -1626
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +10 -11
  5. data/examples/performance.rb +32 -31
  6. data/examples/simple.rb +5 -4
  7. data/lib/active_record/aggregations.rb +263 -249
  8. data/lib/active_record/association_relation.rb +11 -6
  9. data/lib/active_record/associations/alias_tracker.rb +29 -35
  10. data/lib/active_record/associations/association.rb +77 -43
  11. data/lib/active_record/associations/association_scope.rb +106 -133
  12. data/lib/active_record/associations/belongs_to_association.rb +52 -41
  13. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -8
  14. data/lib/active_record/associations/builder/association.rb +29 -38
  15. data/lib/active_record/associations/builder/belongs_to.rb +77 -30
  16. data/lib/active_record/associations/builder/collection_association.rb +9 -22
  17. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +42 -35
  18. data/lib/active_record/associations/builder/has_many.rb +6 -4
  19. data/lib/active_record/associations/builder/has_one.rb +13 -6
  20. data/lib/active_record/associations/builder/singular_association.rb +15 -11
  21. data/lib/active_record/associations/collection_association.rb +139 -280
  22. data/lib/active_record/associations/collection_proxy.rb +231 -133
  23. data/lib/active_record/associations/foreign_association.rb +3 -1
  24. data/lib/active_record/associations/has_many_association.rb +34 -89
  25. data/lib/active_record/associations/has_many_through_association.rb +49 -76
  26. data/lib/active_record/associations/has_one_association.rb +38 -24
  27. data/lib/active_record/associations/has_one_through_association.rb +18 -9
  28. data/lib/active_record/associations/join_dependency/join_association.rb +40 -87
  29. data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
  30. data/lib/active_record/associations/join_dependency/join_part.rb +12 -12
  31. data/lib/active_record/associations/join_dependency.rb +133 -159
  32. data/lib/active_record/associations/preloader/association.rb +85 -120
  33. data/lib/active_record/associations/preloader/through_association.rb +85 -74
  34. data/lib/active_record/associations/preloader.rb +81 -91
  35. data/lib/active_record/associations/singular_association.rb +27 -34
  36. data/lib/active_record/associations/through_association.rb +38 -18
  37. data/lib/active_record/associations.rb +1732 -1597
  38. data/lib/active_record/attribute_assignment.rb +58 -182
  39. data/lib/active_record/attribute_decorators.rb +39 -15
  40. data/lib/active_record/attribute_methods/before_type_cast.rb +10 -8
  41. data/lib/active_record/attribute_methods/dirty.rb +94 -135
  42. data/lib/active_record/attribute_methods/primary_key.rb +86 -71
  43. data/lib/active_record/attribute_methods/query.rb +4 -2
  44. data/lib/active_record/attribute_methods/read.rb +45 -63
  45. data/lib/active_record/attribute_methods/serialization.rb +40 -20
  46. data/lib/active_record/attribute_methods/time_zone_conversion.rb +58 -36
  47. data/lib/active_record/attribute_methods/write.rb +30 -45
  48. data/lib/active_record/attribute_methods.rb +166 -109
  49. data/lib/active_record/attributes.rb +201 -82
  50. data/lib/active_record/autosave_association.rb +94 -36
  51. data/lib/active_record/base.rb +57 -44
  52. data/lib/active_record/callbacks.rb +97 -57
  53. data/lib/active_record/coders/json.rb +3 -1
  54. data/lib/active_record/coders/yaml_column.rb +24 -12
  55. data/lib/active_record/collection_cache_key.rb +53 -0
  56. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +712 -290
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +10 -5
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +237 -90
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +71 -21
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +118 -52
  61. data/lib/active_record/connection_adapters/abstract/savepoints.rb +5 -3
  62. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +67 -46
  63. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +318 -217
  64. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +81 -36
  65. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +570 -228
  66. data/lib/active_record/connection_adapters/abstract/transaction.rb +138 -70
  67. data/lib/active_record/connection_adapters/abstract_adapter.rb +325 -202
  68. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +542 -601
  69. data/lib/active_record/connection_adapters/column.rb +50 -41
  70. data/lib/active_record/connection_adapters/connection_specification.rb +147 -135
  71. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +33 -0
  72. data/lib/active_record/connection_adapters/mysql/column.rb +27 -0
  73. data/lib/active_record/connection_adapters/mysql/database_statements.rb +140 -0
  74. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +72 -0
  75. data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -0
  76. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +73 -0
  77. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +87 -0
  78. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +80 -0
  79. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +148 -0
  80. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +35 -0
  81. data/lib/active_record/connection_adapters/mysql2_adapter.rb +41 -180
  82. data/lib/active_record/connection_adapters/postgresql/column.rb +35 -11
  83. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +45 -114
  84. data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
  85. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +50 -58
  86. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +10 -6
  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 +4 -2
  89. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +5 -1
  90. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +13 -1
  91. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +9 -22
  92. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
  93. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +5 -3
  94. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +31 -19
  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 -11
  97. data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +45 -0
  98. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +5 -7
  99. data/lib/active_record/connection_adapters/postgresql/oid/{integer.rb → oid.rb} +6 -2
  100. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +33 -11
  101. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +52 -34
  102. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -5
  103. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +55 -53
  104. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +5 -3
  105. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +3 -1
  106. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +3 -1
  107. data/lib/active_record/connection_adapters/postgresql/oid.rb +23 -25
  108. data/lib/active_record/connection_adapters/postgresql/quoting.rb +107 -47
  109. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +27 -14
  110. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +65 -0
  111. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +144 -90
  112. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +50 -0
  113. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +462 -284
  114. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +39 -0
  115. data/lib/active_record/connection_adapters/postgresql/utils.rb +12 -8
  116. data/lib/active_record/connection_adapters/postgresql_adapter.rb +432 -323
  117. data/lib/active_record/connection_adapters/schema_cache.rb +48 -24
  118. data/lib/active_record/connection_adapters/sql_type_metadata.rb +34 -0
  119. data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
  120. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +67 -0
  121. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +17 -0
  122. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
  123. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
  124. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +106 -0
  125. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +269 -308
  126. data/lib/active_record/connection_adapters/statement_pool.rb +34 -13
  127. data/lib/active_record/connection_handling.rb +40 -27
  128. data/lib/active_record/core.rb +178 -198
  129. data/lib/active_record/counter_cache.rb +79 -36
  130. data/lib/active_record/define_callbacks.rb +22 -0
  131. data/lib/active_record/dynamic_matchers.rb +87 -105
  132. data/lib/active_record/enum.rb +135 -88
  133. data/lib/active_record/errors.rb +179 -52
  134. data/lib/active_record/explain.rb +23 -11
  135. data/lib/active_record/explain_registry.rb +4 -2
  136. data/lib/active_record/explain_subscriber.rb +10 -5
  137. data/lib/active_record/fixture_set/file.rb +35 -9
  138. data/lib/active_record/fixtures.rb +188 -132
  139. data/lib/active_record/gem_version.rb +5 -3
  140. data/lib/active_record/inheritance.rb +148 -112
  141. data/lib/active_record/integration.rb +70 -28
  142. data/lib/active_record/internal_metadata.rb +45 -0
  143. data/lib/active_record/legacy_yaml_adapter.rb +21 -3
  144. data/lib/active_record/locale/en.yml +3 -2
  145. data/lib/active_record/locking/optimistic.rb +88 -96
  146. data/lib/active_record/locking/pessimistic.rb +15 -3
  147. data/lib/active_record/log_subscriber.rb +95 -33
  148. data/lib/active_record/migration/command_recorder.rb +133 -90
  149. data/lib/active_record/migration/compatibility.rb +217 -0
  150. data/lib/active_record/migration/join_table.rb +8 -6
  151. data/lib/active_record/migration.rb +581 -282
  152. data/lib/active_record/model_schema.rb +290 -111
  153. data/lib/active_record/nested_attributes.rb +264 -222
  154. data/lib/active_record/no_touching.rb +7 -1
  155. data/lib/active_record/null_relation.rb +24 -37
  156. data/lib/active_record/persistence.rb +347 -119
  157. data/lib/active_record/query_cache.rb +13 -24
  158. data/lib/active_record/querying.rb +19 -17
  159. data/lib/active_record/railtie.rb +94 -32
  160. data/lib/active_record/railties/console_sandbox.rb +2 -0
  161. data/lib/active_record/railties/controller_runtime.rb +9 -3
  162. data/lib/active_record/railties/databases.rake +149 -156
  163. data/lib/active_record/readonly_attributes.rb +5 -4
  164. data/lib/active_record/reflection.rb +414 -267
  165. data/lib/active_record/relation/batches/batch_enumerator.rb +69 -0
  166. data/lib/active_record/relation/batches.rb +204 -55
  167. data/lib/active_record/relation/calculations.rb +256 -248
  168. data/lib/active_record/relation/delegation.rb +67 -60
  169. data/lib/active_record/relation/finder_methods.rb +288 -239
  170. data/lib/active_record/relation/from_clause.rb +26 -0
  171. data/lib/active_record/relation/merger.rb +86 -86
  172. data/lib/active_record/relation/predicate_builder/array_handler.rb +24 -24
  173. data/lib/active_record/relation/predicate_builder/association_query_value.rb +46 -0
  174. data/lib/active_record/relation/predicate_builder/base_handler.rb +19 -0
  175. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +20 -0
  176. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +56 -0
  177. data/lib/active_record/relation/predicate_builder/range_handler.rb +42 -0
  178. data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
  179. data/lib/active_record/relation/predicate_builder.rb +116 -119
  180. data/lib/active_record/relation/query_attribute.rb +45 -0
  181. data/lib/active_record/relation/query_methods.rb +448 -393
  182. data/lib/active_record/relation/record_fetch_warning.rb +51 -0
  183. data/lib/active_record/relation/spawn_methods.rb +11 -13
  184. data/lib/active_record/relation/where_clause.rb +186 -0
  185. data/lib/active_record/relation/where_clause_factory.rb +34 -0
  186. data/lib/active_record/relation.rb +287 -340
  187. data/lib/active_record/result.rb +54 -36
  188. data/lib/active_record/runtime_registry.rb +6 -4
  189. data/lib/active_record/sanitization.rb +155 -124
  190. data/lib/active_record/schema.rb +30 -24
  191. data/lib/active_record/schema_dumper.rb +91 -87
  192. data/lib/active_record/schema_migration.rb +19 -16
  193. data/lib/active_record/scoping/default.rb +102 -85
  194. data/lib/active_record/scoping/named.rb +81 -32
  195. data/lib/active_record/scoping.rb +45 -26
  196. data/lib/active_record/secure_token.rb +40 -0
  197. data/lib/active_record/serialization.rb +5 -5
  198. data/lib/active_record/statement_cache.rb +45 -35
  199. data/lib/active_record/store.rb +42 -36
  200. data/lib/active_record/suppressor.rb +61 -0
  201. data/lib/active_record/table_metadata.rb +82 -0
  202. data/lib/active_record/tasks/database_tasks.rb +134 -96
  203. data/lib/active_record/tasks/mysql_database_tasks.rb +56 -100
  204. data/lib/active_record/tasks/postgresql_database_tasks.rb +83 -41
  205. data/lib/active_record/tasks/sqlite_database_tasks.rb +44 -16
  206. data/lib/active_record/timestamp.rb +70 -38
  207. data/lib/active_record/touch_later.rb +64 -0
  208. data/lib/active_record/transactions.rb +199 -124
  209. data/lib/active_record/translation.rb +2 -0
  210. data/lib/active_record/type/adapter_specific_registry.rb +136 -0
  211. data/lib/active_record/type/date.rb +4 -45
  212. data/lib/active_record/type/date_time.rb +4 -49
  213. data/lib/active_record/type/decimal_without_scale.rb +6 -2
  214. data/lib/active_record/type/hash_lookup_type_map.rb +5 -3
  215. data/lib/active_record/type/internal/timezone.rb +17 -0
  216. data/lib/active_record/type/json.rb +30 -0
  217. data/lib/active_record/type/serialized.rb +24 -15
  218. data/lib/active_record/type/text.rb +2 -2
  219. data/lib/active_record/type/time.rb +11 -16
  220. data/lib/active_record/type/type_map.rb +15 -17
  221. data/lib/active_record/type/unsigned_integer.rb +9 -7
  222. data/lib/active_record/type.rb +79 -23
  223. data/lib/active_record/type_caster/connection.rb +33 -0
  224. data/lib/active_record/type_caster/map.rb +23 -0
  225. data/lib/active_record/type_caster.rb +9 -0
  226. data/lib/active_record/validations/absence.rb +25 -0
  227. data/lib/active_record/validations/associated.rb +13 -4
  228. data/lib/active_record/validations/length.rb +26 -0
  229. data/lib/active_record/validations/presence.rb +14 -13
  230. data/lib/active_record/validations/uniqueness.rb +40 -41
  231. data/lib/active_record/validations.rb +38 -35
  232. data/lib/active_record/version.rb +3 -1
  233. data/lib/active_record.rb +34 -22
  234. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +27 -0
  235. data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +5 -0
  236. data/lib/rails/generators/active_record/migration/migration_generator.rb +43 -35
  237. data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +8 -3
  238. data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +8 -1
  239. data/lib/rails/generators/active_record/migration.rb +18 -1
  240. data/lib/rails/generators/active_record/model/model_generator.rb +18 -22
  241. data/lib/rails/generators/active_record/model/templates/{model.rb → model.rb.tt} +3 -0
  242. data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
  243. data/lib/rails/generators/active_record.rb +7 -5
  244. metadata +72 -50
  245. data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
  246. data/lib/active_record/associations/preloader/collection_association.rb +0 -24
  247. data/lib/active_record/associations/preloader/has_many.rb +0 -17
  248. data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
  249. data/lib/active_record/associations/preloader/has_one.rb +0 -23
  250. data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
  251. data/lib/active_record/associations/preloader/singular_association.rb +0 -21
  252. data/lib/active_record/attribute.rb +0 -163
  253. data/lib/active_record/attribute_set/builder.rb +0 -106
  254. data/lib/active_record/attribute_set.rb +0 -81
  255. data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -498
  256. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +0 -93
  257. data/lib/active_record/connection_adapters/postgresql/oid/float.rb +0 -21
  258. data/lib/active_record/connection_adapters/postgresql/oid/infinity.rb +0 -13
  259. data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -35
  260. data/lib/active_record/connection_adapters/postgresql/oid/time.rb +0 -11
  261. data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
  262. data/lib/active_record/serializers/xml_serializer.rb +0 -193
  263. data/lib/active_record/type/big_integer.rb +0 -13
  264. data/lib/active_record/type/binary.rb +0 -50
  265. data/lib/active_record/type/boolean.rb +0 -31
  266. data/lib/active_record/type/decimal.rb +0 -64
  267. data/lib/active_record/type/decorator.rb +0 -14
  268. data/lib/active_record/type/float.rb +0 -19
  269. data/lib/active_record/type/integer.rb +0 -59
  270. data/lib/active_record/type/mutable.rb +0 -16
  271. data/lib/active_record/type/numeric.rb +0 -36
  272. data/lib/active_record/type/string.rb +0 -40
  273. data/lib/active_record/type/time_value.rb +0 -38
  274. data/lib/active_record/type/value.rb +0 -110
data/CHANGELOG.md CHANGED
@@ -1,2028 +1,982 @@
1
- ## Rails 4.2.11 (November 27, 2018) ##
1
+ ## Rails 5.2.4.1 (December 18, 2019) ##
2
2
 
3
3
  * No changes.
4
4
 
5
5
 
6
- ## Rails 4.2.10 (September 27, 2017) ##
6
+ ## Rails 5.2.4 (November 27, 2019) ##
7
7
 
8
- * `Relation#joins` is no longer affected by the target model's
9
- `current_scope`, with the exception of `unscoped`.
10
-
11
- Fixes #29338.
12
-
13
- *Sean Griffin*
14
-
15
- ## Rails 4.2.9 (June 26, 2017) ##
16
-
17
- * Fix regression caused by `collection_singular_ids=` ignoring different primary key on relationship.
8
+ * Fix circular `autosave: true` causes invalid records to be saved.
18
9
 
19
- *Nick Pezza*
10
+ Prior to the fix, when there was a circular series of `autosave: true`
11
+ associations, the callback for a `has_many` association was run while
12
+ another instance of the same callback on the same association hadn't
13
+ finished running. When control returned to the first instance of the
14
+ callback, the instance variable had changed, and subsequent associated
15
+ records weren't saved correctly. Specifically, the ID field for the
16
+ `belongs_to` corresponding to the `has_many` was `nil`.
20
17
 
21
- * Fix `rake db:schema:load` with subdirectories.
18
+ Fixes #28080.
22
19
 
23
- *Ryuta Kamizono*
24
-
25
- * Fix `rake db:migrate:status` with subdirectories.
26
-
27
- *Ryuta Kamizono*
20
+ *Larry Reid*
28
21
 
29
- * Fix regression of #1969 with SELECT aliases in HAVING clause.
22
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
30
23
 
31
- *Eugene Kenny*
32
-
33
- * Fix `wait_timeout` to configurable for mysql2 adapter.
34
-
35
- Fixes #26556.
24
+ Fixes #36022.
36
25
 
37
26
  *Ryuta Kamizono*
38
27
 
39
- * Make `table_name=` reset current statement cache,
40
- so queries are not run against the previous table name.
41
-
42
- *namusyaka*
43
-
44
-
45
- ## Rails 4.2.8 (February 21, 2017) ##
46
-
47
- * Using a mysql2 connection after it fails to reconnect will now have an error message
48
- saying the connection is closed rather than an undefined method error message.
49
-
50
- *Dylan Thacker-Smith*
51
-
52
- * Bust Model.attribute_names cache when resetting column information
53
-
54
- *James Coleman*
55
-
56
- * Fix query caching when type information is reset
57
-
58
- Backports ancillary fix in 5.0.
59
-
60
- *James Coleman*
61
-
62
- * Allow `joins` to be unscoped.
63
-
64
- Fixes #13775.
65
-
66
- *Takashi Kokubun*
67
-
68
- * Hashes can once again be passed to setters of `composed_of`, if all of the
69
- mapping methods are methods implemented on `Hash`.
70
-
71
- Fixes #25978.
72
-
73
- *Sean Griffin*
74
-
75
-
76
- ## Rails 4.2.7 (July 12, 2016) ##
77
-
78
- * Inspecting an object with an associated array of over 10 elements no longer
79
- truncates the array, preventing `inspect` from looping infinitely in some
80
- cases.
81
-
82
- *Kevin McPhillips*
83
-
84
- * Ensure hashes can be assigned to attributes created using `composed_of`.
85
- Fixes #25210.
28
+ * Fix sqlite3 collation parsing when using decimal columns.
86
29
 
87
- *Sean Griffin*
30
+ *Martin R. Schuster*
88
31
 
89
- * Queries such as `Computer.joins(:monitor).group(:status).count` will now be
90
- interpreted as `Computer.joins(:monitor).group('computers.status').count`
91
- so that when `Computer` and `Monitor` have both `status` columns we don't
92
- have conflicts in projection.
32
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
93
33
 
94
- *Rafael Sales*
34
+ Fixes #36465.
95
35
 
96
- * ActiveRecord::Relation#count: raise an ArgumentError when finder options
97
- are specified or an ActiveRecord::StatementInvalid when an invalid type
98
- is provided for a column name (e.g. a Hash).
36
+ *Jeff Doering*
99
37
 
100
- Fixes #20434
38
+ * Assign all attributes before calling `build` to ensure the child record is visible in
39
+ `before_add` and `after_add` callbacks for `has_many :through` associations.
101
40
 
102
- *Konstantinos Rousis*
41
+ Fixes #33249.
103
42
 
104
- * Correctly pass MySQL options when using structure_dump or structure_load
43
+ *Ryan H. Kerr*
105
44
 
106
- Specifically, it fixes an issue when using SSL authentication.
107
45
 
108
- *Alex Coomans*
46
+ ## Rails 5.2.3 (March 27, 2019) ##
109
47
 
48
+ * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
110
49
 
111
- ## Rails 4.2.6 (March 07, 2016) ##
50
+ Fixes #35214.
112
51
 
113
- * Fix a bug where using `t.foreign_key` twice with the same `to_table` within
114
- the same table definition would only create one foreign key.
52
+ *Juani Villarejo*
115
53
 
116
- *George Millo*
54
+ * Fix prepared statements caching to be enabled even when query caching is enabled.
117
55
 
118
- * Fix regression in dirty attribute tracking after #dup. Changes to the
119
- clone no longer show as changed attributes in the original object.
56
+ *Ryuta Kamizono*
120
57
 
121
- *Dominic Cleal*
58
+ * Don't allow `where` with invalid value matches to nil values.
122
59
 
123
- * Fix regression when loading fixture files with symbol keys.
60
+ Fixes #33624.
124
61
 
125
- Closes #22584.
62
+ *Ryuta Kamizono*
126
63
 
127
- *Yves Senn*
64
+ * Restore an ability that class level `update` without giving ids.
128
65
 
129
- * Fix `rake db:structure:dump` on Postgres when multiple schemas are used.
66
+ Fixes #34743.
130
67
 
131
- Fixes #22346.
68
+ *Ryuta Kamizono*
132
69
 
133
- *Nick Muerdter*, *ckoenig*
70
+ * Fix join table column quoting with SQLite.
134
71
 
135
- * Introduce `connection.data_sources` and `connection.data_source_exists?`.
136
- These methods determine what relations can be used to back Active Record
137
- models (usually tables and views).
72
+ *Gannon McGibbon*
138
73
 
139
- *Yves Senn*, *Matthew Draper*
74
+ * Ensure that `delete_all` on collection proxy returns affected count.
140
75
 
76
+ *Ryuta Kamizono*
141
77
 
142
- ## Rails 4.2.5.2 (February 26, 2016) ##
78
+ * Reset scope after delete on collection association to clear stale offsets of removed records.
143
79
 
144
- * No changes.
80
+ *Gannon McGibbon*
145
81
 
146
82
 
147
- ## Rails 4.2.5.1 (January 25, 2015) ##
83
+ ## Rails 5.2.2.1 (March 11, 2019) ##
148
84
 
149
85
  * No changes.
150
86
 
151
87
 
152
- ## Rails 4.2.5 (November 12, 2015) ##
153
-
154
- * No longer pass deprecated option `-i` to `pg_dump`.
155
-
156
- *Paul Sadauskas*
157
-
158
- * Set `scope.reordering_value` to `true` if :reordering values are specified.
159
-
160
- Fixes #21886.
88
+ ## Rails 5.2.2 (December 04, 2018) ##
161
89
 
162
- *Hiroaki Izu*
90
+ * Do not ignore the scoping with query methods in the scope block.
163
91
 
164
- * Avoid disabling errors on the PostgreSQL connection when enabling the
165
- standard_conforming_strings setting. Errors were previously disabled because
166
- the setting wasn't writable in Postgres 8.1 and didn't exist in earlier
167
- versions. Now Rails only supports Postgres 8.2+ we're fine to assume the
168
- setting exists. Disabling errors caused problems when using a connection
169
- pooling tool like PgBouncer because it's not guaranteed to have the same
170
- connection between calls to `execute` and it could leave the connection
171
- with errors disabled.
172
-
173
- Fixes #22101.
174
-
175
- *Harry Marr*
176
-
177
- * Includes HABTM returns correct size now. It's caused by the join dependency
178
- only instantiates one HABTM object because the join table hasn't a primary key.
179
-
180
- Fixes #16032.
181
-
182
- Examples:
183
-
184
- before:
185
-
186
- Project.first.salaried_developers.size # => 3
187
- Project.includes(:salaried_developers).first.salaried_developers.size # => 1
92
+ *Ryuta Kamizono*
188
93
 
189
- after:
94
+ * Allow aliased attributes to be used in `#update_columns` and `#update`.
190
95
 
191
- Project.first.salaried_developers.size # => 3
192
- Project.includes(:salaried_developers).first.salaried_developers.size # => 3
96
+ *Gannon McGibbon*
193
97
 
194
- *Bigxiang*
98
+ * Allow spaces in postgres table names.
195
99
 
196
- * Descriptive error message when fixtures contain a missing column.
100
+ Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres
101
+ adapter.
197
102
 
198
- Closes #21201.
103
+ *Gannon McGibbon*
199
104
 
200
- *Yves Senn*
105
+ * Cached columns_hash fields should be excluded from ResultSet#column_types
201
106
 
202
- * `bin/rake db:migrate` uses
203
- `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of
204
- `Migrator.migrations_paths`.
107
+ PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
108
+ was passing for SQLite and MySQL, but failed for PostgreSQL:
205
109
 
206
- *Tobias Bielohlawek*
110
+ ```ruby
111
+ class DeveloperName < ActiveRecord::Type::String
112
+ def deserialize(value)
113
+ "Developer: #{value}"
114
+ end
115
+ end
207
116
 
208
- * Fix `rewhere` in a `has_many` association.
117
+ class AttributedDeveloper < ActiveRecord::Base
118
+ self.table_name = "developers"
209
119
 
210
- Fixes #21955.
120
+ attribute :name, DeveloperName.new
211
121
 
212
- *Josh Branchaud*, *Kal*
122
+ self.ignored_columns += ["name"]
123
+ end
213
124
 
214
- * Added run_cmd class method to ActiveRecord::Tasks::DatabaseTasks for
215
- drying up Kernel.system() calls within this namespace and to avoid
216
- shell expansion by using a paramter list instead of string as arguments
217
- for Kernel.system(). Thanks to Nate Berkopec for supply patch to get
218
- test units passing.
125
+ developer = AttributedDeveloper.create
126
+ developer.update_column :name, "name"
219
127
 
220
- *Bryan Paxton*
128
+ loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
129
+ puts loaded_developer.name # should be "Developer: name" but it's just "name"
130
+ ```
221
131
 
222
- * Avoid leaking the first relation we call `first` on, per model.
132
+ *Dmitry Tsepelev*
223
133
 
224
- Fixes #21921.
134
+ * Values of enum are frozen, raising an error when attempting to modify them.
225
135
 
226
- *Matthew Draper*, *Jean Boussier*
136
+ *Emmanuel Byrd*
227
137
 
228
- * Allow deserialization of Active Record models that were YAML encoded prior
229
- to Rails 4.2
138
+ * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
139
+ if the attribute does not exist.
230
140
 
231
141
  *Sean Griffin*
232
142
 
233
- * Correctly apply `unscope` when preloading through associations.
234
-
235
- *Jimmy Bourassa*
236
-
237
- * Ensure `select` quotes aliased attributes, even when using `from`.
238
-
239
- Fixes #21488
240
-
241
- *Sean Griffin & @johanlunds*
242
-
243
- * Correct query for PostgreSQL 8.2 compatibility.
244
-
245
- *Ben Murphy*, *Matthew Draper*
246
-
247
- * Uniqueness validator raises descriptive error when running on a persisted
248
- record without primary key.
249
-
250
- Closes #21304.
143
+ * Do not use prepared statement in queries that have a large number of binds.
251
144
 
252
- *Yves Senn*
253
-
254
-
255
- ## Rails 4.2.4 (August 24, 2015) ##
256
-
257
- * Skip statement cache on through association reader.
258
-
259
- If the through class has default scopes we should skip the statement
260
- cache.
261
-
262
- Closes #20745.
263
-
264
- *Rafael Mendonça França*
265
-
266
- * Fixes #19420. When generating schema.rb using Postgres BigInt[] data type
267
- the limit: 8 was not coming through. This caused it to become Int[] data type
268
- after doing a rebuild off of schema.rb.
269
-
270
- *Jake Waller*
271
-
272
- * Fix state being carried over from previous transaction.
273
-
274
- Considering the following example where `name` is a required attribute.
275
- Before we had `new_record?` returning `true` for a persisted record:
276
-
277
- author = Author.create! name: 'foo'
278
- author.name = nil
279
- author.save # => false
280
- author.new_record? # => true
281
-
282
- Fixes #20824.
283
-
284
- *Roque Pinel*
145
+ *Ryuta Kamizono*
285
146
 
286
- * Correctly ignore `mark_for_destruction` when `autosave` isn't set to `true`
287
- when validating associations.
147
+ * Fix query cache to load before first request.
288
148
 
289
- Fixes #20882.
149
+ *Eileen M. Uchitelle*
290
150
 
291
- *Sean Griffin*
151
+ * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
292
152
 
293
- * Fix through associations using scopes having the scope merged multiple
294
- times.
153
+ Fixes #33056.
295
154
 
296
- Fixes #20721.
297
- Fixes #20727.
155
+ *Federico Martinez*
298
156
 
299
- *Sean Griffin*
157
+ * Fix duplicated record creation when using nested attributes with `create_with`.
300
158
 
301
- * `ActiveRecord::Base.dump_schema_after_migration` applies migration tasks
302
- other than `db:migrate`. (eg. `db:rollback`, `db:migrate:dup`, ...)
159
+ *Darwin Wu*
303
160
 
304
- Fixes #20743.
161
+ * Fix regression setting children record in parent `before_save` callback.
305
162
 
306
- *Yves Senn*
163
+ *Guo Xiang Tan*
307
164
 
308
- * Correctly raise `ActiveRecord::AssociationTypeMismatch` when assigning
309
- a wrong type to a namespaced association.
165
+ * Prevent leaking of user's DB credentials on `rails db:create` failure.
310
166
 
311
- Fixes #20545.
167
+ *bogdanvlviv*
312
168
 
313
- *Diego Carrion*
169
+ * Clear mutation tracker before continuing the around callbacks.
314
170
 
315
- * Prevent error when using `force_reload: true` on an unassigned polymorphic
316
- belongs_to association.
171
+ *Yuya Tanaka*
317
172
 
318
- Fixes #20426.
173
+ * Prevent deadlocks when waiting for connection from pool.
319
174
 
320
- *James Dabbs*
175
+ *Brent Wheeldon*
321
176
 
177
+ * Avoid extra scoping when using `Relation#update` that was causing this method to change the current scope.
322
178
 
323
- ## Rails 4.2.3 (June 25, 2015) ##
179
+ *Ryuta Kamizono*
324
180
 
325
- * Let `WITH` queries (Common Table Expressions) be explainable.
181
+ * Fix numericality validator not to be affected by custom getter.
326
182
 
327
- *Vladimir Kochnev*
183
+ *Ryuta Kamizono*
328
184
 
329
- * Fix n+1 query problem when eager loading nil associations (fixes #18312)
185
+ * Fix bulk change table ignores comment option on PostgreSQL.
330
186
 
331
- *Sammy Larbi*
187
+ *Yoshiyuki Kinjo*
332
188
 
333
- * Fixed an error which would occur in dirty checking when calling
334
- `update_attributes` from a getter.
335
189
 
336
- Fixes #20531.
190
+ ## Rails 5.2.1.1 (November 27, 2018) ##
337
191
 
338
- *Sean Griffin*
192
+ * No changes.
339
193
 
340
- * Ensure symbols passed to `ActiveRecord::Relation#select` are always treated
341
- as columns.
342
194
 
343
- Fixes #20360.
195
+ ## Rails 5.2.1 (August 07, 2018) ##
344
196
 
345
- *Sean Griffin*
197
+ * PostgreSQL: Support new relkind for partitioned tables.
346
198
 
347
- * Clear query cache when `ActiveRecord::Base#reload` is called.
199
+ Fixes #33008.
348
200
 
349
- *Shane Hender*
201
+ *Yannick Schutz*
350
202
 
351
- * Pass `:extend` option for `has_and_belongs_to_many` associations to the
352
- underlying `has_many :through`.
203
+ * Rollback parent transaction when children fails to update.
353
204
 
354
- *Jaehyun Shin*
205
+ *Guillaume Malette*
355
206
 
356
- * Make `unscope` aware of "less than" and "greater than" conditions.
207
+ * Fix default value for MySQL time types with specified precision.
357
208
 
358
- *TAKAHASHI Kazuaki*
209
+ *Nikolay Kondratyev*
359
210
 
360
- * Revert behavior of `db:schema:load` back to loading the full
361
- environment. This ensures that initializers are run.
211
+ * Fix `touch` option to behave consistently with `Persistence#touch` method.
362
212
 
363
- Fixes #19545.
213
+ *Ryuta Kamizono*
364
214
 
365
- *Yves Senn*
215
+ * Fix `save` in `after_create_commit` won't invoke extra `after_create_commit`.
366
216
 
367
- * Fix missing index when using `timestamps` with the `index` option.
217
+ Fixes #32831.
368
218
 
369
- The `index` option used with `timestamps` should be passed to both
370
- `column` definitions for `created_at` and `updated_at` rather than just
371
- the first.
219
+ *Ryuta Kamizono*
372
220
 
373
- *Paul Mucur*
221
+ * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
374
222
 
375
- * Rename `:class` to `:anonymous_class` in association options.
223
+ *Brian Durand*
376
224
 
377
- Fixes #19659.
225
+ * Fix parent record should not get saved with duplicate children records.
378
226
 
379
- *Andrew White*
227
+ Fixes #32940.
380
228
 
381
- * Fixed a bug where uniqueness validations would error on out of range values,
382
- even if an validation should have prevented it from hitting the database.
229
+ *Santosh Wadghule*
383
230
 
384
- *Andrey Voronkov*
231
+ * Fix that association's after_touch is not called with counter cache.
385
232
 
386
- * Foreign key related methods in the migration DSL respect
387
- `ActiveRecord::Base.pluralize_table_names = false`.
233
+ Fixes #31559.
388
234
 
389
- Fixes #19643.
235
+ *Ryuta Kamizono*
390
236
 
391
- *Mehmet Emin İNAÇ*
237
+ * `becomes` should clear the mutation tracker which is created in `after_initialize`.
392
238
 
393
- * Reduce memory usage from loading types on pg.
239
+ Fixes #32867.
394
240
 
395
- Fixes #19578.
241
+ *Ryuta Kamizono*
396
242
 
397
- *Sean Griffin*
243
+ * Allow a belonging to parent object to be created from a new record.
398
244
 
399
- * Fix referencing wrong table aliases while joining tables of has many through
400
- association (only when calling calculation methods).
245
+ *Jolyon Pawlyn*
401
246
 
402
- Fixes #19276.
247
+ * Fix that building record with assigning multiple has_one associations
248
+ wrongly persists through record.
403
249
 
404
- *pinglamb*
250
+ Fixes #32511.
405
251
 
406
- * Don't attempt to update counter caches, when the column wasn't selected.
252
+ *Sam DeCesare*
407
253
 
408
- Fixes #19437.
254
+ * Fix relation merging when one of the relations is going to skip the
255
+ query cache.
409
256
 
410
- *Sean Griffin*
257
+ *James Williams*
411
258
 
412
- * Correctly persist a serialized attribute that has been returned to
413
- its default value by an in-place modification.
414
259
 
415
- Fixes #19467.
260
+ ## Rails 5.2.0 (April 09, 2018) ##
416
261
 
417
- *Matthew Draper*
262
+ * MySQL: Support mysql2 0.5.x.
418
263
 
419
- * Fix default `format` value in `ActiveRecord::Tasks::DatabaseTasks#schema_file`.
264
+ *Aaron Stone*
420
265
 
421
- *James Cox*
266
+ * Apply time column precision on assignment.
422
267
 
423
- * Dont enroll records in the transaction if they dont have commit callbacks.
424
- That was causing a memory grow problem when creating a lot of records inside a transaction.
268
+ PR #20317 changed the behavior of datetime columns so that when they
269
+ have a specified precision then on assignment the value is rounded to
270
+ that precision. This behavior is now applied to time columns as well.
425
271
 
426
- Fixes #15549.
272
+ Fixes #30301.
427
273
 
428
- *Will Bryant*, *Aaron Patterson*
274
+ *Andrew White*
429
275
 
430
- * Correctly create through records when created on a has many through
431
- association when using `where`.
276
+ * Normalize time column values for SQLite database.
432
277
 
433
- Fixes #19073.
278
+ For legacy reasons, time columns in SQLite are stored as full datetimes
279
+ because until #24542 the quoting for time columns didn't remove the date
280
+ component. To ensure that values are consistent we now normalize the
281
+ date component to 2001-01-01 on reading and writing.
434
282
 
435
- *Sean Griffin*
283
+ *Andrew White*
436
284
 
285
+ * Ensure that the date component is removed when quoting times.
437
286
 
438
- ## Rails 4.2.2 (June 16, 2015) ##
287
+ PR #24542 altered the quoting for time columns so that the date component
288
+ was removed however it only removed it when it was 2001-01-01. Now the
289
+ date component is removed irrespective of what the date is.
439
290
 
440
- * No Changes *
291
+ *Andrew White*
441
292
 
293
+ * Fix `dependent: :destroy` issue for has_one/belongs_to relationship where
294
+ the parent class was getting deleted when the child was not.
442
295
 
443
- ## Rails 4.2.1 (March 19, 2015) ##
296
+ Fixes #32022.
444
297
 
445
- * Fixed ActiveRecord::Relation#becomes! and changed_attributes issues for type column
298
+ *Fernando Gorodscy*
446
299
 
447
- Fixes #17139.
300
+ * Whitelist `NULLS FIRST` and `NULLS LAST` in order clauses too.
448
301
 
449
- *Miklos Fazekas*
302
+ *Xavier Noria*
450
303
 
451
- * `remove_reference` with `foreign_key: true` removes the foreign key before
452
- removing the column. This fixes a bug where it was not possible to remove
453
- the column on MySQL.
304
+ * Fix that after commit callbacks on update does not triggered when optimistic locking is enabled.
454
305
 
455
- Fixes #18664.
306
+ *Ryuta Kamizono*
456
307
 
457
- *Yves Senn*
308
+ * Fix `#columns_for_distinct` of MySQL and PostgreSQL to make
309
+ `ActiveRecord::FinderMethods#limited_ids_for` use correct primary key values
310
+ even if `ORDER BY` columns include other table's primary key.
458
311
 
459
- * Add a `:foreign_key` option to `references` and associated migration
460
- methods. The model and migration generators now use this option, rather than
461
- the `add_foreign_key` form.
312
+ Fixes #28364.
462
313
 
463
- *Sean Griffin*
314
+ *Takumi Kagiyama*
464
315
 
465
- * Fix rounding problem for PostgreSQL timestamp column.
316
+ * Make `reflection.klass` raise if `polymorphic?` not to be misused.
466
317
 
467
- If timestamp column have the precision, it need to format according to
468
- the precision of timestamp column.
318
+ Fixes #31876.
469
319
 
470
320
  *Ryuta Kamizono*
471
321
 
472
- * Respect the database default charset for `schema_migrations` table.
322
+ * PostgreSQL: Allow pg-1.0 gem to be used with Active Record.
323
+
324
+ *Lars Kanis*
473
325
 
474
- The charset of `version` column in `schema_migrations` table is depend
475
- on the database default charset and collation rather than the encoding
476
- of the connection.
326
+ * Deprecate `expand_hash_conditions_for_aggregates` without replacement.
327
+ Using a `Relation` for performing queries is the prefered API.
477
328
 
478
329
  *Ryuta Kamizono*
479
330
 
480
- * Respect custom primary keys for associations when calling `Relation#where`
331
+ * Fix not expanded problem when passing an Array object as argument to the where method using `composed_of` column.
481
332
 
482
- Fixes #18813.
333
+ ```
334
+ david_balance = customers(:david).balance
335
+ Customer.where(balance: [david_balance]).to_sql
483
336
 
484
- *Sean Griffin*
337
+ # Before: WHERE `customers`.`balance` = NULL
338
+ # After : WHERE `customers`.`balance` = 50
339
+ ```
485
340
 
486
- * Fixed several edge cases which could result in a counter cache updating
487
- twice or not updating at all for `has_many` and `has_many :through`.
341
+ Fixes #31723.
488
342
 
489
- Fixes #10865.
343
+ *Yutaro Kanagawa*
490
344
 
491
- *Sean Griffin*
345
+ * Fix `count(:all)` with eager loading and having an order other than the driving table.
492
346
 
493
- * Foreign keys added by migrations were given random, generated names. This
494
- meant a different `structure.sql` would be generated every time a developer
495
- ran migrations on their machine.
347
+ Fixes #31783.
496
348
 
497
- The generated part of foreign key names is now a hash of the table name and
498
- column name, which is consistent every time you run the migration.
349
+ *Ryuta Kamizono*
499
350
 
500
- *Chris Sinjakli*
351
+ * Clear the transaction state when an Active Record object is duped.
501
352
 
502
- * Fixed ActiveRecord::Relation#group method when argument is SQL reserved key word:
353
+ Fixes #31670.
503
354
 
504
- SplitTest.group(:key).count
505
- Property.group(:value).count
355
+ *Yuriy Ustushenko*
506
356
 
507
- *Bogdan Gusiev*
357
+ * Support for PostgreSQL foreign tables.
508
358
 
509
- * Don't define autosave association callbacks twice from
510
- `accepts_nested_attributes_for`.
359
+ *fatkodima*
511
360
 
512
- Fixes #18704.
361
+ * Fix relation merger issue with `left_outer_joins`.
513
362
 
514
- *Sean Griffin*
363
+ *Mehmet Emin İNAÇ*
515
364
 
516
- * Integer types will no longer raise a `RangeError` when assigning an
517
- attribute, but will instead raise when going to the database.
365
+ * Don't allow destroyed object mutation after `save` or `save!` is called.
518
366
 
519
- Fixes several vague issues which were never reported directly. See the
520
- commit message from the commit which added this line for some examples.
367
+ *Ryuta Kamizono*
521
368
 
522
- *Sean Griffin*
369
+ * Take into account association conditions when deleting through records.
523
370
 
524
- * Values which would error while being sent to the database (such as an
525
- ASCII-8BIT string with invalid UTF-8 bytes on Sqlite3), no longer error on
526
- assignment. They will still error when sent to the database, but you are
527
- given the ability to re-assign it to a valid value.
371
+ Fixes #18424.
528
372
 
529
- Fixes #18580.
373
+ *Piotr Jakubowski*
530
374
 
531
- *Sean Griffin*
375
+ * Fix nested `has_many :through` associations on unpersisted parent instances.
532
376
 
533
- * Don't remove join dependencies in `Relation#exists?`
377
+ For example, if you have
534
378
 
535
- Fixes #18632.
379
+ class Post < ActiveRecord::Base
380
+ belongs_to :author
381
+ has_many :books, through: :author
382
+ has_many :subscriptions, through: :books
383
+ end
536
384
 
537
- *Sean Griffin*
385
+ class Author < ActiveRecord::Base
386
+ has_one :post
387
+ has_many :books
388
+ has_many :subscriptions, through: :books
389
+ end
538
390
 
539
- * Invalid values assigned to a JSON column are assumed to be `nil`.
391
+ class Book < ActiveRecord::Base
392
+ belongs_to :author
393
+ has_many :subscriptions
394
+ end
540
395
 
541
- Fixes #18629.
396
+ class Subscription < ActiveRecord::Base
397
+ belongs_to :book
398
+ end
542
399
 
543
- *Sean Griffin*
400
+ Before:
544
401
 
545
- * No longer issue deprecation warning when including a scope with extensions.
546
- Previously every scope with extension methods was transformed into an
547
- instance dependent scope. Including such a scope would wrongfully issue a
548
- deprecation warning. This is no longer the case.
402
+ If `post` is not persisted, then `post.subscriptions` will be empty.
549
403
 
550
- Fixes #18467.
404
+ After:
551
405
 
552
- *Yves Senn*
406
+ If `post` is not persisted, then `post.subscriptions` can be set and used
407
+ just like it would if `post` were persisted.
553
408
 
554
- * Correctly use the type provided by `serialize` when updating records using
555
- optimistic locking.
409
+ Fixes #16313.
556
410
 
557
- Fixes #18385.
411
+ *Zoltan Kiss*
558
412
 
559
- *Sean Griffin*
413
+ * Fixed inconsistency with `first(n)` when used with `limit()`.
414
+ The `first(n)` finder now respects the `limit()`, making it consistent
415
+ with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
560
416
 
561
- * `attribute_will_change!` will no longer cause non-persistable attributes to
562
- be sent to the database.
417
+ Fixes #23979.
563
418
 
564
- Fixes #18407.
419
+ *Brian Christian*
565
420
 
566
- *Sean Griffin*
421
+ * Use `count(:all)` in `HasManyAssociation#count_records` to prevent invalid
422
+ SQL queries for association counting.
567
423
 
568
- * Format the datetime string according to the precision of the datetime field.
424
+ *Klas Eskilson*
569
425
 
570
- Incompatible to rounding behavior between MySQL 5.6 and earlier.
426
+ * Fix to invoke callbacks when using `update_attribute`.
571
427
 
572
- In 5.5, when you insert `2014-08-17 12:30:00.999999` the fractional part
573
- is ignored. In 5.6, it's rounded to `2014-08-17 12:30:01`:
428
+ *Mike Busch*
574
429
 
575
- http://bugs.mysql.com/bug.php?id=68760
430
+ * Fix `count(:all)` to correctly work `distinct` with custom SELECT list.
576
431
 
577
432
  *Ryuta Kamizono*
578
433
 
579
- * Allow precision option for MySQL datetimes.
434
+ * Using subselect for `delete_all` with `limit` or `offset`.
580
435
 
581
436
  *Ryuta Kamizono*
582
437
 
583
- * Clear query cache on rollback.
584
-
585
- *Florian Weingarten*
586
-
587
- * Fixed setting of foreign_key for through associations while building of new record.
588
-
589
- Fixes #12698.
590
-
591
- *Ivan Antropov*
592
-
593
- * Fixed automatic inverse_of for models nested in module.
594
-
595
- *Andrew McCloud*
438
+ * Undefine attribute methods on descendants when resetting column
439
+ information.
596
440
 
597
- * Fix `reaping_frequency` option when the value is a string.
441
+ *Chris Salzberg*
598
442
 
599
- This usually happens when it is configured using `DATABASE_URL`.
443
+ * Log database query callers.
600
444
 
601
- *korbin*
445
+ Add `verbose_query_logs` configuration option to display the caller
446
+ of database queries in the log to facilitate N+1 query resolution
447
+ and other debugging.
602
448
 
603
- * Fix error message when trying to create an associated record and the foreign
604
- key is missing.
449
+ Enabled in development only for new and upgraded applications. Not
450
+ recommended for use in the production environment since it relies
451
+ on Ruby's `Kernel#caller_locations` which is fairly slow.
605
452
 
606
- Before this fix the following exception was being raised:
453
+ *Olivier Lacan*
607
454
 
608
- NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218>
455
+ * Fix conflicts `counter_cache` with `touch: true` by optimistic locking.
609
456
 
610
- Now the message is:
457
+ ```
458
+ # create_table :posts do |t|
459
+ # t.integer :comments_count, default: 0
460
+ # t.integer :lock_version
461
+ # t.timestamps
462
+ # end
463
+ class Post < ApplicationRecord
464
+ end
611
465
 
612
- ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
466
+ # create_table :comments do |t|
467
+ # t.belongs_to :post
468
+ # end
469
+ class Comment < ApplicationRecord
470
+ belongs_to :post, touch: true, counter_cache: true
471
+ end
472
+ ```
613
473
 
614
- *Rafael Mendonça França*
615
-
616
- * Fix change detection problem for PostgreSQL bytea type and
617
- `ArgumentError: string contains null byte` exception with pg-0.18.
618
-
619
- Fixes #17680.
620
-
621
- *Lars Kanis*
622
-
623
- * When a table has a composite primary key, the `primary_key` method for
624
- SQLite3 and PostgreSQL adapters was only returning the first field of the key.
625
- Ensures that it will return nil instead, as Active Record doesn't support
626
- composite primary keys.
627
-
628
- Fixes #18070.
629
-
630
- *arthurnn*
631
-
632
- * Ensure `first!` and friends work on loaded associations.
633
-
634
- Fixes #18237.
635
-
636
- *Sean Griffin*
474
+ Before:
475
+ ```
476
+ post = Post.create!
477
+ # => begin transaction
478
+ INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
479
+ VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
480
+ commit transaction
481
+
482
+ comment = Comment.create!(post: post)
483
+ # => begin transaction
484
+ INSERT INTO "comments" ("post_id") VALUES (1)
485
+
486
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
487
+ "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
488
+
489
+ UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
490
+ "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
491
+ rollback transaction
492
+ # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
493
+
494
+ Comment.take.destroy!
495
+ # => begin transaction
496
+ DELETE FROM "comments" WHERE "comments"."id" = 1
497
+
498
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
499
+ "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
500
+
501
+ UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
502
+ "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
503
+ rollback transaction
504
+ # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
505
+ ```
637
506
 
638
- * Dump the default `nil` for PostgreSQL UUID primary key.
507
+ After:
508
+ ```
509
+ post = Post.create!
510
+ # => begin transaction
511
+ INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
512
+ VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
513
+ commit transaction
639
514
 
640
- *Ryuta Kamizono*
515
+ comment = Comment.create!(post: post)
516
+ # => begin transaction
517
+ INSERT INTO "comments" ("post_id") VALUES (1)
641
518
 
642
- * Don't raise when writing an attribute with an out-of-range datetime passed
643
- by the user.
519
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
520
+ "lock_version" = COALESCE("lock_version", 0) + 1,
521
+ "updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
522
+ commit transaction
644
523
 
645
- *Grey Baker*
524
+ comment.destroy!
525
+ # => begin transaction
526
+ DELETE FROM "comments" WHERE "comments"."id" = 1
646
527
 
647
- * Fixes bug with 'ActiveRecord::Type::Numeric' that causes negative values to
648
- be marked as having changed when set to the same negative value.
528
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
529
+ "lock_version" = COALESCE("lock_version", 0) + 1,
530
+ "updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
531
+ commit transaction
532
+ ```
649
533
 
650
- Fixes #18161.
534
+ Fixes #31199.
651
535
 
652
- *Daniel Fox*
536
+ *bogdanvlviv*
653
537
 
538
+ * Add support for PostgreSQL operator classes to `add_index`.
654
539
 
655
- ## Rails 4.2.0 (December 20, 2014) ##
540
+ Example:
656
541
 
657
- * Introduce `force: :cascade` option for `create_table`. Using this option
658
- will recreate tables even if they have dependent objects (like foreign keys).
659
- `db/schema.rb` now uses `force: :cascade`. This makes it possible to
660
- reload the schema when foreign keys are in place.
542
+ add_index :users, :name, using: :gist, opclass: { name: :gist_trgm_ops }
661
543
 
662
- *Matthew Draper*, *Yves Senn*
544
+ *Greg Navis*
663
545
 
664
- * `db:schema:load` and `db:structure:load` no longer purge the database
665
- before loading the schema. This is left for the user to do.
666
- `db:test:prepare` will still purge the database.
546
+ * Don't allow scopes to be defined which conflict with instance methods on `Relation`.
667
547
 
668
- Fixes #17945.
548
+ Fixes #31120.
669
549
 
670
- *Yves Senn*
550
+ *kinnrot*
671
551
 
672
- * Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.
552
+ * Add new error class `QueryCanceled` which will be raised
553
+ when canceling statement due to user request.
673
554
 
674
555
  *Ryuta Kamizono*
675
556
 
676
- * Add `foreign_type` option to `has_one` and `has_many` association macros.
557
+ * Add `#up_only` to database migrations for code that is only relevant when
558
+ migrating up, e.g. populating a new column.
677
559
 
678
- This option enables to define the column name of associated object's type for polymorphic associations.
560
+ *Rich Daley*
679
561
 
680
- *Ulisses Almeida, Kassio Borges*
562
+ * Require raw SQL fragments to be explicitly marked when used in
563
+ relation query methods.
681
564
 
682
- * `add_timestamps` and `remove_timestamps` now properly reversible with
683
- options.
684
-
685
- *Noam Gagliardi-Rabinovich*
686
-
687
- * Bring back `db:test:prepare` to synchronize the test database schema.
688
-
689
- Manual synchronization using `bin/rake db:test:prepare` is required
690
- when a migration is rolled-back, edited and reapplied.
691
-
692
- `ActiveRecord::Base.maintain_test_schema` now uses `db:test:prepare`
693
- to synchronize the schema. Plugins can use this task as a hook to
694
- provide custom behavior after the schema has been loaded.
695
-
696
- NOTE: `test:prepare` runs before the schema is synchronized.
697
-
698
- Fixes #17171, #15787.
565
+ Before:
566
+ ```
567
+ Article.order("LENGTH(title)")
568
+ ```
699
569
 
700
- *Yves Senn*
570
+ After:
571
+ ```
572
+ Article.order(Arel.sql("LENGTH(title)"))
573
+ ```
701
574
 
702
- * Change `reflections` public api to return the keys as String objects.
575
+ This prevents SQL injection if applications use the [strongly
576
+ discouraged] form `Article.order(params[:my_order])`, under the
577
+ mistaken belief that only column names will be accepted.
703
578
 
704
- Fixes #16928.
579
+ Raw SQL strings will now cause a deprecation warning, which will
580
+ become an UnknownAttributeReference error in Rails 6.0. Applications
581
+ can opt in to the future behavior by setting `allow_unsafe_raw_sql`
582
+ to `:disabled`.
705
583
 
706
- *arthurnn*
584
+ Common and judged-safe string values (such as simple column
585
+ references) are unaffected:
586
+ ```
587
+ Article.order("title DESC")
588
+ ```
707
589
 
708
- * Renaming a table in pg also renames the primary key index.
590
+ *Ben Toews*
709
591
 
710
- Fixes #12856
592
+ * `update_all` will now pass its values to `Type#cast` before passing them to
593
+ `Type#serialize`. This means that `update_all(foo: 'true')` will properly
594
+ persist a boolean.
711
595
 
712
596
  *Sean Griffin*
713
597
 
714
- * Make it possible to access fixtures excluded by a `default_scope`.
715
-
716
- *Yves Senn*
717
-
718
- * Fix preloading of associations with a scope containing joins along with
719
- conditions on the joined association.
720
-
721
- *Siddharth Sharma*
722
-
723
- * Add `Table#name` to match `TableDefinition#name`.
724
-
725
- *Cody Cutrer*
726
-
727
- * Cache `CollectionAssociation#reader` proxies separately before and after
728
- the owner has been saved so that the proxy is not cached without the
729
- owner's id.
730
-
731
- *Ben Woosley*
732
-
733
- * `ActiveRecord::ReadOnlyRecord` now has a descriptive message.
598
+ * Add new error class `StatementTimeout` which will be raised
599
+ when statement timeout exceeded.
734
600
 
735
- *Franky W.*
736
-
737
- * Fix preloading of associations which unscope a default scope.
738
-
739
- Fixes #11036.
740
-
741
- *Byron Bischoff*
742
-
743
- * Added SchemaDumper support for tables with jsonb columns.
744
-
745
- *Ted O'Meara*
746
-
747
- * Deprecate `sanitize_sql_hash_for_conditions` without replacement. Using a
748
- `Relation` for performing queries and updates is the prefered API.
601
+ *Ryuta Kamizono*
749
602
 
750
- *Sean Griffin*
603
+ * Fix `bin/rails db:migrate` with specified `VERSION`.
604
+ `bin/rails db:migrate` with empty VERSION behaves as without `VERSION`.
605
+ Check a format of `VERSION`: Allow a migration version number
606
+ or name of a migration file. Raise error if format of `VERSION` is invalid.
607
+ Raise error if target migration doesn't exist.
751
608
 
752
- * Queries now properly type cast values that are part of a join statement,
753
- even when using type decorators such as `serialize`.
609
+ *bogdanvlviv*
754
610
 
755
- *Melanie Gilman & Sean Griffin*
611
+ * Fixed a bug where column orders for an index weren't written to
612
+ `db/schema.rb` when using the sqlite adapter.
756
613
 
757
- * MySQL enum type lookups, with values matching another type, no longer result
758
- in an endless loop.
614
+ Fixes #30902.
759
615
 
760
- Fixes #17402.
616
+ *Paul Kuruvilla*
761
617
 
762
- *Yves Senn*
618
+ * Remove deprecated method `#sanitize_conditions`.
763
619
 
764
- * Raise `ArgumentError` when the body of a scope is not callable.
620
+ *Rafael Mendonça França*
765
621
 
766
- *Mauro George*
622
+ * Remove deprecated method `#scope_chain`.
767
623
 
768
- * Use type column first in multi-column indexes created with `add-reference`.
624
+ *Rafael Mendonça França*
769
625
 
770
- *Derek Prior*
626
+ * Remove deprecated configuration `.error_on_ignored_order_or_limit`.
771
627
 
772
- * Fix `Relation.rewhere` to work with Range values.
628
+ *Rafael Mendonça França*
773
629
 
774
- *Dan Olson*
630
+ * Remove deprecated arguments from `#verify!`.
775
631
 
776
- * `AR::UnknownAttributeError` now includes the class name of a record.
632
+ *Rafael Mendonça França*
777
633
 
778
- User.new(name: "Yuki Nishijima", project_attributes: {name: "kaminari"})
779
- # => ActiveRecord::UnknownAttributeError: unknown attribute 'name' for User.
634
+ * Remove deprecated argument `name` from `#indexes`.
780
635
 
781
- *Yuki Nishijima*
636
+ *Rafael Mendonça França*
782
637
 
783
- * Fix a regression causing `after_create` callbacks to run before associated
784
- records are autosaved.
638
+ * Remove deprecated method `ActiveRecord::Migrator.schema_migrations_table_name`.
785
639
 
786
- Fixes #17209.
640
+ *Rafael Mendonça França*
787
641
 
788
- *Agis Anastasopoulos*
642
+ * Remove deprecated method `supports_primary_key?`.
789
643
 
790
- * Honor overridden `rack.test` in Rack environment for the connection
791
- management middleware.
644
+ *Rafael Mendonça França*
792
645
 
793
- *Simon Eskildsen*
646
+ * Remove deprecated method `supports_migrations?`.
794
647
 
795
- * Add a truncate method to the connection.
648
+ *Rafael Mendonça França*
796
649
 
797
- *Aaron Patterson*
650
+ * Remove deprecated methods `initialize_schema_migrations_table` and `initialize_internal_metadata_table`.
798
651
 
799
- * Don't autosave unchanged has_one through records.
652
+ *Rafael Mendonça França*
800
653
 
801
- *Alan Kennedy*, *Steve Parrington*
654
+ * Raises when calling `lock!` in a dirty record.
802
655
 
803
- * Do not dump foreign keys for ignored tables.
656
+ *Rafael Mendonça França*
804
657
 
805
- *Yves Senn*
658
+ * Remove deprecated support to passing a class to `:class_name` on associations.
806
659
 
807
- * PostgreSQL adapter correctly dumps foreign keys targeting tables
808
- outside the schema search path.
660
+ *Rafael Mendonça França*
809
661
 
810
- Fixes #16907.
662
+ * Remove deprecated argument `default` from `index_name_exists?`.
811
663
 
812
- *Matthew Draper*, *Yves Senn*
664
+ *Rafael Mendonça França*
813
665
 
814
- * When a thread is killed, rollback the active transaction, instead of
815
- committing it during the stack unwind. Previously, we could commit half-
816
- completed work. This fix only works for Ruby 2.0+; on 1.9, we can't
817
- distinguish a thread kill from an ordinary non-local (block) return, so must
818
- default to committing.
666
+ * Remove deprecated support to `quoted_id` when typecasting an Active Record object.
819
667
 
820
- *Chris Hanks*
668
+ *Rafael Mendonça França*
821
669
 
822
- * A `NullRelation` should represent nothing. This fixes a bug where
823
- `Comment.where(post_id: Post.none)` returned a non-empty result.
670
+ * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
671
+ ar_internal_metadata's data for a test database.
824
672
 
825
- Fixes #15176.
673
+ Before:
674
+ ```
675
+ $ RAILS_ENV=test rails dbconsole
676
+ > SELECT * FROM ar_internal_metadata;
677
+ key|value|created_at|updated_at
678
+ environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
679
+ ```
826
680
 
827
- *Matthew Draper*, *Yves Senn*
681
+ After:
682
+ ```
683
+ $ RAILS_ENV=test rails dbconsole
684
+ > SELECT * FROM ar_internal_metadata;
685
+ key|value|created_at|updated_at
686
+ environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
687
+ ```
828
688
 
829
- * Include default column limits in schema.rb. Allows defaults to be changed
830
- in the future without affecting old migrations that assumed old defaults.
689
+ Fixes #26731.
831
690
 
832
- *Jeremy Kemper*
691
+ *bogdanvlviv*
833
692
 
834
- * MySQL: schema.rb now includes TEXT and BLOB column limits.
693
+ * Fix longer sequence name detection for serial columns.
835
694
 
836
- *Jeremy Kemper*
695
+ Fixes #28332.
837
696
 
838
- * MySQL: correct LONGTEXT and LONGBLOB limits from 2GB to their true 4GB.
697
+ *Ryuta Kamizono*
839
698
 
840
- *Jeremy Kemper*
699
+ * MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`.
841
700
 
842
- * SQLite3Adapter now checks for views in `table_exists?`. Fixes #14041.
701
+ Fixes #30894.
843
702
 
844
- *Girish Sonawane*
703
+ *Ryuta Kamizono*
845
704
 
846
- * Introduce `connection.supports_views?` to check whether the current adapter
847
- has support for SQL views. Connection adapters should define this method.
705
+ * Fix `COUNT(DISTINCT ...)` for `GROUP BY` with `ORDER BY` and `LIMIT`.
848
706
 
849
- *Yves Senn*
707
+ Fixes #30886.
850
708
 
851
- * Allow included modules to override association methods.
709
+ *Ryuta Kamizono*
852
710
 
853
- Fixes #16684.
711
+ * PostgreSQL `tsrange` now preserves subsecond precision.
854
712
 
855
- *Yves Senn*
713
+ PostgreSQL 9.1+ introduced range types, and Rails added support for using
714
+ this datatype in Active Record. However, the serialization of
715
+ `PostgreSQL::OID::Range` was incomplete, because it did not properly
716
+ cast the bounds that make up the range. This led to subseconds being
717
+ dropped in SQL commands:
856
718
 
857
- * Schema loading rake tasks (like `db:schema:load` and `db:setup`) maintain
858
- the database connection to the current environment.
719
+ Before:
859
720
 
860
- Fixes #16757.
721
+ connection.type_cast(tsrange.serialize(range_value))
722
+ # => "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
861
723
 
862
- *Joshua Cody*, *Yves Senn*
724
+ Now:
863
725
 
864
- * MySQL: set the connection collation along with the charset.
726
+ connection.type_cast(tsrange.serialize(range_value))
727
+ # => "[2010-01-01 13:30:00.670277,2011-02-02 19:30:00.745125)"
865
728
 
866
- Sets the connection collation to the database collation configured in
867
- database.yml. Otherwise, `SET NAMES utf8mb4` will use the default
868
- collation for that charset (utf8mb4_general_ci) when you may have chosen
869
- a different collation, like utf8mb4_unicode_ci.
729
+ *Thomas Cannon*
870
730
 
871
- This only applies to literal string comparisons, not column values, so it
872
- is unlikely to affect you.
731
+ * Passing a `Set` to `Relation#where` now behaves the same as passing an
732
+ array.
873
733
 
874
- *Jeremy Kemper*
734
+ *Sean Griffin*
875
735
 
876
- * `default_sequence_name` from the PostgreSQL adapter returns a `String`.
736
+ * Use given algorithm while removing index from database.
877
737
 
878
- *Yves Senn*
738
+ Fixes #24190.
879
739
 
880
- * Fix a regression where whitespaces were stripped from DISTINCT queries in
881
- PostgreSQL.
740
+ *Mehmet Emin İNAÇ*
882
741
 
883
- *Agis Anastasopoulos*
742
+ * Update payload names for `sql.active_record` instrumentation to be
743
+ more descriptive.
884
744
 
885
- Fixes #16623.
745
+ Fixes #30586.
886
746
 
887
- * Fix has_many :through relation merging failing when dynamic conditions are
888
- passed as a lambda with an arity of one.
747
+ *Jeremy Green*
889
748
 
890
- Fixes #16128.
749
+ * Add new error class `LockWaitTimeout` which will be raised
750
+ when lock wait timeout exceeded.
891
751
 
892
- *Agis Anastasopoulos*
752
+ *Gabriel Courtemanche*
893
753
 
894
- * Fix `Relation#exists?` to work with polymorphic associations.
754
+ * Remove deprecated `#migration_keys`.
895
755
 
896
- Fixes #15821.
756
+ *Ryuta Kamizono*
897
757
 
898
- *Kassio Borges*
758
+ * Automatically guess the inverse associations for STI.
899
759
 
900
- * Currently, Active Record rescues any errors raised within
901
- `after_rollback`/`after_create` callbacks and prints them to the logs.
902
- Future versions of Rails will not rescue these errors anymore and
903
- just bubble them up like the other callbacks.
760
+ *Yuichiro Kaneko*
904
761
 
905
- This commit adds an opt-in flag to enable not rescuing the errors.
762
+ * Ensure `sum` honors `distinct` on `has_many :through` associations.
906
763
 
907
- Example:
764
+ Fixes #16791.
908
765
 
909
- # Do not swallow errors in after_commit/after_rollback callbacks.
910
- config.active_record.raise_in_transactional_callbacks = true
766
+ *Aaron Wortham*
911
767
 
912
- Fixes #13460.
768
+ * Add `binary` fixture helper method.
913
769
 
914
- *arthurnn*
770
+ *Atsushi Yoshida*
915
771
 
916
- * Fix an issue where custom accessor methods (such as those generated by
917
- `enum`) with the same name as a global method are incorrectly overridden
918
- when subclassing.
772
+ * When using `Relation#or`, extract the common conditions and put them before the OR condition.
919
773
 
920
- Fixes #16288.
774
+ *Maxime Handfield Lapointe*
921
775
 
922
- *Godfrey Chan*
776
+ * `Relation#or` now accepts two relations who have different values for
777
+ `references` only, as `references` can be implicitly called by `where`.
923
778
 
924
- * `*_was` and `changes` now work correctly for in-place attribute changes as
925
- well.
779
+ Fixes #29411.
926
780
 
927
781
  *Sean Griffin*
928
782
 
929
- * Fix regression on `after_commit` that did not fire with nested transactions.
930
-
931
- Fixes #16425.
783
+ * `ApplicationRecord` is no longer generated when generating models. If you
784
+ need to generate it, it can be created with `rails g application_record`.
932
785
 
933
- *arthurnn*
786
+ *Lisa Ugray*
934
787
 
935
- * Do not try to write timestamps when a table has no timestamps columns.
788
+ * Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT` to keep the existing select list.
936
789
 
937
- Fixes #8813.
938
-
939
- *Sergey Potapov*
790
+ *Ryuta Kamizono*
940
791
 
941
- * `index_exists?` with `:name` option does verify specified columns.
792
+ * When a `has_one` association is destroyed by `dependent: destroy`,
793
+ `destroyed_by_association` will now be set to the reflection, matching the
794
+ behaviour of `has_many` associations.
942
795
 
943
- Example:
796
+ *Lisa Ugray*
944
797
 
945
- add_index :articles, :title, name: "idx_title"
798
+ * Fix `unscoped(where: [columns])` removing the wrong bind values.
946
799
 
947
- # Before:
948
- index_exists? :articles, :title, name: "idx_title" # => `true`
949
- index_exists? :articles, :body, name: "idx_title" # => `true`
800
+ When the `where` is called on a relation after a `or`, unscoping the column of that later `where` removed
801
+ bind values used by the `or` instead. (possibly other cases too)
950
802
 
951
- # After:
952
- index_exists? :articles, :title, name: "idx_title" # => `true`
953
- index_exists? :articles, :body, name: "idx_title" # => `false`
803
+ ```
804
+ Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).to_sql
805
+ # Currently:
806
+ # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 2 OR "posts"."id" = 3)
807
+ # With fix:
808
+ # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1 OR "posts"."id" = 2)
809
+ ```
954
810
 
955
- *Yves Senn*, *Matthew Draper*
811
+ *Maxime Handfield Lapointe*
956
812
 
957
- * `add_timestamps` and `t.timestamps` now require you to pass the `:null` option.
958
- Not passing the option is deprecated but the default is still `null: true`.
959
- With Rails 5 this will change to `null: false`.
813
+ * Values constructed using multi-parameter assignment will now use the
814
+ post-type-cast value for rendering in single-field form inputs.
960
815
 
961
816
  *Sean Griffin*
962
817
 
963
- * When calling `update_columns` on a record that is not persisted, the error
964
- message now reflects whether that object is a new record or has been
965
- destroyed.
966
-
967
- *Lachlan Sylvester*
968
-
969
- * Define `id_was` to get the previous value of the primary key.
970
-
971
- Currently when we call `id_was` and we have a custom primary key name,
972
- Active Record will return the current value of the primary key. This
973
- makes it impossible to correctly do an update operation if you change the
974
- id.
975
-
976
- Fixes #16413.
977
-
978
- *Rafael Mendonça França*
979
-
980
- * Deprecate `DatabaseTasks.load_schema` to act on the current connection.
981
- Use `.load_schema_current` instead. In the future `load_schema` will
982
- require the `configuration` to act on as an argument.
983
-
984
- *Yves Senn*
985
-
986
- * Fix automatic maintaining test schema to properly handle sql structure
987
- schema format.
988
-
989
- Fixes #15394.
990
-
991
- *Wojciech Wnętrzak*
992
-
993
- * Fix type casting to Decimal from Float with large precision.
994
-
995
- *Tomohiro Hashidate*
818
+ * `Relation#joins` is no longer affected by the target model's
819
+ `current_scope`, with the exception of `unscoped`.
996
820
 
997
- * Deprecate `Reflection#source_macro`
821
+ Fixes #29338.
998
822
 
999
- `Reflection#source_macro` is no longer needed in Active Record
1000
- source so it has been deprecated. Code that used `source_macro`
1001
- was removed in #16353.
823
+ *Sean Griffin*
1002
824
 
1003
- *Eileen M. Uchtitelle*, *Aaron Patterson*
825
+ * Change sqlite3 boolean serialization to use 1 and 0.
1004
826
 
1005
- * No verbose backtrace by `db:drop` when database does not exist.
827
+ SQLite natively recognizes 1 and 0 as true and false, but does not natively
828
+ recognize 't' and 'f' as was previously serialized.
1006
829
 
1007
- Fixes #16295.
830
+ This change in serialization requires a migration of stored boolean data
831
+ for SQLite databases, so it's implemented behind a configuration flag
832
+ whose default false value is deprecated.
1008
833
 
1009
- *Kenn Ejima*
834
+ *Lisa Ugray*
1010
835
 
1011
- * Add support for PostgreSQL JSONB.
836
+ * Skip query caching when working with batches of records (`find_each`, `find_in_batches`,
837
+ `in_batches`).
1012
838
 
1013
- Example:
839
+ Previously, records would be fetched in batches, but all records would be retained in memory
840
+ until the end of the request or job.
1014
841
 
1015
- create_table :posts do |t|
1016
- t.jsonb :meta_data
1017
- end
842
+ *Eugene Kenny*
1018
843
 
1019
- *Philippe Creux*, *Chris Teague*
844
+ * Prevent errors raised by `sql.active_record` notification subscribers from being converted into
845
+ `ActiveRecord::StatementInvalid` exceptions.
1020
846
 
1021
- * `db:purge` with MySQL respects `Rails.env`.
847
+ *Dennis Taylor*
1022
848
 
1023
- *Yves Senn*
849
+ * Fix eager loading/preloading association with scope including joins.
1024
850
 
1025
- * `change_column_default :table, :column, nil` with PostgreSQL will issue a
1026
- `DROP DEFAULT` instead of a `DEFAULT NULL` query.
851
+ Fixes #28324.
1027
852
 
1028
- Fixes #16261.
853
+ *Ryuta Kamizono*
1029
854
 
1030
- *Matthew Draper*, *Yves Senn*
855
+ * Fix transactions to apply state to child transactions.
1031
856
 
1032
- * Allow to specify a type for the foreign key column in `references`
1033
- and `add_reference`.
857
+ Previously, if you had a nested transaction and the outer transaction was rolledback, the record from the
858
+ inner transaction would still be marked as persisted.
1034
859
 
1035
- Example:
860
+ This change fixes that by applying the state of the parent transaction to the child transaction when the
861
+ parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
1036
862
 
1037
- change_table :vehicle do |t|
1038
- t.references :station, type: :uuid
1039
- end
863
+ *Eileen M. Uchitelle*, *Aaron Patterson*
1040
864
 
1041
- *Andrey Novikov*, *Łukasz Sarnacki*
865
+ * Deprecate `set_state` method in `TransactionState`.
1042
866
 
1043
- * `create_join_table` removes a common prefix when generating the join table.
1044
- This matches the existing behavior of HABTM associations.
867
+ Deprecated the `set_state` method in favor of setting the state via specific methods. If you need to mark the
868
+ state of the transaction you can now use `rollback!`, `commit!` or `nullify!` instead of
869
+ `set_state(:rolledback)`, `set_state(:committed)`, or `set_state(nil)`.
1045
870
 
1046
- Fixes #13683.
871
+ *Eileen M. Uchitelle*, *Aaron Patterson*
1047
872
 
1048
- *Stefan Kanev*
873
+ * Deprecate delegating to `arel` in `Relation`.
1049
874
 
1050
- * Do not swallow errors on `compute_type` when having a bad `alias_method` on
1051
- a class.
875
+ *Ryuta Kamizono*
1052
876
 
1053
- *arthurnn*
877
+ * Query cache was unavailable when entering the `ActiveRecord::Base.cache` block
878
+ without being connected.
1054
879
 
1055
- * PostgreSQL invalid `uuid` are convert to nil.
880
+ *Tsukasa Oishi*
1056
881
 
1057
- *Abdelkader Boudih*
882
+ * Previously, when building records using a `has_many :through` association,
883
+ if the child records were deleted before the parent was saved, they would
884
+ still be persisted. Now, if child records are deleted before the parent is saved
885
+ on a `has_many :through` association, the child records will not be persisted.
1058
886
 
1059
- * Restore 4.0 behavior for using serialize attributes with `JSON` as coder.
887
+ *Tobias Kraze*
1060
888
 
1061
- With 4.1.x, `serialize` started returning a string when `JSON` was passed as
1062
- the second attribute. It will now return a hash as per previous versions.
889
+ * Merging two relations representing nested joins no longer transforms the joins of
890
+ the merged relation into LEFT OUTER JOIN.
1063
891
 
1064
892
  Example:
1065
893
 
1066
- class Post < ActiveRecord::Base
1067
- serialize :comment, JSON
1068
- end
1069
-
1070
- class Comment
1071
- include ActiveModel::Model
1072
- attr_accessor :category, :text
1073
- end
1074
-
1075
- post = Post.create!
1076
- post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
1077
- post.save!
1078
-
1079
- # 4.0
1080
- post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
1081
-
1082
- # 4.1 before
1083
- post.comment # => "#<Comment:0x007f80ab48ff98>"
1084
-
1085
- # 4.1 after
1086
- post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
1087
-
1088
- When using `JSON` as the coder in `serialize`, Active Record will use the
1089
- new `ActiveRecord::Coders::JSON` coder which delegates its `dump/load` to
1090
- `ActiveSupport::JSON.encode/decode`. This ensures special objects are dumped
1091
- correctly using the `#as_json` hook.
1092
-
1093
- To keep the previous behaviour, supply a custom coder instead
1094
- ([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
1095
-
1096
- Fixes #15594.
1097
-
1098
- *Jenn Cooper*
1099
-
1100
- * Do not use `RENAME INDEX` syntax for MariaDB 10.0.
1101
-
1102
- Fixes #15931.
1103
-
1104
- *Jeff Browning*
1105
-
1106
- * Calling `#empty?` on a `has_many` association would use the value from the
1107
- counter cache if one exists.
1108
-
1109
- *David Verhasselt*
1110
-
1111
- * Fix the schema dump generated for tables without constraints and with
1112
- primary key with default value of custom PostgreSQL function result.
1113
-
1114
- Fixes #16111.
894
+ ```
895
+ Author.joins(:posts).merge(Post.joins(:comments))
896
+ # Before the change:
897
+ #=> SELECT ... FROM authors INNER JOIN posts ON ... LEFT OUTER JOIN comments ON...
1115
898
 
1116
- *Andrey Novikov*
899
+ # After the change:
900
+ #=> SELECT ... FROM authors INNER JOIN posts ON ... INNER JOIN comments ON...
901
+ ```
1117
902
 
1118
- * Fix the SQL generated when a `delete_all` is run on an association to not
1119
- produce an `IN` statements.
903
+ *Maxime Handfield Lapointe*
1120
904
 
1121
- Before:
1122
-
1123
- UPDATE "categorizations" SET "category_id" = NULL WHERE
1124
- "categorizations"."category_id" = 1 AND "categorizations"."id" IN (1, 2)
1125
-
1126
- After:
905
+ * `ActiveRecord::Persistence#touch` does not work well when optimistic locking enabled and
906
+ `locking_column`, without default value, is null in the database.
1127
907
 
1128
- UPDATE "categorizations" SET "category_id" = NULL WHERE
1129
- "categorizations"."category_id" = 1
908
+ *bogdanvlviv*
1130
909
 
1131
- *Eileen M. Uchitelle, Aaron Patterson*
910
+ * Fix destroying existing object does not work well when optimistic locking enabled and
911
+ `locking_column` is null in the database.
1132
912
 
1133
- * Avoid type casting boolean and `ActiveSupport::Duration` values to numeric
1134
- values for string columns. Otherwise, in some database, the string column
1135
- values will be coerced to a numeric allowing false or 0.seconds match any
1136
- string starting with a non-digit.
913
+ *bogdanvlviv*
1137
914
 
1138
- Example:
1139
-
1140
- App.where(apikey: false) # => SELECT * FROM users WHERE apikey = '0'
915
+ * Use bulk INSERT to insert fixtures for better performance.
1141
916
 
1142
- *Dylan Thacker-Smith*
917
+ *Kir Shatrov*
1143
918
 
1144
- * Add a `:required` option to singular associations, providing a nicer
1145
- API for presence validations on associations.
919
+ * Prevent creation of bind param if casted value is nil.
1146
920
 
1147
- *Sean Griffin*
921
+ *Ryuta Kamizono*
1148
922
 
1149
- * Fix an error in `reset_counters` when associations have `select` scope.
1150
- (Call to `count` generated invalid SQL.)
923
+ * Deprecate passing arguments and block at the same time to `count` and `sum` in `ActiveRecord::Calculations`.
1151
924
 
1152
- *Cade Truitt*
925
+ *Ryuta Kamizono*
1153
926
 
1154
- * After a successful `reload`, `new_record?` is always false.
927
+ * Loading model schema from database is now thread-safe.
1155
928
 
1156
- Fixes #12101.
929
+ Fixes #28589.
1157
930
 
1158
- *Matthew Draper*
931
+ *Vikrant Chaudhary*, *David Abdemoulaie*
1159
932
 
1160
- * PostgreSQL renaming table doesn't attempt to rename non existent sequences.
933
+ * Add `ActiveRecord::Base#cache_version` to support recyclable cache keys via the new versioned entries
934
+ in `ActiveSupport::Cache`. This also means that `ActiveRecord::Base#cache_key` will now return a stable key
935
+ that does not include a timestamp any more.
1161
936
 
1162
- *Abdelkader Boudih*
937
+ NOTE: This feature is turned off by default, and `#cache_key` will still return cache keys with timestamps
938
+ until you set `ActiveRecord::Base.cache_versioning = true`. That's the setting for all new apps on Rails 5.2+
1163
939
 
1164
- * Move 'dependent: :destroy' handling for `belongs_to`
1165
- from `before_destroy` to `after_destroy` callback chain
940
+ *DHH*
1166
941
 
1167
- Fixes #12380.
942
+ * Respect `SchemaDumper.ignore_tables` in rake tasks for databases structure dump.
1168
943
 
1169
- *Ivan Antropov*
944
+ *Rusty Geldmacher*, *Guillermo Iguaran*
1170
945
 
1171
- * Detect in-place modifications on String attributes.
946
+ * Add type caster to `RuntimeReflection#alias_name`.
1172
947
 
1173
- Before this change, an attribute modified in-place had to be marked as
1174
- changed in order for it to be persisted in the database. Now it is no longer
1175
- required.
948
+ Fixes #28959.
1176
949
 
1177
- Before:
950
+ *Jon Moss*
1178
951
 
1179
- user = User.first
1180
- user.name << ' Griffin'
1181
- user.name_will_change!
1182
- user.save
1183
- user.reload.name # => "Sean Griffin"
952
+ * Deprecate `supports_statement_cache?`.
1184
953
 
1185
- After:
954
+ *Ryuta Kamizono*
1186
955
 
1187
- user = User.first
1188
- user.name << ' Griffin'
1189
- user.save
1190
- user.reload.name # => "Sean Griffin"
956
+ * Raise error `UnknownMigrationVersionError` on the movement of migrations
957
+ when the current migration does not exist.
1191
958
 
1192
- *Sean Griffin*
959
+ *bogdanvlviv*
1193
960
 
1194
- * Add `ActiveRecord::Base#validate!` that raises `RecordInvalid` if the record
1195
- is invalid.
961
+ * Fix `bin/rails db:forward` first migration.
1196
962
 
1197
- *Bogdan Gusiev*, *Marc Schütz*
963
+ *bogdanvlviv*
1198
964
 
1199
- * Support for adding and removing foreign keys. Foreign keys are now
1200
- a part of `schema.rb`. This is supported by Mysql2Adapter, MysqlAdapter
1201
- and PostgreSQLAdapter.
965
+ * Support Descending Indexes for MySQL.
1202
966
 
1203
- Many thanks to *Matthew Higgins* for laying the foundation with his work on
1204
- [foreigner](https://github.com/matthuhiggins/foreigner).
967
+ MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored.
968
+ See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
1205
969
 
1206
- Example:
970
+ *Ryuta Kamizono*
1207
971
 
1208
- # within your migrations:
1209
- add_foreign_key :articles, :authors
1210
- remove_foreign_key :articles, :authors
972
+ * Fix inconsistency with changed attributes when overriding Active Record attribute reader.
1211
973
 
1212
- *Yves Senn*
974
+ *bogdanvlviv*
1213
975
 
1214
- * Fix subtle bugs regarding attribute assignment on models with no primary
1215
- key. `'id'` will no longer be part of the attributes hash.
976
+ * When calling the dynamic fixture accessor method with no arguments, it now returns all fixtures of this type.
977
+ Previously this method always returned an empty array.
1216
978
 
1217
- *Sean Griffin*
1218
-
1219
- * Deprecate automatic counter caches on `has_many :through`. The behavior was
1220
- broken and inconsistent.
1221
-
1222
- *Sean Griffin*
1223
-
1224
- * `preload` preserves readonly flag for associations.
1225
-
1226
- See #15853.
1227
-
1228
- *Yves Senn*
1229
-
1230
- * Assume numeric types have changed if they were assigned to a value that
1231
- would fail numericality validation, regardless of the old value. Previously
1232
- this would only occur if the old value was 0.
1233
-
1234
- Example:
1235
-
1236
- model = Model.create!(number: 5)
1237
- model.number = '5wibble'
1238
- model.number_changed? # => true
1239
-
1240
- Fixes #14731.
1241
-
1242
- *Sean Griffin*
1243
-
1244
- * `reload` no longer merges with the existing attributes.
1245
- The attribute hash is fully replaced. The record is put into the same state
1246
- as it would be with `Model.find(model.id)`.
1247
-
1248
- *Sean Griffin*
1249
-
1250
- * The object returned from `select_all` must respond to `column_types`.
1251
- If this is not the case a `NoMethodError` is raised.
1252
-
1253
- *Sean Griffin*
1254
-
1255
- * Detect in-place modifications of PG array types
1256
-
1257
- *Sean Griffin*
1258
-
1259
- * Add `bin/rake db:purge` task to empty the current database.
1260
-
1261
- *Yves Senn*
1262
-
1263
- * Deprecate `serialized_attributes` without replacement.
1264
-
1265
- *Sean Griffin*
1266
-
1267
- * Correctly extract IPv6 addresses from `DATABASE_URI`: the square brackets
1268
- are part of the URI structure, not the actual host.
1269
-
1270
- Fixes #15705.
1271
-
1272
- *Andy Bakun*, *Aaron Stone*
1273
-
1274
- * Ensure both parent IDs are set on join records when both sides of a
1275
- through association are new.
1276
-
1277
- *Sean Griffin*
1278
-
1279
- * `ActiveRecord::Dirty` now detects in-place changes to mutable values.
1280
- Serialized attributes on ActiveRecord models will no longer save when
1281
- unchanged.
1282
-
1283
- Fixes #8328.
1284
-
1285
- *Sean Griffin*
1286
-
1287
- * `Pluck` now works when selecting columns from different tables with the same
1288
- name.
1289
-
1290
- Fixes #15649.
1291
-
1292
- *Sean Griffin*
1293
-
1294
- * Remove `cache_attributes` and friends. All attributes are cached.
1295
-
1296
- *Sean Griffin*
1297
-
1298
- * Remove deprecated method `ActiveRecord::Base.quoted_locking_column`.
1299
-
1300
- *Akshay Vishnoi*
1301
-
1302
- * `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
1303
- `Enumerable#find` does.
1304
-
1305
- Fixes #15382.
1306
-
1307
- *James Yang*
1308
-
1309
- * Make timezone aware attributes work with PostgreSQL array columns.
1310
-
1311
- Fixes #13402.
1312
-
1313
- *Kuldeep Aggarwal*, *Sean Griffin*
1314
-
1315
- * `ActiveRecord::SchemaMigration` has no primary key regardless of the
1316
- `primary_key_prefix_type` configuration.
1317
-
1318
- Fixes #15051.
1319
-
1320
- *JoseLuis Torres*, *Yves Senn*
1321
-
1322
- * `rake db:migrate:status` works with legacy migration numbers like `00018_xyz.rb`.
1323
-
1324
- Fixes #15538.
1325
-
1326
- *Yves Senn*
1327
-
1328
- * Baseclass becomes! subclass.
1329
-
1330
- Before this change, a record which changed its STI type, could not be
1331
- updated.
1332
-
1333
- Fixes #14785.
1334
-
1335
- *Matthew Draper*, *Earl St Sauver*, *Edo Balvers*
1336
-
1337
- * Remove deprecated `ActiveRecord::Migrator.proper_table_name`. Use the
1338
- `proper_table_name` instance method on `ActiveRecord::Migration` instead.
1339
-
1340
- *Akshay Vishnoi*
1341
-
1342
- * Fix regression on eager loading association based on SQL query rather than
1343
- existing column.
1344
-
1345
- Fixes #15480.
1346
-
1347
- *Lauro Caetano*, *Carlos Antonio da Silva*
1348
-
1349
- * Deprecate returning `nil` from `column_for_attribute` when no column exists.
1350
- It will return a null object in Rails 5.0
1351
-
1352
- *Sean Griffin*
1353
-
1354
- * Implemented `ActiveRecord::Base#pretty_print` to work with PP.
1355
-
1356
- *Ethan*
1357
-
1358
- * Preserve type when dumping PostgreSQL point, bit, bit varying and money
1359
- columns.
1360
-
1361
- *Yves Senn*
1362
-
1363
- * New records remain new after YAML serialization.
1364
-
1365
- *Sean Griffin*
1366
-
1367
- * PostgreSQL support default values for enum types. Fixes #7814.
1368
-
1369
- *Yves Senn*
1370
-
1371
- * PostgreSQL `default_sequence_name` respects schema. Fixes #7516.
1372
-
1373
- *Yves Senn*
1374
-
1375
- * Fix `columns_for_distinct` of PostgreSQL adapter to work correctly
1376
- with orders without sort direction modifiers.
1377
-
1378
- *Nikolay Kondratyev*
1379
-
1380
- * PostgreSQL `reset_pk_sequence!` respects schemas. Fixes #14719.
1381
-
1382
- *Yves Senn*
1383
-
1384
- * Keep PostgreSQL `hstore` and `json` attributes as `Hash` in `@attributes`.
1385
- Fixes duplication in combination with `store_accessor`.
1386
-
1387
- Fixes #15369.
1388
-
1389
- *Yves Senn*
1390
-
1391
- * `rake railties:install:migrations` respects the order of railties.
1392
-
1393
- *Arun Agrawal*
1394
-
1395
- * Fix redefine a `has_and_belongs_to_many` inside inherited class
1396
- Fixing regression case, where redefining the same `has_and_belongs_to_many`
1397
- definition into a subclass would raise.
1398
-
1399
- Fixes #14983.
1400
-
1401
- *arthurnn*
1402
-
1403
- * Fix `has_and_belongs_to_many` public reflection.
1404
- When defining a `has_and_belongs_to_many`, internally we convert that to two has_many.
1405
- But as `reflections` is a public API, people expect to see the right macro.
1406
-
1407
- Fixes #14682.
1408
-
1409
- *arthurnn*
1410
-
1411
- * Fix serialization for records with an attribute named `format`.
1412
-
1413
- Fixes #15188.
1414
-
1415
- *Godfrey Chan*
1416
-
1417
- * When a `group` is set, `sum`, `size`, `average`, `minimum` and `maximum`
1418
- on a NullRelation should return a Hash.
1419
-
1420
- *Kuldeep Aggarwal*
1421
-
1422
- * Fix serialized fields returning serialized data after being updated with
1423
- `update_column`.
1424
-
1425
- *Simon Hørup Eskildsen*
1426
-
1427
- * Fix polymorphic eager loading when using a String as foreign key.
1428
-
1429
- Fixes #14734.
1430
-
1431
- *Lauro Caetano*
1432
-
1433
- * Change belongs_to touch to be consistent with timestamp updates
1434
-
1435
- If a model is set up with a belongs_to: touch relationship the parent
1436
- record will only be touched if the record was modified. This makes it
1437
- consistent with timestamp updating on the record itself.
1438
-
1439
- *Brock Trappitt*
1440
-
1441
- * Fix the inferred table name of a `has_and_belongs_to_many` auxiliary
1442
- table inside a schema.
1443
-
1444
- Fixes #14824.
1445
-
1446
- *Eric Chahin*
1447
-
1448
- * Remove unused `:timestamp` type. Transparently alias it to `:datetime`
1449
- in all cases. Fixes inconsistencies when column types are sent outside of
1450
- `ActiveRecord`, such as for XML Serialization.
1451
-
1452
- *Sean Griffin*
1453
-
1454
- * Fix bug that added `table_name_prefix` and `table_name_suffix` to
1455
- extension names in PostgreSQL when migrating.
1456
-
1457
- *Joao Carlos*
1458
-
1459
- * The `:index` option in migrations, which previously was only available for
1460
- `references`, now works with any column types.
1461
-
1462
- *Marc Schütz*
1463
-
1464
- * Add support for counter name to be passed as parameter on `CounterCache::ClassMethods#reset_counters`.
1465
-
1466
- *jnormore*
1467
-
1468
- * Restrict deletion of record when using `delete_all` with `uniq`, `group`, `having`
1469
- or `offset`.
1470
-
1471
- In these cases the generated query ignored them and that caused unintended
1472
- records to be deleted.
1473
-
1474
- Fixes #11985.
1475
-
1476
- *Leandro Facchinetti*
1477
-
1478
- * Floats with limit >= 25 that get turned into doubles in MySQL no longer have
1479
- their limit dropped from the schema.
1480
-
1481
- Fixes #14135.
1482
-
1483
- *Aaron Nelson*
1484
-
1485
- * Fix how to calculate associated class name when using namespaced `has_and_belongs_to_many`
1486
- association.
1487
-
1488
- Fixes #14709.
1489
-
1490
- *Kassio Borges*
1491
-
1492
- * `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and
1493
- strings in column names as equal.
1494
-
1495
- This fixes a rare case in which more bind values are passed than there are
1496
- placeholders for them in the generated SQL statement, which can make PostgreSQL
1497
- throw a `StatementInvalid` exception.
1498
-
1499
- *Nat Budin*
1500
-
1501
- * Fix `stored_attributes` to correctly merge the details of stored
1502
- attributes defined in parent classes.
1503
-
1504
- Fixes #14672.
1505
-
1506
- *Brad Bennett*, *Jessica Yao*, *Lakshmi Parthasarathy*
1507
-
1508
- * `change_column_default` allows `[]` as argument to `change_column_default`.
1509
-
1510
- Fixes #11586.
1511
-
1512
- *Yves Senn*
1513
-
1514
- * Handle `name` and `"char"` column types in the PostgreSQL adapter.
1515
-
1516
- `name` and `"char"` are special character types used internally by
1517
- PostgreSQL and are used by internal system catalogs. These field types
1518
- can sometimes show up in structure-sniffing queries that feature internal system
1519
- structures or with certain PostgreSQL extensions.
1520
-
1521
- *J Smith*, *Yves Senn*
1522
-
1523
- * Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and
1524
- NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
1525
-
1526
- Before:
1527
-
1528
- Point.create(value: 1.0/0)
1529
- Point.last.value # => 0.0
1530
-
1531
- After:
1532
-
1533
- Point.create(value: 1.0/0)
1534
- Point.last.value # => Infinity
1535
-
1536
- *Innokenty Mikhailov*
1537
-
1538
- * Allow the PostgreSQL adapter to handle bigserial primary key types again.
1539
-
1540
- Fixes #10410.
1541
-
1542
- *Patrick Robertson*
1543
-
1544
- * Deprecate joining, eager loading and preloading of instance dependent
1545
- associations without replacement. These operations happen before instances
1546
- are created. The current behavior is unexpected and can result in broken
1547
- behavior.
1548
-
1549
- Fixes #15024.
1550
-
1551
- *Yves Senn*
1552
-
1553
- * Fix `has_and_belongs_to_many` CollectionAssociation size calculations.
1554
-
1555
- `has_and_belongs_to_many` should fall back to using the normal CollectionAssociation's
1556
- size calculation if the collection is not cached or loaded.
1557
-
1558
- Fixes #14913, #14914.
1559
-
1560
- *Fred Wu*
1561
-
1562
- * Return a non zero status when running `rake db:migrate:status` and migration table does
1563
- not exist.
1564
-
1565
- *Paul B.*
1566
-
1567
- * Add support for module-level `table_name_suffix` in models.
1568
-
1569
- This makes `table_name_suffix` work the same way as `table_name_prefix` when
1570
- using namespaced models.
1571
-
1572
- *Jenner LaFave*
1573
-
1574
- * Revert the behaviour of `ActiveRecord::Relation#join` changed through 4.0 => 4.1 to 4.0.
1575
-
1576
- In 4.1.0 `Relation#join` is delegated to `Arel#SelectManager`.
1577
- In 4.0 series it is delegated to `Array#join`.
1578
-
1579
- *Bogdan Gusiev*
1580
-
1581
- * Log nil binary column values correctly.
1582
-
1583
- When an object with a binary column is updated with a nil value
1584
- in that column, the SQL logger would throw an exception when trying
1585
- to log that nil value. This only occurs when updating a record
1586
- that already has a non-nil value in that column since an initial nil
1587
- value isn't included in the SQL anyway (at least, when dirty checking
1588
- is enabled.) The column's new value will now be logged as `<NULL binary data>`
1589
- to parallel the existing `<N bytes of binary data>` for non-nil values.
1590
-
1591
- *James Coleman*
1592
-
1593
- * Rails will now pass a custom validation context through to autosave associations
1594
- in order to validate child associations with the same context.
1595
-
1596
- Fixes #13854.
1597
-
1598
- *Eric Chahin*, *Aaron Nelson*, *Kevin Casey*
1599
-
1600
- * Stringify all variables keys of MySQL connection configuration.
1601
-
1602
- When `sql_mode` variable for MySQL adapters set in configuration as `String`
1603
- was ignored and overwritten by strict mode option.
1604
-
1605
- Fixes #14895.
1606
-
1607
- *Paul Nikitochkin*
1608
-
1609
- * Ensure SQLite3 statements are closed on errors.
1610
-
1611
- Fixes #13631.
1612
-
1613
- *Timur Alperovich*
1614
-
1615
- * Give `ActiveRecord::PredicateBuilder` private methods the privacy they deserve.
1616
-
1617
- *Hector Satre*
1618
-
1619
- * When using a custom `join_table` name on a `habtm`, rails was not saving it
1620
- on Reflections. This causes a problem when rails loads fixtures, because it
1621
- uses the reflections to set database with fixtures.
1622
-
1623
- Fixes #14845.
1624
-
1625
- *Kassio Borges*
1626
-
1627
- * Reset the cache when modifying a Relation with cached Arel.
1628
- Additionally display a warning message to make the user aware.
1629
-
1630
- *Yves Senn*
1631
-
1632
- * PostgreSQL should internally use `:datetime` consistently for TimeStamp. Assures
1633
- different spellings of timestamps are treated the same.
1634
-
1635
- Example:
1636
-
1637
- mytimestamp.simplified_type('timestamp without time zone')
1638
- # => :datetime
1639
- mytimestamp.simplified_type('timestamp(6) without time zone')
1640
- # => also :datetime (previously would be :timestamp)
1641
-
1642
- See #14513.
1643
-
1644
- *Jefferson Lai*
1645
-
1646
- * `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.
1647
-
1648
- Fixes #14841.
1649
-
1650
- *Lucas Mazza*
1651
-
1652
- * Fix name collision with `Array#select!` with `Relation#select!`.
1653
-
1654
- Fixes #14752.
1655
-
1656
- *Earl St Sauver*
1657
-
1658
- * Fix unexpected behavior for `has_many :through` associations going through
1659
- a scoped `has_many`.
1660
-
1661
- If a `has_many` association is adjusted using a scope, and another
1662
- `has_many :through` uses this association, then the scope adjustment is
1663
- unexpectedly neglected.
1664
-
1665
- Fixes #14537.
1666
-
1667
- *Jan Habermann*
1668
-
1669
- * `@destroyed` should always be set to `false` when an object is duped.
1670
-
1671
- *Kuldeep Aggarwal*
1672
-
1673
- * Enable `has_many` associations to support irregular inflections.
1674
-
1675
- Fixes #8928.
1676
-
1677
- *arthurnn*, *Javier Goizueta*
1678
-
1679
- * Fix `count` used with a grouping not returning a Hash.
1680
-
1681
- Fixes #14721.
1682
-
1683
- *Eric Chahin*
1684
-
1685
- * `sanitize_sql_like` helper method to escape a string for safe use in an SQL
1686
- LIKE statement.
1687
-
1688
- Example:
1689
-
1690
- class Article
1691
- def self.search(term)
1692
- where("title LIKE ?", sanitize_sql_like(term))
1693
- end
1694
- end
1695
-
1696
- Article.search("20% _reduction_")
1697
- # => Query looks like "... title LIKE '20\% \_reduction\_' ..."
1698
-
1699
- *Rob Gilson*, *Yves Senn*
1700
-
1701
- * Do not quote uuid default value on `change_column`.
1702
-
1703
- Fixes #14604.
1704
-
1705
- *Eric Chahin*
1706
-
1707
- * The comparison between `Relation` and `CollectionProxy` should be consistent.
1708
-
1709
- Example:
1710
-
1711
- author.posts == Post.where(author_id: author.id)
1712
- # => true
1713
- Post.where(author_id: author.id) == author.posts
1714
- # => true
1715
-
1716
- Fixes #13506.
1717
-
1718
- *Lauro Caetano*
1719
-
1720
- * Calling `delete_all` on an unloaded `CollectionProxy` no longer
1721
- generates an SQL statement containing each id of the collection:
1722
-
1723
- Before:
1724
-
1725
- DELETE FROM `model` WHERE `model`.`parent_id` = 1
1726
- AND `model`.`id` IN (1, 2, 3...)
1727
-
1728
- After:
1729
-
1730
- DELETE FROM `model` WHERE `model`.`parent_id` = 1
1731
-
1732
- *Eileen M. Uchitelle*, *Aaron Patterson*
1733
-
1734
- * Fix invalid SQL when aggregate methods (`empty?`, `any?`, `count`) used
1735
- with `select`.
1736
-
1737
- Fixes #13648.
1738
-
1739
- *Simon Woker*
1740
-
1741
- * PostgreSQL adapter only warns once for every missing OID per connection.
1742
-
1743
- Fixes #14275.
1744
-
1745
- *Matthew Draper*, *Yves Senn*
1746
-
1747
- * PostgreSQL adapter automatically reloads it's type map when encountering
1748
- unknown OIDs.
1749
-
1750
- Fixes #14678.
1751
-
1752
- *Matthew Draper*, *Yves Senn*
1753
-
1754
- * Fix insertion of records via `has_many :through` association with scope.
1755
-
1756
- Fixes #3548.
1757
-
1758
- *Ivan Antropov*
1759
-
1760
- * Auto-generate stable fixture UUIDs on PostgreSQL.
1761
-
1762
- Fixes #11524.
1763
-
1764
- *Roderick van Domburg*
1765
-
1766
- * Fix a problem where an enum would overwrite values of another enum with the
1767
- same name in an unrelated class.
1768
-
1769
- Fixes #14607.
1770
-
1771
- *Evan Whalen*
1772
-
1773
- * PostgreSQL and SQLite string columns no longer have a default limit of 255.
1774
-
1775
- Fixes #13435, #9153.
1776
-
1777
- *Vladimir Sazhin*, *Toms Mikoss*, *Yves Senn*
1778
-
1779
- * Make possible to have an association called `records`.
1780
-
1781
- Fixes #11645.
1782
-
1783
- *prathamesh-sonpatki*
1784
-
1785
- * `to_sql` on an association now matches the query that is actually executed, where it
1786
- could previously have incorrectly accrued additional conditions (e.g. as a result of
1787
- a previous query). `CollectionProxy` now always defers to the association scope's
1788
- `arel` method so the (incorrect) inherited one should be entirely concealed.
1789
-
1790
- Fixes #14003.
1791
-
1792
- *Jefferson Lai*
1793
-
1794
- * Block a few default Class methods as scope name.
1795
-
1796
- For instance, this will raise:
1797
-
1798
- scope :public, -> { where(status: 1) }
1799
-
1800
- *arthurnn*
1801
-
1802
- * Fix error when using `with_options` with lambda.
1803
-
1804
- Fixes #9805.
1805
-
1806
- *Lauro Caetano*
1807
-
1808
- * Switch `sqlite3:///` URLs (which were temporarily
1809
- deprecated in 4.1) from relative to absolute.
1810
-
1811
- If you still want the previous interpretation, you should replace
1812
- `sqlite3:///my/path` with `sqlite3:my/path`.
1813
-
1814
- *Matthew Draper*
1815
-
1816
- * Treat blank UUID values as `nil`.
1817
-
1818
- Example:
1819
-
1820
- Sample.new(uuid_field: '') #=> <Sample id: nil, uuid_field: nil>
1821
-
1822
- *Dmitry Lavrov*
1823
-
1824
- * Enable support for materialized views on PostgreSQL >= 9.3.
1825
-
1826
- *Dave Lee*
1827
-
1828
- * The PostgreSQL adapter supports custom domains. Fixes #14305.
1829
-
1830
- *Yves Senn*
1831
-
1832
- * PostgreSQL `Column#type` is now determined through the corresponding OID.
1833
- The column types stay the same except for enum columns. They no longer have
1834
- `nil` as type but `enum`.
1835
-
1836
- See #7814.
1837
-
1838
- *Yves Senn*
1839
-
1840
- * Fix error when specifying a non-empty default value on a PostgreSQL array
1841
- column.
1842
-
1843
- Fixes #10613.
1844
-
1845
- *Luke Steensen*
1846
-
1847
- * Fix error where `.persisted?` throws SystemStackError for an unsaved model with a
1848
- custom primary key that did not save due to validation error.
1849
-
1850
- Fixes #14393.
1851
-
1852
- *Chris Finne*
1853
-
1854
- * Introduce `validate` as an alias for `valid?`.
1855
-
1856
- This is more intuitive when you want to run validations but don't care about the return value.
1857
-
1858
- *Henrik Nyh*
1859
-
1860
- * Create indexes inline in CREATE TABLE for MySQL.
1861
-
1862
- This is important, because adding an index on a temporary table after it has been created
1863
- would commit the transaction.
1864
-
1865
- It also allows creating and dropping indexed tables with fewer queries and fewer permissions
1866
- required.
1867
-
1868
- Example:
1869
-
1870
- create_table :temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query" do |t|
1871
- t.index :zip
1872
- end
1873
- # => CREATE TEMPORARY TABLE temp (INDEX (zip)) AS SELECT id, name, zip FROM a_really_complicated_query
1874
-
1875
- *Cody Cutrer*, *Steve Rice*, *Rafael Mendonça Franca*
1876
-
1877
- * Use singular table name in generated migrations when
1878
- `ActiveRecord::Base.pluralize_table_names` is `false`.
1879
-
1880
- Fixes #13426.
1881
-
1882
- *Kuldeep Aggarwal*
1883
-
1884
- * `touch` accepts many attributes to be touched at once.
1885
-
1886
- Example:
1887
-
1888
- # touches :signed_at, :sealed_at, and :updated_at/on attributes.
1889
- Photo.last.touch(:signed_at, :sealed_at)
1890
-
1891
- *James Pinto*
1892
-
1893
- * `rake db:structure:dump` only dumps schema information if the schema
1894
- migration table exists.
1895
-
1896
- Fixes #14217.
1897
-
1898
- *Yves Senn*
1899
-
1900
- * Reap connections that were checked out by now-dead threads, instead
1901
- of waiting until they disconnect by themselves. Before this change,
1902
- a suitably constructed series of short-lived threads could starve
1903
- the connection pool, without ever having more than a couple alive at
1904
- the same time.
1905
-
1906
- *Matthew Draper*
1907
-
1908
- * `pk_and_sequence_for` now ensures that only the pg_depend entries
1909
- pointing to pg_class, and thus only sequence objects, are considered.
1910
-
1911
- *Josh Williams*
1912
-
1913
- * `where.not` adds `references` for `includes` like normal `where` calls do.
1914
-
1915
- Fixes #14406.
1916
-
1917
- *Yves Senn*
1918
-
1919
- * Extend fixture `$LABEL` replacement to allow string interpolation.
1920
-
1921
- Example:
1922
-
1923
- martin:
1924
- email: $LABEL@email.com
1925
-
1926
- users(:martin).email # => martin@email.com
1927
-
1928
- *Eric Steele*
1929
-
1930
- * Add support for `Relation` be passed as parameter on `QueryCache#select_all`.
1931
-
1932
- Fixes #14361.
1933
-
1934
- *arthurnn*
1935
-
1936
- * Passing an Active Record object to `find` or `exists?` is now deprecated.
1937
- Call `.id` on the object first.
1938
-
1939
- *Aaron Patterson*
1940
-
1941
- * Only use BINARY for MySQL case sensitive uniqueness check when column
1942
- has a case insensitive collation.
1943
-
1944
- *Ryuta Kamizono*
1945
-
1946
- * Support for MySQL 5.6 fractional seconds.
1947
-
1948
- *arthurnn*, *Tatsuhiko Miyagawa*
1949
-
1950
- * Support for PostgreSQL `citext` data type enabling case-insensitive
1951
- `where` values without needing to wrap in UPPER/LOWER sql functions.
1952
-
1953
- *Troy Kruthoff*, *Lachlan Sylvester*
1954
-
1955
- * Only save has_one associations if record has changes.
1956
- Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
1957
- object did not get saved to the db.
1958
-
1959
- *Alan Kennedy*
1960
-
1961
- * Allow strings to specify the `#order` value.
1962
-
1963
- Example:
1964
-
1965
- Model.order(id: 'asc').to_sql == Model.order(id: :asc).to_sql
1966
-
1967
- *Marcelo Casiraghi*, *Robin Dupret*
1968
-
1969
- * Dynamically register PostgreSQL enum OIDs. This prevents "unknown OID"
1970
- warnings on enum columns.
1971
-
1972
- *Dieter Komendera*
1973
-
1974
- * `includes` is able to detect the right preloading strategy when string
1975
- joins are involved.
1976
-
1977
- Fixes #14109.
1978
-
1979
- *Aaron Patterson*, *Yves Senn*
1980
-
1981
- * Fix error with validation with enum fields for records where the value for
1982
- any enum attribute is always evaluated as 0 during uniqueness validation.
1983
-
1984
- Fixes #14172.
1985
-
1986
- *Vilius Luneckas* *Ahmed AbouElhamayed*
1987
-
1988
- * `before_add` callbacks are fired before the record is saved on
1989
- `has_and_belongs_to_many` associations *and* on `has_many :through`
1990
- associations. Before this change, `before_add` callbacks would be fired
1991
- before the record was saved on `has_and_belongs_to_many` associations, but
1992
- *not* on `has_many :through` associations.
1993
-
1994
- Fixes #14144.
1995
-
1996
- * Fix STI classes not defining an attribute method if there is a conflicting
1997
- private method defined on its ancestors.
1998
-
1999
- Fixes #11569.
2000
-
2001
- *Godfrey Chan*
2002
-
2003
- * Coerce strings when reading attributes. Fixes #10485.
2004
-
2005
- Example:
2006
-
2007
- book = Book.new(title: 12345)
2008
- book.save!
2009
- book.title # => "12345"
2010
-
2011
- *Yves Senn*
2012
-
2013
- * Deprecate half-baked support for PostgreSQL range values with excluding beginnings.
2014
- We currently map PostgreSQL ranges to Ruby ranges. This conversion is not fully
2015
- possible because the Ruby range does not support excluded beginnings.
2016
-
2017
- The current solution of incrementing the beginning is not correct and is now
2018
- deprecated. For subtypes where we don't know how to increment (e.g. `#succ`
2019
- is not defined) it will raise an `ArgumentException` for ranges with excluding
2020
- beginnings.
2021
-
2022
- *Yves Senn*
2023
-
2024
- * Support for user created range types in PostgreSQL.
979
+ *Kevin McPhillips*
2025
980
 
2026
- *Yves Senn*
2027
981
 
2028
- Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/activerecord/CHANGELOG.md) for previous changes.
982
+ Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activerecord/CHANGELOG.md) for previous changes.