activerecord 3.2.22.5 → 5.2.8

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 (275) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +657 -621
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +41 -46
  5. data/examples/performance.rb +55 -42
  6. data/examples/simple.rb +6 -5
  7. data/lib/active_record/aggregations.rb +264 -236
  8. data/lib/active_record/association_relation.rb +40 -0
  9. data/lib/active_record/associations/alias_tracker.rb +47 -42
  10. data/lib/active_record/associations/association.rb +127 -75
  11. data/lib/active_record/associations/association_scope.rb +126 -92
  12. data/lib/active_record/associations/belongs_to_association.rb +78 -27
  13. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +9 -4
  14. data/lib/active_record/associations/builder/association.rb +117 -32
  15. data/lib/active_record/associations/builder/belongs_to.rb +135 -60
  16. data/lib/active_record/associations/builder/collection_association.rb +61 -54
  17. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +120 -42
  18. data/lib/active_record/associations/builder/has_many.rb +10 -64
  19. data/lib/active_record/associations/builder/has_one.rb +19 -51
  20. data/lib/active_record/associations/builder/singular_association.rb +28 -18
  21. data/lib/active_record/associations/collection_association.rb +226 -293
  22. data/lib/active_record/associations/collection_proxy.rb +1067 -69
  23. data/lib/active_record/associations/foreign_association.rb +13 -0
  24. data/lib/active_record/associations/has_many_association.rb +83 -47
  25. data/lib/active_record/associations/has_many_through_association.rb +98 -65
  26. data/lib/active_record/associations/has_one_association.rb +57 -20
  27. data/lib/active_record/associations/has_one_through_association.rb +18 -9
  28. data/lib/active_record/associations/join_dependency/join_association.rb +48 -126
  29. data/lib/active_record/associations/join_dependency/join_base.rb +11 -12
  30. data/lib/active_record/associations/join_dependency/join_part.rb +35 -42
  31. data/lib/active_record/associations/join_dependency.rb +212 -164
  32. data/lib/active_record/associations/preloader/association.rb +95 -89
  33. data/lib/active_record/associations/preloader/through_association.rb +84 -44
  34. data/lib/active_record/associations/preloader.rb +123 -111
  35. data/lib/active_record/associations/singular_association.rb +33 -24
  36. data/lib/active_record/associations/through_association.rb +60 -26
  37. data/lib/active_record/associations.rb +1759 -1506
  38. data/lib/active_record/attribute_assignment.rb +60 -193
  39. data/lib/active_record/attribute_decorators.rb +90 -0
  40. data/lib/active_record/attribute_methods/before_type_cast.rb +55 -8
  41. data/lib/active_record/attribute_methods/dirty.rb +113 -74
  42. data/lib/active_record/attribute_methods/primary_key.rb +106 -77
  43. data/lib/active_record/attribute_methods/query.rb +8 -5
  44. data/lib/active_record/attribute_methods/read.rb +63 -114
  45. data/lib/active_record/attribute_methods/serialization.rb +60 -90
  46. data/lib/active_record/attribute_methods/time_zone_conversion.rb +69 -43
  47. data/lib/active_record/attribute_methods/write.rb +43 -45
  48. data/lib/active_record/attribute_methods.rb +366 -149
  49. data/lib/active_record/attributes.rb +266 -0
  50. data/lib/active_record/autosave_association.rb +312 -225
  51. data/lib/active_record/base.rb +114 -505
  52. data/lib/active_record/callbacks.rb +145 -67
  53. data/lib/active_record/coders/json.rb +15 -0
  54. data/lib/active_record/coders/yaml_column.rb +32 -23
  55. data/lib/active_record/collection_cache_key.rb +53 -0
  56. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +883 -284
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +16 -2
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +350 -200
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +82 -27
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +150 -65
  61. data/lib/active_record/connection_adapters/abstract/savepoints.rb +23 -0
  62. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +146 -0
  63. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +477 -284
  64. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +95 -0
  65. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +1100 -310
  66. data/lib/active_record/connection_adapters/abstract/transaction.rb +283 -0
  67. data/lib/active_record/connection_adapters/abstract_adapter.rb +450 -118
  68. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +657 -446
  69. data/lib/active_record/connection_adapters/column.rb +50 -255
  70. data/lib/active_record/connection_adapters/connection_specification.rb +287 -0
  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 +59 -210
  82. data/lib/active_record/connection_adapters/postgresql/column.rb +44 -0
  83. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +163 -0
  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 +92 -0
  86. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +56 -0
  87. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +15 -0
  88. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +17 -0
  89. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +50 -0
  90. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
  91. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +23 -0
  92. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +15 -0
  93. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +21 -0
  94. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +71 -0
  95. data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +15 -0
  96. data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +15 -0
  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 +41 -0
  99. data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +15 -0
  100. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +65 -0
  101. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +97 -0
  102. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +18 -0
  103. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +111 -0
  104. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +23 -0
  105. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +28 -0
  106. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +30 -0
  107. data/lib/active_record/connection_adapters/postgresql/oid.rb +34 -0
  108. data/lib/active_record/connection_adapters/postgresql/quoting.rb +168 -0
  109. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +43 -0
  110. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +65 -0
  111. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +206 -0
  112. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +50 -0
  113. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +774 -0
  114. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +39 -0
  115. data/lib/active_record/connection_adapters/postgresql/utils.rb +81 -0
  116. data/lib/active_record/connection_adapters/postgresql_adapter.rb +620 -1080
  117. data/lib/active_record/connection_adapters/schema_cache.rb +85 -36
  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 +545 -27
  126. data/lib/active_record/connection_adapters/statement_pool.rb +34 -13
  127. data/lib/active_record/connection_handling.rb +145 -0
  128. data/lib/active_record/core.rb +559 -0
  129. data/lib/active_record/counter_cache.rb +200 -105
  130. data/lib/active_record/define_callbacks.rb +22 -0
  131. data/lib/active_record/dynamic_matchers.rb +107 -69
  132. data/lib/active_record/enum.rb +244 -0
  133. data/lib/active_record/errors.rb +245 -60
  134. data/lib/active_record/explain.rb +35 -71
  135. data/lib/active_record/explain_registry.rb +32 -0
  136. data/lib/active_record/explain_subscriber.rb +18 -9
  137. data/lib/active_record/fixture_set/file.rb +82 -0
  138. data/lib/active_record/fixtures.rb +418 -275
  139. data/lib/active_record/gem_version.rb +17 -0
  140. data/lib/active_record/inheritance.rb +209 -100
  141. data/lib/active_record/integration.rb +116 -21
  142. data/lib/active_record/internal_metadata.rb +45 -0
  143. data/lib/active_record/legacy_yaml_adapter.rb +48 -0
  144. data/lib/active_record/locale/en.yml +9 -1
  145. data/lib/active_record/locking/optimistic.rb +107 -94
  146. data/lib/active_record/locking/pessimistic.rb +20 -8
  147. data/lib/active_record/log_subscriber.rb +99 -34
  148. data/lib/active_record/migration/command_recorder.rb +199 -64
  149. data/lib/active_record/migration/compatibility.rb +217 -0
  150. data/lib/active_record/migration/join_table.rb +17 -0
  151. data/lib/active_record/migration.rb +893 -296
  152. data/lib/active_record/model_schema.rb +328 -175
  153. data/lib/active_record/nested_attributes.rb +338 -242
  154. data/lib/active_record/no_touching.rb +58 -0
  155. data/lib/active_record/null_relation.rb +68 -0
  156. data/lib/active_record/persistence.rb +557 -170
  157. data/lib/active_record/query_cache.rb +14 -43
  158. data/lib/active_record/querying.rb +36 -24
  159. data/lib/active_record/railtie.rb +147 -52
  160. data/lib/active_record/railties/console_sandbox.rb +5 -4
  161. data/lib/active_record/railties/controller_runtime.rb +13 -6
  162. data/lib/active_record/railties/databases.rake +206 -488
  163. data/lib/active_record/readonly_attributes.rb +4 -6
  164. data/lib/active_record/reflection.rb +734 -228
  165. data/lib/active_record/relation/batches/batch_enumerator.rb +69 -0
  166. data/lib/active_record/relation/batches.rb +249 -52
  167. data/lib/active_record/relation/calculations.rb +330 -284
  168. data/lib/active_record/relation/delegation.rb +135 -37
  169. data/lib/active_record/relation/finder_methods.rb +450 -287
  170. data/lib/active_record/relation/from_clause.rb +26 -0
  171. data/lib/active_record/relation/merger.rb +193 -0
  172. data/lib/active_record/relation/predicate_builder/array_handler.rb +48 -0
  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 +19 -0
  179. data/lib/active_record/relation/predicate_builder.rb +132 -43
  180. data/lib/active_record/relation/query_attribute.rb +45 -0
  181. data/lib/active_record/relation/query_methods.rb +1037 -221
  182. data/lib/active_record/relation/record_fetch_warning.rb +51 -0
  183. data/lib/active_record/relation/spawn_methods.rb +48 -151
  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 +451 -359
  187. data/lib/active_record/result.rb +129 -20
  188. data/lib/active_record/runtime_registry.rb +24 -0
  189. data/lib/active_record/sanitization.rb +164 -136
  190. data/lib/active_record/schema.rb +31 -19
  191. data/lib/active_record/schema_dumper.rb +154 -107
  192. data/lib/active_record/schema_migration.rb +56 -0
  193. data/lib/active_record/scoping/default.rb +108 -98
  194. data/lib/active_record/scoping/named.rb +125 -112
  195. data/lib/active_record/scoping.rb +77 -123
  196. data/lib/active_record/secure_token.rb +40 -0
  197. data/lib/active_record/serialization.rb +10 -6
  198. data/lib/active_record/statement_cache.rb +121 -0
  199. data/lib/active_record/store.rb +175 -16
  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 +337 -0
  203. data/lib/active_record/tasks/mysql_database_tasks.rb +115 -0
  204. data/lib/active_record/tasks/postgresql_database_tasks.rb +143 -0
  205. data/lib/active_record/tasks/sqlite_database_tasks.rb +83 -0
  206. data/lib/active_record/timestamp.rb +80 -41
  207. data/lib/active_record/touch_later.rb +64 -0
  208. data/lib/active_record/transactions.rb +240 -119
  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 +9 -0
  212. data/lib/active_record/type/date_time.rb +9 -0
  213. data/lib/active_record/type/decimal_without_scale.rb +15 -0
  214. data/lib/active_record/type/hash_lookup_type_map.rb +25 -0
  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 +71 -0
  218. data/lib/active_record/type/text.rb +11 -0
  219. data/lib/active_record/type/time.rb +21 -0
  220. data/lib/active_record/type/type_map.rb +62 -0
  221. data/lib/active_record/type/unsigned_integer.rb +17 -0
  222. data/lib/active_record/type.rb +79 -0
  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 +35 -18
  228. data/lib/active_record/validations/length.rb +26 -0
  229. data/lib/active_record/validations/presence.rb +68 -0
  230. data/lib/active_record/validations/uniqueness.rb +133 -75
  231. data/lib/active_record/validations.rb +53 -43
  232. data/lib/active_record/version.rb +7 -7
  233. data/lib/active_record.rb +89 -57
  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 +61 -8
  237. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +24 -0
  238. data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +46 -0
  239. data/lib/rails/generators/active_record/migration.rb +28 -8
  240. data/lib/rails/generators/active_record/model/model_generator.rb +23 -22
  241. data/lib/rails/generators/active_record/model/templates/model.rb.tt +13 -0
  242. data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +1 -1
  243. data/lib/rails/generators/active_record.rb +10 -16
  244. metadata +141 -62
  245. data/examples/associations.png +0 -0
  246. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +0 -63
  247. data/lib/active_record/associations/join_helper.rb +0 -55
  248. data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
  249. data/lib/active_record/associations/preloader/collection_association.rb +0 -24
  250. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +0 -60
  251. data/lib/active_record/associations/preloader/has_many.rb +0 -17
  252. data/lib/active_record/associations/preloader/has_many_through.rb +0 -15
  253. data/lib/active_record/associations/preloader/has_one.rb +0 -23
  254. data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
  255. data/lib/active_record/associations/preloader/singular_association.rb +0 -21
  256. data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +0 -32
  257. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +0 -191
  258. data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -441
  259. data/lib/active_record/connection_adapters/sqlite_adapter.rb +0 -583
  260. data/lib/active_record/dynamic_finder_match.rb +0 -68
  261. data/lib/active_record/dynamic_scope_match.rb +0 -23
  262. data/lib/active_record/fixtures/file.rb +0 -65
  263. data/lib/active_record/identity_map.rb +0 -162
  264. data/lib/active_record/observer.rb +0 -121
  265. data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
  266. data/lib/active_record/serializers/xml_serializer.rb +0 -203
  267. data/lib/active_record/session_store.rb +0 -360
  268. data/lib/active_record/test_case.rb +0 -73
  269. data/lib/rails/generators/active_record/migration/templates/migration.rb +0 -34
  270. data/lib/rails/generators/active_record/model/templates/migration.rb +0 -15
  271. data/lib/rails/generators/active_record/model/templates/model.rb +0 -12
  272. data/lib/rails/generators/active_record/observer/observer_generator.rb +0 -15
  273. data/lib/rails/generators/active_record/observer/templates/observer.rb +0 -4
  274. data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +0 -25
  275. data/lib/rails/generators/active_record/session_migration/templates/migration.rb +0 -12
data/CHANGELOG.md CHANGED
@@ -1,1020 +1,1056 @@
1
- * Support Ruby 2.3 by not unexpectedly calling `.to_proc` on Hash objects
1
+ ## Rails 5.2.8 (May 09, 2022) ##
2
2
 
3
- Fixes #25010
3
+ * No changes.
4
4
 
5
- *tlrdstd*
6
5
 
7
- ## Rails 3.2.22 (Jun 16, 2015) ##
6
+ ## Rails 5.2.7.1 (April 26, 2022) ##
8
7
 
9
- * No changes.
8
+ * No changes.
10
9
 
11
10
 
12
- ## Rails 3.2.19 (Jul 2, 2014) ##
11
+ ## Rails 5.2.7 (March 10, 2022) ##
13
12
 
14
- * Fix SQL Injection Vulnerability in 'bitstring' quoting.
13
+ * No changes.
15
14
 
16
- Fixes CVE-2014-3482.
17
15
 
18
- *Rafael Mendonça França*
16
+ ## Rails 5.2.6.3 (March 08, 2022) ##
19
17
 
18
+ * No changes.
20
19
 
21
- ## Rails 3.2.18 (May 6, 2014) ##
22
20
 
23
- * No changes.
21
+ ## Rails 5.2.6.2 (February 11, 2022) ##
24
22
 
23
+ * No changes.
25
24
 
26
- ## Rails 3.2.17 (Feb 18, 2014) ##
27
25
 
28
- * No changes.
26
+ ## Rails 5.2.6.1 (February 11, 2022) ##
29
27
 
28
+ * No changes.
30
29
 
31
- ## Rails 3.2.16 (Dec 3, 2013) ##
32
30
 
33
- * No changes.
31
+ ## Rails 5.2.6 (May 05, 2021) ##
34
32
 
33
+ * No changes.
35
34
 
36
- ## Rails 3.2.15 (Oct 16, 2013) ##
37
35
 
38
- * When calling the method .find_or_initialize_by_* from a collection_proxy
39
- it should set the inverse_of relation even when the entry was found on the db.
36
+ ## Rails 5.2.5 (March 26, 2021) ##
40
37
 
41
- *arthurnn*
38
+ * No changes.
42
39
 
43
- * Callbacks on has_many should access the in memory parent if a inverse_of is set.
44
40
 
45
- *arthurnn*
41
+ ## Rails 5.2.4.6 (May 05, 2021) ##
46
42
 
47
- * Fix `FinderMethods#last` unscoped primary key.
43
+ * No changes.
48
44
 
49
- Fixes #11917.
50
45
 
51
- *Eugene Kalenkovich*
46
+ ## Rails 5.2.4.5 (February 10, 2021) ##
52
47
 
53
- * Load fixtures from linked folders.
48
+ * Fix possible DoS vector in PostgreSQL money type
54
49
 
55
- *Kassio Borges*
50
+ Carefully crafted input can cause a DoS via the regular expressions used
51
+ for validating the money format in the PostgreSQL adapter. This patch
52
+ fixes the regexp.
56
53
 
57
- * When using optimistic locking, `update` was not passing the column to `quote_value`
58
- to allow the connection adapter to properly determine how to quote the value. This was
59
- affecting certain databases that use specific colmn types.
54
+ Thanks to @dee-see from Hackerone for this patch!
60
55
 
61
- Fixes: #6763
56
+ [CVE-2021-22880]
62
57
 
63
- *Alfred Wong*
58
+ *Aaron Patterson*
64
59
 
65
60
 
66
- ## Rails 3.2.14 (Jul 22, 2013) ##
61
+ ## Rails 5.2.4.4 (September 09, 2020) ##
67
62
 
68
- * Fix merge error when Equality LHS is non-attribute.
69
- Backport of #7380.
63
+ * No changes.
70
64
 
71
- *Karmes Alexander*
72
65
 
73
- * Do not re-create destroyed association when saving the parent object.
66
+ ## Rails 5.2.4.3 (May 18, 2020) ##
74
67
 
75
- Fixes #11450.
68
+ * No changes.
76
69
 
77
- *Paul Nikitochkin*
70
+ ## Rails 5.2.4.2 (March 19, 2020) ##
78
71
 
79
- * Do not shallow the original exception in `exec_cache` on PostgreSQL adapter.
72
+ * No changes.
80
73
 
81
- Fixes #11260.
82
74
 
83
- *Rafael Mendonça França*
75
+ ## Rails 5.2.4.1 (December 18, 2019) ##
84
76
 
85
- * Fix `ActiveRecord::Store` incorrectly tracking changes of its attributes.
86
- Fixes #10373.
77
+ * No changes.
87
78
 
88
- *Janko Marohnić*
89
79
 
90
- * Fix a bug that prevented the use of the default STI inheritance column
91
- (ActiveRecord::Base.inheritance_column = 'some_column'.)
80
+ ## Rails 5.2.4 (November 27, 2019) ##
92
81
 
93
- *chapmajs + Takehiro Adachi*
82
+ * Fix circular `autosave: true` causes invalid records to be saved.
94
83
 
95
- * Fix mysql2 adapter raises the correct exception when executing a query on a
96
- closed connection.
84
+ Prior to the fix, when there was a circular series of `autosave: true`
85
+ associations, the callback for a `has_many` association was run while
86
+ another instance of the same callback on the same association hadn't
87
+ finished running. When control returned to the first instance of the
88
+ callback, the instance variable had changed, and subsequent associated
89
+ records weren't saved correctly. Specifically, the ID field for the
90
+ `belongs_to` corresponding to the `has_many` was `nil`.
97
91
 
98
- *Yves Senn*
92
+ Fixes #28080.
99
93
 
100
- * Fixes bug where `Company.new.contract_ids` would incorrectly load
101
- all non-associated contracts.
94
+ *Larry Reid*
102
95
 
103
- Example:
96
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
104
97
 
105
- company = Company.new # Company has many :contracts
98
+ Fixes #36022.
106
99
 
107
- # before
108
- company.contract_ids # => SELECT ... WHERE `contracts`.`company_id` IS NULL
100
+ *Ryuta Kamizono*
109
101
 
110
- # after
111
- company.contract_ids # => []
102
+ * Fix sqlite3 collation parsing when using decimal columns.
112
103
 
113
- *Jared Armstrong*
104
+ *Martin R. Schuster*
114
105
 
115
- * Fix the `:primary_key` option for `has_many` associations.
116
- Fixes #10693.
106
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
117
107
 
118
- *Yves Senn*
108
+ Fixes #36465.
119
109
 
120
- * fixes bug introduced by #3329. Now, when autosaving associations,
121
- deletions happen before inserts and saves. This prevents a 'duplicate
122
- unique value' database error that would occur if a record being created had
123
- the same value on a unique indexed field as that of a record being destroyed.
110
+ *Jeff Doering*
124
111
 
125
- Backport of #10417
112
+ * Assign all attributes before calling `build` to ensure the child record is visible in
113
+ `before_add` and `after_add` callbacks for `has_many :through` associations.
126
114
 
127
- *Johnny Holton*
115
+ Fixes #33249.
128
116
 
129
- * Fix that under some conditions, Active Record could produce invalid SQL of the sort:
130
- "SELECT DISTINCT DISTINCT".
117
+ *Ryan H. Kerr*
131
118
 
132
- Backport of #6792.
133
119
 
134
- *Ben Woosley*
120
+ ## Rails 5.2.3 (March 27, 2019) ##
135
121
 
136
- * Require `ActiveRecord::Base` in railtie hooks for rake_tasks, console and runner to
137
- avoid circular constant loading issues.
122
+ * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
138
123
 
139
- Backport #7695.
124
+ Fixes #35214.
140
125
 
141
- Fixes #7683 and #882
126
+ *Juani Villarejo*
142
127
 
143
- *Ben Holley*
128
+ * Fix prepared statements caching to be enabled even when query caching is enabled.
144
129
 
145
- * Maintain context for joins within ActiveRecord::Relation merges.
146
- Backport #10164.
130
+ *Ryuta Kamizono*
147
131
 
148
- *Neeraj Singh + Andrew Horner*
132
+ * Don't allow `where` with invalid value matches to nil values.
149
133
 
150
- * Make sure the `EXPLAIN` command is never triggered by a `select_db` call.
134
+ Fixes #33624.
151
135
 
152
- *Daniel Schierbeck*
136
+ *Ryuta Kamizono*
153
137
 
154
- * Revert changes on `pluck` that was ignoring the select clause when the relation already
155
- has one. This caused a regression since it changed the behavior in a stable release.
138
+ * Restore an ability that class level `update` without giving ids.
156
139
 
157
- Fixes #9777.
140
+ Fixes #34743.
158
141
 
159
- *Rafael Mendonça França*
142
+ *Ryuta Kamizono*
160
143
 
161
- * Confirm a record has not already been destroyed before decrementing counter cache.
144
+ * Fix join table column quoting with SQLite.
162
145
 
163
- *Ben Tucker*
146
+ *Gannon McGibbon*
164
147
 
165
- * Default values for PostgreSQL bigint types now get parsed and dumped to the
166
- schema correctly.
167
- Backport #10098.
148
+ * Ensure that `delete_all` on collection proxy returns affected count.
168
149
 
169
- *Erik Peterson*
150
+ *Ryuta Kamizono*
170
151
 
171
- * Removed warning when `auto_explain_threshold_in_seconds` is set and the
172
- connection adapter doesn't support explain.
173
- This is causing a regression since the Active Record Railtie is trying to
174
- connect to the development database in the application boot.
152
+ * Reset scope after delete on collection association to clear stale offsets of removed records.
175
153
 
176
- *Rafael Mendonça França*
154
+ *Gannon McGibbon*
177
155
 
178
- * Do not reset `inheritance_column` when it's set explicitly.
179
- Backport of #5327.
180
156
 
181
- *kennyj + Fred Wu*
157
+ ## Rails 5.2.2.1 (March 11, 2019) ##
182
158
 
183
- * Fix a problem wrong exception is occured
184
- when raising no translatable exception in PostgreSQL.
159
+ * No changes.
185
160
 
186
- *kennyj*
187
161
 
188
- * Resets the postgres search path in the structure.sql after the structure
189
- is dumped in order to find schema_migrations table when multiples schemas
190
- are used.
191
- Fixes #9796.
162
+ ## Rails 5.2.2 (December 04, 2018) ##
192
163
 
193
- *Juan M. Cuello + Dembskiy Alexander*
164
+ * Do not ignore the scoping with query methods in the scope block.
194
165
 
195
- * Reload the association target if it's stale. `@stale_state` should be nil
196
- when a model isn't saved.
197
- Fixes #7526.
166
+ *Ryuta Kamizono*
198
167
 
199
- *Larry Lv*
168
+ * Allow aliased attributes to be used in `#update_columns` and `#update`.
200
169
 
201
- * Don't read CSV files during execution of `db:fixtures:load`. CSV support for
202
- fixtures was removed some time ago but the task was still loading them, even
203
- though later the code was looking for the related yaml file instead.
170
+ *Gannon McGibbon*
204
171
 
205
- *kennyj*
172
+ * Allow spaces in postgres table names.
206
173
 
174
+ Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres
175
+ adapter.
207
176
 
208
- ## Rails 3.2.13 (Mar 18, 2013) ##
177
+ *Gannon McGibbon*
209
178
 
210
- * Chaining multiple preloaded scopes will correctly preload all the scopes
211
- at the same time.
179
+ * Cached columns_hash fields should be excluded from ResultSet#column_types
212
180
 
213
- *Chris Geihsler*
181
+ PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
182
+ was passing for SQLite and MySQL, but failed for PostgreSQL:
214
183
 
215
- * Reverted 921a296a3390192a71abeec6d9a035cc6d1865c8, 'Quote numeric values
216
- compared to string columns.' This caused several regressions.
184
+ ```ruby
185
+ class DeveloperName < ActiveRecord::Type::String
186
+ def deserialize(value)
187
+ "Developer: #{value}"
188
+ end
189
+ end
217
190
 
218
- *Steve Klabnik*
191
+ class AttributedDeveloper < ActiveRecord::Base
192
+ self.table_name = "developers"
219
193
 
220
- * Fix overriding of attributes by `default_scope` on `ActiveRecord::Base#dup`.
194
+ attribute :name, DeveloperName.new
221
195
 
222
- *Hiroshige UMINO*
196
+ self.ignored_columns += ["name"]
197
+ end
223
198
 
224
- * Fix issue with overriding Active Record reader methods with a composed object
225
- and using that attribute as the scope of a `uniqueness_of` validation.
226
- Backport #7072.
199
+ developer = AttributedDeveloper.create
200
+ developer.update_column :name, "name"
227
201
 
228
- *Peter Brown*
202
+ loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
203
+ puts loaded_developer.name # should be "Developer: name" but it's just "name"
204
+ ```
229
205
 
230
- * Sqlite now preserves custom primary keys when copying or altering tables.
231
- Fixes #9367.
232
- Backport #2312.
206
+ *Dmitry Tsepelev*
233
207
 
234
- *Sean Scally + Yves Senn*
208
+ * Values of enum are frozen, raising an error when attempting to modify them.
235
209
 
236
- * Preloading `has_many :through` associations with conditions won't
237
- cache the `:through` association. This will prevent invalid
238
- subsets to be cached.
239
- Fixes #8423.
240
- Backport #9252.
210
+ *Emmanuel Byrd*
241
211
 
242
- Example:
212
+ * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
213
+ if the attribute does not exist.
243
214
 
244
- class User
245
- has_many :posts
246
- has_many :recent_comments, -> { where('created_at > ?', 1.week.ago) }, :through => :posts
247
- end
215
+ *Sean Griffin*
248
216
 
249
- a_user = User.includes(:recent_comments).first
217
+ * Do not use prepared statement in queries that have a large number of binds.
250
218
 
251
- # this is preloaded
252
- a_user.recent_comments
219
+ *Ryuta Kamizono*
253
220
 
254
- # fetching the recent_comments through the posts association won't preload it.
255
- a_user.posts
221
+ * Fix query cache to load before first request.
256
222
 
257
- *Yves Senn*
223
+ *Eileen M. Uchitelle*
258
224
 
259
- * Fix handling of dirty time zone aware attributes
225
+ * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
260
226
 
261
- Previously, when `time_zone_aware_attributes` were enabled, after
262
- changing a datetime or timestamp attribute and then changing it back
263
- to the original value, `changed_attributes` still tracked the
264
- attribute as changed. This caused `[attribute]_changed?` and
265
- `changed?` methods to return true incorrectly.
227
+ Fixes #33056.
266
228
 
267
- Example:
229
+ *Federico Martinez*
268
230
 
269
- in_time_zone 'Paris' do
270
- order = Order.new
271
- original_time = Time.local(2012, 10, 10)
272
- order.shipped_at = original_time
273
- order.save
274
- order.changed? # => false
231
+ * Fix duplicated record creation when using nested attributes with `create_with`.
275
232
 
276
- # changing value
277
- order.shipped_at = Time.local(2013, 1, 1)
278
- order.changed? # => true
233
+ *Darwin Wu*
279
234
 
280
- # reverting to original value
281
- order.shipped_at = original_time
282
- order.changed? # => false, used to return true
283
- end
235
+ * Fix regression setting children record in parent `before_save` callback.
284
236
 
285
- Backport of #9073
286
- Fixes #8898
237
+ *Guo Xiang Tan*
287
238
 
288
- *Lilibeth De La Cruz*
239
+ * Prevent leaking of user's DB credentials on `rails db:create` failure.
289
240
 
290
- * Fix counter cache columns not updated when replacing `has_many :through`
291
- associations.
292
- Backport #8400.
293
- Fix #7630.
241
+ *bogdanvlviv*
294
242
 
295
- *Matthew Robertson*
243
+ * Clear mutation tracker before continuing the around callbacks.
296
244
 
297
- * Don't update `column_defaults` when calling destructive methods on column with default value.
298
- Backport c517602.
299
- Fix #6115.
245
+ *Yuya Tanaka*
300
246
 
301
- *Piotr Sarnacki + Aleksey Magusev + Alan Daud*
247
+ * Prevent deadlocks when waiting for connection from pool.
302
248
 
303
- * When `#count` is used in conjunction with `#uniq` we perform `count(:distinct => true)`.
304
- Fix #6865.
249
+ *Brent Wheeldon*
305
250
 
306
- Example:
251
+ * Avoid extra scoping when using `Relation#update` that was causing this method to change the current scope.
307
252
 
308
- relation.uniq.count # => SELECT COUNT(DISTINCT *)
253
+ *Ryuta Kamizono*
309
254
 
310
- *Yves Senn + Kaspar Schiess*
255
+ * Fix numericality validator not to be affected by custom getter.
311
256
 
312
- * Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
313
- Backport #7536.
314
- Fix #8968.
257
+ *Ryuta Kamizono*
315
258
 
316
- *Ian Lesperance + Yves Senn + Kaspar Schiess*
259
+ * Fix bulk change table ignores comment option on PostgreSQL.
317
260
 
318
- * Don't run explain on slow queries for database adapters that don't support it.
319
- Backport #6197.
261
+ *Yoshiyuki Kinjo*
320
262
 
321
- *Blake Smith*
322
263
 
323
- * Revert round usec when comparing timestamp attributes in the dirty tracking.
324
- Fixes #8460.
264
+ ## Rails 5.2.1.1 (November 27, 2018) ##
325
265
 
326
- *Andrew White*
266
+ * No changes.
327
267
 
328
- * Revert creation of through association models when using `collection=[]`
329
- on a `has_many :through` association from an unsaved model.
330
- Fix #7661, #8269.
331
268
 
332
- *Ernie Miller*
269
+ ## Rails 5.2.1 (August 07, 2018) ##
333
270
 
334
- * Fix undefined method `to_i` when calling `new` on a scope that uses an
335
- Array; Fix FloatDomainError when setting integer column to NaN.
336
- Fixes #8718, #8734, #8757.
271
+ * PostgreSQL: Support new relkind for partitioned tables.
337
272
 
338
- *Jason Stirk + Tristan Harward*
273
+ Fixes #33008.
339
274
 
340
- * Serialized attributes can be serialized in integer columns.
341
- Fix #8575.
275
+ *Yannick Schutz*
342
276
 
343
- *Rafael Mendonça França*
277
+ * Rollback parent transaction when children fails to update.
344
278
 
345
- * Keep index names when using `alter_table` with sqlite3.
346
- Fix #3489.
347
- Backport #8522.
279
+ *Guillaume Malette*
348
280
 
349
- *Yves Senn*
281
+ * Fix default value for MySQL time types with specified precision.
350
282
 
351
- * Recognize migrations placed in directories containing numbers and 'rb'.
352
- Fix #8492.
353
- Backport of #8500.
283
+ *Nikolay Kondratyev*
354
284
 
355
- *Yves Senn*
285
+ * Fix `touch` option to behave consistently with `Persistence#touch` method.
356
286
 
357
- * Add `ActiveRecord::Base.cache_timestamp_format` class attribute to control
358
- the format of the timestamp value in the cache key.
359
- This allows users to improve the precision of the cache key.
360
- Fixes #8195.
287
+ *Ryuta Kamizono*
361
288
 
362
- *Rafael Mendonça França*
289
+ * Fix `save` in `after_create_commit` won't invoke extra `after_create_commit`.
290
+
291
+ Fixes #32831.
363
292
 
364
- * Add `:nsec` date format. This can be used to improve the precision of cache key.
365
- Please note that this format only works with Ruby 1.9, Ruby 1.8 will ignore it completely.
293
+ *Ryuta Kamizono*
366
294
 
367
- *Jamie Gaskins*
295
+ * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
368
296
 
369
- * Unscope `update_column(s)` query to ignore default scope.
297
+ *Brian Durand*
370
298
 
371
- When applying `default_scope` to a class with a where clause, using
372
- `update_column(s)` could generate a query that would not properly update
373
- the record due to the where clause from the `default_scope` being applied
374
- to the update query.
299
+ * Fix parent record should not get saved with duplicate children records.
375
300
 
376
- class User < ActiveRecord::Base
377
- default_scope where(active: true)
378
- end
301
+ Fixes #32940.
379
302
 
380
- user = User.first
381
- user.active = false
382
- user.save!
303
+ *Santosh Wadghule*
383
304
 
384
- user.update_column(:active, true) # => false
305
+ * Fix that association's after_touch is not called with counter cache.
385
306
 
386
- In this situation we want to skip the default_scope clause and just
387
- update the record based on the primary key. With this change:
307
+ Fixes #31559.
388
308
 
389
- user.update_column(:active, true) # => true
309
+ *Ryuta Kamizono*
390
310
 
391
- Backport of #8436 fix.
311
+ * `becomes` should clear the mutation tracker which is created in `after_initialize`.
392
312
 
393
- *Carlos Antonio da Silva*
313
+ Fixes #32867.
394
314
 
395
- * Fix performance problem with primary_key method in PostgreSQL adapter when having many schemas.
396
- Uses pg_constraint table instead of pg_depend table which has many records in general.
397
- Fix #8414
315
+ *Ryuta Kamizono*
398
316
 
399
- *kennyj*
317
+ * Allow a belonging to parent object to be created from a new record.
400
318
 
401
- * Do not instantiate intermediate Active Record objects when eager loading.
402
- These records caused `after_find` to run more than expected.
403
- Fix #3313
404
- Backport of #8403
319
+ *Jolyon Pawlyn*
405
320
 
406
- *Yves Senn*
321
+ * Fix that building record with assigning multiple has_one associations
322
+ wrongly persists through record.
407
323
 
408
- * Fix `pluck` to work with joins. Backport of #4942.
324
+ Fixes #32511.
409
325
 
410
- *Carlos Antonio da Silva*
326
+ *Sam DeCesare*
411
327
 
412
- * Fix a problem with `translate_exception` method in a non English environment.
413
- Backport of #6397.
328
+ * Fix relation merging when one of the relations is going to skip the
329
+ query cache.
414
330
 
415
- *kennyj*
331
+ *James Williams*
416
332
 
417
- * Fix dirty attribute checks for TimeZoneConversion with nil and blank
418
- datetime attributes. Setting a nil datetime to a blank string should not
419
- result in a change being flagged.
420
- Fixes #8310.
421
- Backport of #8311.
422
333
 
423
- *Alisdair McDiarmid*
334
+ ## Rails 5.2.0 (April 09, 2018) ##
424
335
 
425
- * Prevent mass assignment to the type column of polymorphic associations when using `build`.
426
- Fixes #8265.
427
- Backport of #8291.
336
+ * MySQL: Support mysql2 0.5.x.
428
337
 
429
- *Yves Senn*
338
+ *Aaron Stone*
430
339
 
431
- * When running migrations on Postgresql, the `:limit` option for `binary` and `text` columns is
432
- silently dropped.
433
- Previously, these migrations caused sql exceptions, because Postgresql doesn't support limits
434
- on these types.
340
+ * Apply time column precision on assignment.
435
341
 
436
- *Victor Costan*
342
+ PR #20317 changed the behavior of datetime columns so that when they
343
+ have a specified precision then on assignment the value is rounded to
344
+ that precision. This behavior is now applied to time columns as well.
437
345
 
438
- * `#pluck` can be used on a relation with `select` clause.
439
- Fixes #7551.
440
- Backport of #8176.
346
+ Fixes #30301.
441
347
 
442
- Example:
348
+ *Andrew White*
443
349
 
444
- Topic.select([:approved, :id]).order(:id).pluck(:id)
350
+ * Normalize time column values for SQLite database.
445
351
 
446
- *Yves Senn*
352
+ For legacy reasons, time columns in SQLite are stored as full datetimes
353
+ because until #24542 the quoting for time columns didn't remove the date
354
+ component. To ensure that values are consistent we now normalize the
355
+ date component to 2001-01-01 on reading and writing.
447
356
 
448
- * Use `nil?` instead of `blank?` to check whether dynamic finder with a bang
449
- should raise RecordNotFound.
450
- Fixes #7238.
357
+ *Andrew White*
451
358
 
452
- *Nikita Afanasenko*
359
+ * Ensure that the date component is removed when quoting times.
453
360
 
454
- * Fix deleting from a HABTM join table upon destroying an object of a model
455
- with optimistic locking enabled.
456
- Fixes #5332.
361
+ PR #24542 altered the quoting for time columns so that the date component
362
+ was removed however it only removed it when it was 2001-01-01. Now the
363
+ date component is removed irrespective of what the date is.
457
364
 
458
- *Nick Rogers*
365
+ *Andrew White*
459
366
 
460
- * Use query cache/uncache when using ENV["DATABASE_URL"].
461
- Fixes #6951.
462
- Backport of #8074.
367
+ * Fix `dependent: :destroy` issue for has_one/belongs_to relationship where
368
+ the parent class was getting deleted when the child was not.
463
369
 
464
- *kennyj*
370
+ Fixes #32022.
465
371
 
466
- * Do not create useless database transaction when building `has_one` association.
372
+ *Fernando Gorodscy*
467
373
 
468
- Example:
374
+ * Whitelist `NULLS FIRST` and `NULLS LAST` in order clauses too.
469
375
 
470
- User.has_one :profile
471
- User.new.build_profile
376
+ *Xavier Noria*
472
377
 
473
- Backport of #8154.
378
+ * Fix that after commit callbacks on update does not triggered when optimistic locking is enabled.
474
379
 
475
- *Bogdan Gusiev*
380
+ *Ryuta Kamizono*
476
381
 
477
- * `AR::Base#attributes_before_type_cast` now returns unserialized values for serialized attributes.
382
+ * Fix `#columns_for_distinct` of MySQL and PostgreSQL to make
383
+ `ActiveRecord::FinderMethods#limited_ids_for` use correct primary key values
384
+ even if `ORDER BY` columns include other table's primary key.
478
385
 
479
- *Nikita Afanasenko*
386
+ Fixes #28364.
480
387
 
481
- * Fix issue that raises `NameError` when overriding the `accepts_nested_attributes` in child classes.
388
+ *Takumi Kagiyama*
482
389
 
483
- Before:
390
+ * Make `reflection.klass` raise if `polymorphic?` not to be misused.
391
+
392
+ Fixes #31876.
393
+
394
+ *Ryuta Kamizono*
395
+
396
+ * PostgreSQL: Allow pg-1.0 gem to be used with Active Record.
397
+
398
+ *Lars Kanis*
399
+
400
+ * Deprecate `expand_hash_conditions_for_aggregates` without replacement.
401
+ Using a `Relation` for performing queries is the prefered API.
402
+
403
+ *Ryuta Kamizono*
404
+
405
+ * Fix not expanded problem when passing an Array object as argument to the where method using `composed_of` column.
406
+
407
+ ```
408
+ david_balance = customers(:david).balance
409
+ Customer.where(balance: [david_balance]).to_sql
410
+
411
+ # Before: WHERE `customers`.`balance` = NULL
412
+ # After : WHERE `customers`.`balance` = 50
413
+ ```
414
+
415
+ Fixes #31723.
416
+
417
+ *Yutaro Kanagawa*
418
+
419
+ * Fix `count(:all)` with eager loading and having an order other than the driving table.
420
+
421
+ Fixes #31783.
422
+
423
+ *Ryuta Kamizono*
424
+
425
+ * Clear the transaction state when an Active Record object is duped.
426
+
427
+ Fixes #31670.
428
+
429
+ *Yuriy Ustushenko*
430
+
431
+ * Support for PostgreSQL foreign tables.
432
+
433
+ *fatkodima*
434
+
435
+ * Fix relation merger issue with `left_outer_joins`.
484
436
 
485
- class Shared::Person < ActiveRecord::Base
486
- has_one :address
437
+ *Mehmet Emin İNAÇ*
487
438
 
488
- accepts_nested_attributes :address, :reject_if => :all_blank
439
+ * Don't allow destroyed object mutation after `save` or `save!` is called.
440
+
441
+ *Ryuta Kamizono*
442
+
443
+ * Take into account association conditions when deleting through records.
444
+
445
+ Fixes #18424.
446
+
447
+ *Piotr Jakubowski*
448
+
449
+ * Fix nested `has_many :through` associations on unpersisted parent instances.
450
+
451
+ For example, if you have
452
+
453
+ class Post < ActiveRecord::Base
454
+ belongs_to :author
455
+ has_many :books, through: :author
456
+ has_many :subscriptions, through: :books
489
457
  end
490
458
 
491
- class Person < Shared::Person
492
- accepts_nested_attributes :address
459
+ class Author < ActiveRecord::Base
460
+ has_one :post
461
+ has_many :books
462
+ has_many :subscriptions, through: :books
493
463
  end
494
464
 
495
- Person
496
- #=> NameError: method `address_attributes=' not defined in Person
465
+ class Book < ActiveRecord::Base
466
+ belongs_to :author
467
+ has_many :subscriptions
468
+ end
469
+
470
+ class Subscription < ActiveRecord::Base
471
+ belongs_to :book
472
+ end
473
+
474
+ Before:
475
+
476
+ If `post` is not persisted, then `post.subscriptions` will be empty.
497
477
 
498
478
  After:
499
479
 
500
- Person
501
- #=> Person(id: integer, ...)
480
+ If `post` is not persisted, then `post.subscriptions` can be set and used
481
+ just like it would if `post` were persisted.
502
482
 
503
- Fixes #8131.
483
+ Fixes #16313.
504
484
 
505
- *Gabriel Sobrinho, Ricardo Henrique*
485
+ *Zoltan Kiss*
506
486
 
487
+ * Fixed inconsistency with `first(n)` when used with `limit()`.
488
+ The `first(n)` finder now respects the `limit()`, making it consistent
489
+ with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
507
490
 
508
- ## Rails 3.2.12 (Feb 11, 2013) ##
491
+ Fixes #23979.
509
492
 
510
- * Quote numeric values being compared to non-numeric columns. Otherwise,
511
- in some database, the string column values will be coerced to a numeric
512
- allowing 0, 0.0 or false to match any string starting with a non-digit.
493
+ *Brian Christian*
513
494
 
514
- Example:
495
+ * Use `count(:all)` in `HasManyAssociation#count_records` to prevent invalid
496
+ SQL queries for association counting.
515
497
 
516
- App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
498
+ *Klas Eskilson*
517
499
 
518
- *Dylan Smith*
500
+ * Fix to invoke callbacks when using `update_attribute`.
519
501
 
502
+ *Mike Busch*
520
503
 
521
- ## Rails 3.2.11 (Jan 8, 2013) ##
504
+ * Fix `count(:all)` to correctly work `distinct` with custom SELECT list.
522
505
 
523
- * Fix querying with an empty hash *Damien Mathieu* [CVE-2013-0155]
506
+ *Ryuta Kamizono*
524
507
 
508
+ * Using subselect for `delete_all` with `limit` or `offset`.
525
509
 
526
- ## Rails 3.2.10 (Jan 2, 2013) ##
510
+ *Ryuta Kamizono*
527
511
 
528
- * CVE-2012-5664 options hashes should only be extracted if there are extra
529
- parameters
512
+ * Undefine attribute methods on descendants when resetting column
513
+ information.
530
514
 
515
+ *Chris Salzberg*
531
516
 
532
- ## Rails 3.2.9 (Nov 12, 2012) ##
517
+ * Log database query callers.
533
518
 
534
- * Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
519
+ Add `verbose_query_logs` configuration option to display the caller
520
+ of database queries in the log to facilitate N+1 query resolution
521
+ and other debugging.
535
522
 
536
- *Alexis Bernard*
523
+ Enabled in development only for new and upgraded applications. Not
524
+ recommended for use in the production environment since it relies
525
+ on Ruby's `Kernel#caller_locations` which is fairly slow.
537
526
 
538
- * Fix issue with collection associations calling first(n)/last(n) and attempting
539
- to set the inverse association when `:inverse_of` was used. Fixes #8087.
527
+ *Olivier Lacan*
540
528
 
541
- *Carlos Antonio da Silva*
529
+ * Fix conflicts `counter_cache` with `touch: true` by optimistic locking.
542
530
 
543
- * Fix bug when Column is trying to type cast boolean values to integer.
544
- Fixes #8067.
531
+ ```
532
+ # create_table :posts do |t|
533
+ # t.integer :comments_count, default: 0
534
+ # t.integer :lock_version
535
+ # t.timestamps
536
+ # end
537
+ class Post < ApplicationRecord
538
+ end
545
539
 
546
- *Rafael Mendonça França*
540
+ # create_table :comments do |t|
541
+ # t.belongs_to :post
542
+ # end
543
+ class Comment < ApplicationRecord
544
+ belongs_to :post, touch: true, counter_cache: true
545
+ end
546
+ ```
547
547
 
548
- * Fix bug where `rake db:test:prepare` tries to load the structure.sql into development database.
549
- Fixes #8032.
548
+ Before:
549
+ ```
550
+ post = Post.create!
551
+ # => begin transaction
552
+ INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
553
+ VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
554
+ commit transaction
555
+
556
+ comment = Comment.create!(post: post)
557
+ # => begin transaction
558
+ INSERT INTO "comments" ("post_id") VALUES (1)
559
+
560
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
561
+ "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
562
+
563
+ UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
564
+ "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
565
+ rollback transaction
566
+ # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
567
+
568
+ Comment.take.destroy!
569
+ # => begin transaction
570
+ DELETE FROM "comments" WHERE "comments"."id" = 1
571
+
572
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
573
+ "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
574
+
575
+ UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
576
+ "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
577
+ rollback transaction
578
+ # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
579
+ ```
550
580
 
551
- *Grace Liu + Rafael Mendonça França*
581
+ After:
582
+ ```
583
+ post = Post.create!
584
+ # => begin transaction
585
+ INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
586
+ VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
587
+ commit transaction
552
588
 
553
- * Fixed support for `DATABASE_URL` environment variable for rake db tasks. *Grace Liu*
589
+ comment = Comment.create!(post: post)
590
+ # => begin transaction
591
+ INSERT INTO "comments" ("post_id") VALUES (1)
554
592
 
555
- * Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
593
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
594
+ "lock_version" = COALESCE("lock_version", 0) + 1,
595
+ "updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
596
+ commit transaction
556
597
 
557
- *Henrik Nyh*
598
+ comment.destroy!
599
+ # => begin transaction
600
+ DELETE FROM "comments" WHERE "comments"."id" = 1
558
601
 
559
- * Decode URI encoded attributes on database connection URLs.
602
+ UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
603
+ "lock_version" = COALESCE("lock_version", 0) + 1,
604
+ "updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
605
+ commit transaction
606
+ ```
560
607
 
561
- *Shawn Veader*
608
+ Fixes #31199.
562
609
 
563
- * Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
564
- and the dup'ed object shared the same errors.
610
+ *bogdanvlviv*
565
611
 
566
- *Christian Seiler*
612
+ * Add support for PostgreSQL operator classes to `add_index`.
567
613
 
568
- * Synchronize around deleting from the reserved connections hash.
569
- Fixes #7955
614
+ Example:
570
615
 
571
- * PostgreSQL adapter correctly fetches default values when using
572
- multiple schemas and domains in a db. Fixes #7914
616
+ add_index :users, :name, using: :gist, opclass: { name: :gist_trgm_ops }
573
617
 
574
- *Arturo Pie*
618
+ *Greg Navis*
575
619
 
576
- * Fix deprecation notice when loading a collection association that
577
- selects columns from other tables, if a new record was previously
578
- built using that association.
620
+ * Don't allow scopes to be defined which conflict with instance methods on `Relation`.
579
621
 
580
- *Ernie Miller*
622
+ Fixes #31120.
581
623
 
582
- * The postgres adapter now supports tables with capital letters.
583
- Fix #5920
624
+ *kinnrot*
584
625
 
585
- *Yves Senn*
626
+ * Add new error class `QueryCanceled` which will be raised
627
+ when canceling statement due to user request.
586
628
 
587
- * `CollectionAssociation#count` returns `0` without querying if the
588
- parent record is not persisted.
629
+ *Ryuta Kamizono*
589
630
 
590
- Before:
631
+ * Add `#up_only` to database migrations for code that is only relevant when
632
+ migrating up, e.g. populating a new column.
591
633
 
592
- person.pets.count
593
- # SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
594
- # => 0
634
+ *Rich Daley*
635
+
636
+ * Require raw SQL fragments to be explicitly marked when used in
637
+ relation query methods.
638
+
639
+ Before:
640
+ ```
641
+ Article.order("LENGTH(title)")
642
+ ```
595
643
 
596
644
  After:
645
+ ```
646
+ Article.order(Arel.sql("LENGTH(title)"))
647
+ ```
597
648
 
598
- person.pets.count
599
- # fires without sql query
600
- # => 0
649
+ This prevents SQL injection if applications use the [strongly
650
+ discouraged] form `Article.order(params[:my_order])`, under the
651
+ mistaken belief that only column names will be accepted.
601
652
 
602
- *Francesco Rodriguez*
653
+ Raw SQL strings will now cause a deprecation warning, which will
654
+ become an UnknownAttributeReference error in Rails 6.0. Applications
655
+ can opt in to the future behavior by setting `allow_unsafe_raw_sql`
656
+ to `:disabled`.
603
657
 
604
- * Fix `reset_counters` crashing on `has_many :through` associations.
605
- Fix #7822.
658
+ Common and judged-safe string values (such as simple column
659
+ references) are unaffected:
660
+ ```
661
+ Article.order("title DESC")
662
+ ```
606
663
 
607
- *lulalala*
664
+ *Ben Toews*
608
665
 
609
- * ConnectionPool recognizes checkout_timeout spec key as taking
610
- precedence over legacy wait_timeout spec key, can be used to avoid
611
- conflict with mysql2 use of wait_timeout. Closes #7684.
666
+ * `update_all` will now pass its values to `Type#cast` before passing them to
667
+ `Type#serialize`. This means that `update_all(foo: 'true')` will properly
668
+ persist a boolean.
612
669
 
613
- *jrochkind*
670
+ *Sean Griffin*
614
671
 
615
- * Rename field_changed? to _field_changed? so that users can create a field named field
672
+ * Add new error class `StatementTimeout` which will be raised
673
+ when statement timeout exceeded.
616
674
 
617
- *Akira Matsuda*, backported by *Steve Klabnik*
675
+ *Ryuta Kamizono*
618
676
 
619
- * Fix creation of through association models when using `collection=[]`
620
- on a `has_many :through` association from an unsaved model.
621
- Fix #7661.
677
+ * Fix `bin/rails db:migrate` with specified `VERSION`.
678
+ `bin/rails db:migrate` with empty VERSION behaves as without `VERSION`.
679
+ Check a format of `VERSION`: Allow a migration version number
680
+ or name of a migration file. Raise error if format of `VERSION` is invalid.
681
+ Raise error if target migration doesn't exist.
622
682
 
623
- *Ernie Miller*
683
+ *bogdanvlviv*
624
684
 
625
- * Explain only normal CRUD sql (select / update / insert / delete).
626
- Fix problem that explains unexplainable sql. Closes #7544 #6458.
685
+ * Fixed a bug where column orders for an index weren't written to
686
+ `db/schema.rb` when using the sqlite adapter.
627
687
 
628
- *kennyj*
688
+ Fixes #30902.
629
689
 
630
- * Backport test coverage to ensure that PostgreSQL auto-reconnect functionality
631
- remains healthy.
690
+ *Paul Kuruvilla*
632
691
 
633
- *Steve Jorgensen*
692
+ * Remove deprecated method `#sanitize_conditions`.
634
693
 
635
- * Use config['encoding'] instead of config['charset'] when executing
636
- databases.rake in the mysql/mysql2. A correct option for a database.yml
637
- is 'encoding'.
694
+ *Rafael Mendonça França*
638
695
 
639
- *kennyj*
696
+ * Remove deprecated method `#scope_chain`.
640
697
 
641
- * Fix ConnectionAdapters::Column.type_cast_code integer conversion,
642
- to always convert values to integer calling #to_i. Fixes #7509.
698
+ *Rafael Mendonça França*
643
699
 
644
- *Thiago Pradi*
700
+ * Remove deprecated configuration `.error_on_ignored_order_or_limit`.
645
701
 
646
- * Fix time column type casting for invalid time string values to correctly return nil.
702
+ *Rafael Mendonça França*
647
703
 
648
- *Adam Meehan*
704
+ * Remove deprecated arguments from `#verify!`.
649
705
 
650
- * Fix `becomes` when using a configured `inheritance_column`.
706
+ *Rafael Mendonça França*
651
707
 
652
- *Yves Senn*
708
+ * Remove deprecated argument `name` from `#indexes`.
653
709
 
654
- * Fix `reset_counters` when there are multiple `belongs_to` association with the
655
- same foreign key and one of them have a counter cache.
656
- Fixes #5200.
710
+ *Rafael Mendonça França*
657
711
 
658
- *Dave Desrochers*
712
+ * Remove deprecated method `ActiveRecord::Migrator.schema_migrations_table_name`.
659
713
 
660
- * Round usec when comparing timestamp attributes in the dirty tracking.
661
- Fixes #6975.
714
+ *Rafael Mendonça França*
662
715
 
663
- *kennyj*
716
+ * Remove deprecated method `supports_primary_key?`.
664
717
 
665
- * Use inversed parent for first and last child of has_many association.
718
+ *Rafael Mendonça França*
666
719
 
667
- *Ravil Bayramgalin*
720
+ * Remove deprecated method `supports_migrations?`.
668
721
 
669
- * Fix Column.microseconds and Column.fast_string_to_date to avoid converting
670
- timestamp seconds to a float, since it occasionally results in inaccuracies
671
- with microsecond-precision times. Fixes #7352.
722
+ *Rafael Mendonça França*
723
+
724
+ * Remove deprecated methods `initialize_schema_migrations_table` and `initialize_internal_metadata_table`.
672
725
 
673
- *Ari Pollak*
726
+ *Rafael Mendonça França*
674
727
 
675
- * Fix `increment!`, `decrement!`, `toggle!` that was skipping callbacks.
676
- Fixes #7306.
728
+ * Raises when calling `lock!` in a dirty record.
677
729
 
678
730
  *Rafael Mendonça França*
679
731
 
680
- * Fix AR#create to return an unsaved record when AR::RecordInvalid is
681
- raised. Fixes #3217.
732
+ * Remove deprecated support to passing a class to `:class_name` on associations.
682
733
 
683
- *Dave Yeu*
734
+ *Rafael Mendonça França*
684
735
 
685
- * Remove unnecessary transaction when assigning has_one associations with a nil or equal value.
686
- Fix #7191.
736
+ * Remove deprecated argument `default` from `index_name_exists?`.
687
737
 
688
- *kennyj*
738
+ *Rafael Mendonça França*
689
739
 
690
- * Allow store to work with an empty column.
691
- Fix #4840.
740
+ * Remove deprecated support to `quoted_id` when typecasting an Active Record object.
692
741
 
693
- *Jeremy Walker*
742
+ *Rafael Mendonça França*
694
743
 
695
- * Remove prepared statement from system query in postgresql adapter.
696
- Fix #5872.
744
+ * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
745
+ ar_internal_metadata's data for a test database.
697
746
 
698
- *Ivan Evtuhovich*
747
+ Before:
748
+ ```
749
+ $ RAILS_ENV=test rails dbconsole
750
+ > SELECT * FROM ar_internal_metadata;
751
+ key|value|created_at|updated_at
752
+ environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
753
+ ```
699
754
 
700
- * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`
701
- Fixes #4772.
755
+ After:
756
+ ```
757
+ $ RAILS_ENV=test rails dbconsole
758
+ > SELECT * FROM ar_internal_metadata;
759
+ key|value|created_at|updated_at
760
+ environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
761
+ ```
702
762
 
703
- *Seamus Abshere*
763
+ Fixes #26731.
704
764
 
765
+ *bogdanvlviv*
705
766
 
706
- ## Rails 3.2.8 (Aug 9, 2012) ##
767
+ * Fix longer sequence name detection for serial columns.
707
768
 
708
- * Do not consider the numeric attribute as changed if the old value is zero and the new value
709
- is not a string.
710
- Fixes #7237.
769
+ Fixes #28332.
711
770
 
712
- *Rafael Mendonça França*
771
+ *Ryuta Kamizono*
713
772
 
714
- * Removes the deprecation of `update_attribute`. *fxn*
773
+ * MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`.
715
774
 
716
- * Reverted the deprecation of `composed_of`. *Rafael Mendonça França*
775
+ Fixes #30894.
717
776
 
718
- * Reverted the deprecation of `*_sql` association options. They will
719
- be deprecated in 4.0 instead. *Jon Leighton*
777
+ *Ryuta Kamizono*
720
778
 
721
- * Do not eager load AR session store. ActiveRecord::SessionStore depends on the abstract store
722
- in Action Pack. Eager loading this class would break client code that eager loads Active Record
723
- standalone.
724
- Fixes #7160
779
+ * Fix `COUNT(DISTINCT ...)` for `GROUP BY` with `ORDER BY` and `LIMIT`.
725
780
 
726
- *Xavier Noria*
781
+ Fixes #30886.
727
782
 
728
- * Do not set RAILS_ENV to "development" when using `db:test:prepare` and related rake tasks.
729
- This was causing the truncation of the development database data when using RSpec.
730
- Fixes #7175.
783
+ *Ryuta Kamizono*
731
784
 
732
- *Rafael Mendonça França*
785
+ * PostgreSQL `tsrange` now preserves subsecond precision.
733
786
 
734
- ## Rails 3.2.7 (Jul 26, 2012) ##
787
+ PostgreSQL 9.1+ introduced range types, and Rails added support for using
788
+ this datatype in Active Record. However, the serialization of
789
+ `PostgreSQL::OID::Range` was incomplete, because it did not properly
790
+ cast the bounds that make up the range. This led to subseconds being
791
+ dropped in SQL commands:
735
792
 
736
- * `:finder_sql` and `:counter_sql` options on collection associations
737
- are deprecated. Please transition to using scopes.
793
+ Before:
738
794
 
739
- *Jon Leighton*
795
+ connection.type_cast(tsrange.serialize(range_value))
796
+ # => "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
740
797
 
741
- * `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
742
- associations are deprecated. Please transition to using `has_many
743
- :through`
798
+ Now:
744
799
 
745
- *Jon Leighton*
800
+ connection.type_cast(tsrange.serialize(range_value))
801
+ # => "[2010-01-01 13:30:00.670277,2011-02-02 19:30:00.745125)"
746
802
 
747
- * `composed_of` has been deprecated. You'll have to write your own accessor
748
- and mutator methods if you'd like to use value objects to represent some
749
- portion of your models.
803
+ *Thomas Cannon*
750
804
 
751
- *Steve Klabnik*
805
+ * Passing a `Set` to `Relation#where` now behaves the same as passing an
806
+ array.
752
807
 
753
- * `update_attribute` has been deprecated. Use `update_column` if
754
- you want to bypass mass-assignment protection, validations, callbacks,
755
- and touching of updated_at. Otherwise please use `update_attributes`.
808
+ *Sean Griffin*
756
809
 
757
- *Steve Klabnik*
810
+ * Use given algorithm while removing index from database.
758
811
 
759
- ## Rails 3.2.6 (Jun 12, 2012) ##
812
+ Fixes #24190.
760
813
 
761
- * protect against the nesting of hashes changing the
762
- table context in the next call to build_from_hash. This fix
763
- covers this case as well.
814
+ *Mehmet Emin İNAÇ*
764
815
 
765
- CVE-2012-2695
816
+ * Update payload names for `sql.active_record` instrumentation to be
817
+ more descriptive.
766
818
 
767
- * Revert earlier 'perf fix' (see 3.2.4 changelog / GH #6289). This
768
- change introduced a regression (GH #6609). assoc.clear and
769
- assoc.delete_all have loaded the association before doing the delete
770
- since at least Rails 2.3. Doing the delete without loading the
771
- records means that the `before_remove` and `after_remove` callbacks do
772
- not get invoked. Therefore, this change was less a fix a more an
773
- optimisation, which should only have gone into master.
819
+ Fixes #30586.
774
820
 
775
- *Jon Leighton*
821
+ *Jeremy Green*
776
822
 
777
- ## Rails 3.2.5 (Jun 1, 2012) ##
823
+ * Add new error class `LockWaitTimeout` which will be raised
824
+ when lock wait timeout exceeded.
778
825
 
779
- * Restore behavior of Active Record 3.2.3 scopes.
780
- A series of commits relating to preloading and scopes caused a regression.
826
+ *Gabriel Courtemanche*
781
827
 
782
- *Andrew White*
828
+ * Remove deprecated `#migration_keys`.
783
829
 
830
+ *Ryuta Kamizono*
784
831
 
785
- ## Rails 3.2.4 (May 31, 2012) ##
832
+ * Automatically guess the inverse associations for STI.
786
833
 
787
- * Perf fix: Don't load the records when doing assoc.delete_all.
788
- GH #6289. *Jon Leighton*
834
+ *Yuichiro Kaneko*
789
835
 
790
- * Association preloading shouldn't be affected by the current scoping.
791
- This could cause infinite recursion and potentially other problems.
792
- See GH #5667. *Jon Leighton*
836
+ * Ensure `sum` honors `distinct` on `has_many :through` associations.
793
837
 
794
- * Datetime attributes are forced to be changed. GH #3965
838
+ Fixes #16791.
795
839
 
796
- * Fix attribute casting. GH #5549
840
+ *Aaron Wortham*
797
841
 
798
- * Fix #5667. Preloading should ignore scoping.
842
+ * Add `binary` fixture helper method.
799
843
 
800
- * Predicate builder should not recurse for determining where columns.
801
- Thanks to Ben Murphy for reporting this! CVE-2012-2661
844
+ *Atsushi Yoshida*
802
845
 
846
+ * When using `Relation#or`, extract the common conditions and put them before the OR condition.
803
847
 
804
- ## Rails 3.2.3 (March 30, 2012) ##
848
+ *Maxime Handfield Lapointe*
805
849
 
806
- * Added find_or_create_by_{attribute}! dynamic method. *Andrew White*
850
+ * `Relation#or` now accepts two relations who have different values for
851
+ `references` only, as `references` can be implicitly called by `where`.
807
852
 
808
- * Whitelist all attribute assignment by default. Change the default for newly generated applications to whitelist all attribute assignment. Also update the generated model classes so users are reminded of the importance of attr_accessible. *NZKoz*
853
+ Fixes #29411.
809
854
 
810
- * Update ActiveRecord::AttributeMethods#attribute_present? to return false for empty strings. *Jacobkg*
855
+ *Sean Griffin*
811
856
 
812
- * Fix associations when using per class databases. *larskanis*
857
+ * `ApplicationRecord` is no longer generated when generating models. If you
858
+ need to generate it, it can be created with `rails g application_record`.
813
859
 
814
- * Revert setting NOT NULL constraints in add_timestamps *fxn*
860
+ *Lisa Ugray*
815
861
 
816
- * Fix mysql to use proper text types. Fixes #3931. *kennyj*
862
+ * Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT` to keep the existing select list.
817
863
 
818
- * Fix #5069 - Protect foreign key from mass assignment through association builder. *byroot*
864
+ *Ryuta Kamizono*
819
865
 
866
+ * When a `has_one` association is destroyed by `dependent: destroy`,
867
+ `destroyed_by_association` will now be set to the reflection, matching the
868
+ behaviour of `has_many` associations.
820
869
 
821
- ## Rails 3.2.2 (March 1, 2012) ##
870
+ *Lisa Ugray*
822
871
 
823
- * No changes.
872
+ * Fix `unscoped(where: [columns])` removing the wrong bind values.
824
873
 
874
+ When the `where` is called on a relation after a `or`, unscoping the column of that later `where` removed
875
+ bind values used by the `or` instead. (possibly other cases too)
825
876
 
826
- ## Rails 3.2.1 (January 26, 2012) ##
877
+ ```
878
+ Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).to_sql
879
+ # Currently:
880
+ # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 2 OR "posts"."id" = 3)
881
+ # With fix:
882
+ # SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1 OR "posts"."id" = 2)
883
+ ```
827
884
 
828
- * The threshold for auto EXPLAIN is ignored if there's no logger. *fxn*
885
+ *Maxime Handfield Lapointe*
829
886
 
830
- * Call `to_s` on the value passed to `table_name=`, in particular symbols
831
- are supported (regression). *Sergey Nartimov*
887
+ * Values constructed using multi-parameter assignment will now use the
888
+ post-type-cast value for rendering in single-field form inputs.
832
889
 
833
- * Fix possible race condition when two threads try to define attribute
834
- methods for the same class. *Jon Leighton*
890
+ *Sean Griffin*
835
891
 
892
+ * `Relation#joins` is no longer affected by the target model's
893
+ `current_scope`, with the exception of `unscoped`.
836
894
 
837
- ## Rails 3.2.0 (January 20, 2012) ##
895
+ Fixes #29338.
838
896
 
839
- * Added a `with_lock` method to ActiveRecord objects, which starts
840
- a transaction, locks the object (pessimistically) and yields to the block.
841
- The method takes one (optional) parameter and passes it to `lock!`.
897
+ *Sean Griffin*
842
898
 
843
- Before:
899
+ * Change sqlite3 boolean serialization to use 1 and 0.
844
900
 
845
- class Order < ActiveRecord::Base
846
- def cancel!
847
- transaction do
848
- lock!
849
- # ... cancelling logic
850
- end
851
- end
852
- end
901
+ SQLite natively recognizes 1 and 0 as true and false, but does not natively
902
+ recognize 't' and 'f' as was previously serialized.
853
903
 
854
- After:
904
+ This change in serialization requires a migration of stored boolean data
905
+ for SQLite databases, so it's implemented behind a configuration flag
906
+ whose default false value is deprecated.
855
907
 
856
- class Order < ActiveRecord::Base
857
- def cancel!
858
- with_lock do
859
- # ... cancelling logic
860
- end
861
- end
862
- end
908
+ *Lisa Ugray*
863
909
 
864
- *Olek Janiszewski*
910
+ * Skip query caching when working with batches of records (`find_each`, `find_in_batches`,
911
+ `in_batches`).
865
912
 
866
- * 'on' and 'ON' boolean columns values are type casted to true
867
- *Santiago Pastorino*
913
+ Previously, records would be fetched in batches, but all records would be retained in memory
914
+ until the end of the request or job.
868
915
 
869
- * Added ability to run migrations only for given scope, which allows
870
- to run migrations only from one engine (for example to revert changes
871
- from engine that you want to remove).
916
+ *Eugene Kenny*
872
917
 
873
- Example:
874
- rake db:migrate SCOPE=blog
918
+ * Prevent errors raised by `sql.active_record` notification subscribers from being converted into
919
+ `ActiveRecord::StatementInvalid` exceptions.
875
920
 
876
- *Piotr Sarnacki*
921
+ *Dennis Taylor*
877
922
 
878
- * Migrations copied from engines are now scoped with engine's name,
879
- for example 01_create_posts.blog.rb. *Piotr Sarnacki*
923
+ * Fix eager loading/preloading association with scope including joins.
880
924
 
881
- * Implements `AR::Base.silence_auto_explain`. This method allows the user to
882
- selectively disable automatic EXPLAINs within a block. *fxn*
925
+ Fixes #28324.
883
926
 
884
- * Implements automatic EXPLAIN logging for slow queries.
927
+ *Ryuta Kamizono*
885
928
 
886
- A new configuration parameter `config.active_record.auto_explain_threshold_in_seconds`
887
- determines what's to be considered a slow query. Setting that to `nil` disables
888
- this feature. Defaults are 0.5 in development mode, and `nil` in test and production
889
- modes.
929
+ * Fix transactions to apply state to child transactions.
890
930
 
891
- As of this writing there's support for SQLite, MySQL (mysql2 adapter), and
892
- PostgreSQL.
931
+ Previously, if you had a nested transaction and the outer transaction was rolledback, the record from the
932
+ inner transaction would still be marked as persisted.
893
933
 
894
- *fxn*
934
+ This change fixes that by applying the state of the parent transaction to the child transaction when the
935
+ parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
895
936
 
896
- * Implemented ActiveRecord::Relation#pluck method
937
+ *Eileen M. Uchitelle*, *Aaron Patterson*
897
938
 
898
- Method returns Array of column value from table under ActiveRecord model
939
+ * Deprecate `set_state` method in `TransactionState`.
899
940
 
900
- Client.pluck(:id)
941
+ Deprecated the `set_state` method in favor of setting the state via specific methods. If you need to mark the
942
+ state of the transaction you can now use `rollback!`, `commit!` or `nullify!` instead of
943
+ `set_state(:rolledback)`, `set_state(:committed)`, or `set_state(nil)`.
901
944
 
902
- *Bogdan Gusiev*
945
+ *Eileen M. Uchitelle*, *Aaron Patterson*
903
946
 
904
- * Automatic closure of connections in threads is deprecated. For example
905
- the following code is deprecated:
947
+ * Deprecate delegating to `arel` in `Relation`.
906
948
 
907
- Thread.new { Post.find(1) }.join
949
+ *Ryuta Kamizono*
908
950
 
909
- It should be changed to close the database connection at the end of
910
- the thread:
951
+ * Query cache was unavailable when entering the `ActiveRecord::Base.cache` block
952
+ without being connected.
911
953
 
912
- Thread.new {
913
- Post.find(1)
914
- Post.connection.close
915
- }.join
954
+ *Tsukasa Oishi*
916
955
 
917
- Only people who spawn threads in their application code need to worry
918
- about this change.
956
+ * Previously, when building records using a `has_many :through` association,
957
+ if the child records were deleted before the parent was saved, they would
958
+ still be persisted. Now, if child records are deleted before the parent is saved
959
+ on a `has_many :through` association, the child records will not be persisted.
919
960
 
920
- * Deprecated:
961
+ *Tobias Kraze*
921
962
 
922
- * `set_table_name`
923
- * `set_inheritance_column`
924
- * `set_sequence_name`
925
- * `set_primary_key`
926
- * `set_locking_column`
963
+ * Merging two relations representing nested joins no longer transforms the joins of
964
+ the merged relation into LEFT OUTER JOIN.
927
965
 
928
- Use an assignment method instead. For example, instead of `set_table_name`, use `self.table_name=`:
966
+ Example:
929
967
 
930
- class Project < ActiveRecord::Base
931
- self.table_name = "project"
932
- end
968
+ ```
969
+ Author.joins(:posts).merge(Post.joins(:comments))
970
+ # Before the change:
971
+ #=> SELECT ... FROM authors INNER JOIN posts ON ... LEFT OUTER JOIN comments ON...
933
972
 
934
- Or define your own `self.table_name` method:
973
+ # After the change:
974
+ #=> SELECT ... FROM authors INNER JOIN posts ON ... INNER JOIN comments ON...
975
+ ```
935
976
 
936
- class Post < ActiveRecord::Base
937
- def self.table_name
938
- "special_" + super
939
- end
940
- end
941
- Post.table_name # => "special_posts"
977
+ *Maxime Handfield Lapointe*
942
978
 
943
- *Jon Leighton*
979
+ * `ActiveRecord::Persistence#touch` does not work well when optimistic locking enabled and
980
+ `locking_column`, without default value, is null in the database.
944
981
 
945
- * Generated association methods are created within a separate module to allow overriding and
946
- composition using `super`. For a class named `MyModel`, the module is named
947
- `MyModel::GeneratedFeatureMethods`. It is included into the model class immediately after
948
- the `generated_attributes_methods` module defined in ActiveModel, so association methods
949
- override attribute methods of the same name. *Josh Susser*
982
+ *bogdanvlviv*
950
983
 
951
- * Implemented ActiveRecord::Relation#explain. *fxn*
984
+ * Fix destroying existing object does not work well when optimistic locking enabled and
985
+ `locking_column` is null in the database.
952
986
 
953
- * Add ActiveRecord::Relation#uniq for generating unique queries.
987
+ *bogdanvlviv*
954
988
 
955
- Before:
989
+ * Use bulk INSERT to insert fixtures for better performance.
956
990
 
957
- Client.select('DISTINCT name')
991
+ *Kir Shatrov*
958
992
 
959
- After:
993
+ * Prevent creation of bind param if casted value is nil.
960
994
 
961
- Client.select(:name).uniq
995
+ *Ryuta Kamizono*
962
996
 
963
- This also allows you to revert the unqueness in a relation:
997
+ * Deprecate passing arguments and block at the same time to `count` and `sum` in `ActiveRecord::Calculations`.
964
998
 
965
- Client.select(:name).uniq.uniq(false)
999
+ *Ryuta Kamizono*
966
1000
 
967
- *Jon Leighton*
1001
+ * Loading model schema from database is now thread-safe.
968
1002
 
969
- * Support index sort order in sqlite, mysql and postgres adapters. *Vlad Jebelev*
1003
+ Fixes #28589.
970
1004
 
971
- * Allow the :class_name option for associations to take a symbol (:Client) in addition to
972
- a string ('Client').
1005
+ *Vikrant Chaudhary*, *David Abdemoulaie*
973
1006
 
974
- This is to avoid confusing newbies, and to be consistent with the fact that other options
975
- like :foreign_key already allow a symbol or a string.
1007
+ * Add `ActiveRecord::Base#cache_version` to support recyclable cache keys via the new versioned entries
1008
+ in `ActiveSupport::Cache`. This also means that `ActiveRecord::Base#cache_key` will now return a stable key
1009
+ that does not include a timestamp any more.
976
1010
 
977
- *Jon Leighton*
1011
+ NOTE: This feature is turned off by default, and `#cache_key` will still return cache keys with timestamps
1012
+ until you set `ActiveRecord::Base.cache_versioning = true`. That's the setting for all new apps on Rails 5.2+
978
1013
 
979
- * In development mode the db:drop task also drops the test database. For symmetry with
980
- the db:create task. *Dmitriy Kiriyenko*
1014
+ *DHH*
981
1015
 
982
- * Added ActiveRecord::Base.store for declaring simple single-column key/value stores *DHH*
1016
+ * Respect `SchemaDumper.ignore_tables` in rake tasks for databases structure dump.
983
1017
 
984
- class User < ActiveRecord::Base
985
- store :settings, accessors: [ :color, :homepage ]
986
- end
1018
+ *Rusty Geldmacher*, *Guillermo Iguaran*
987
1019
 
988
- u = User.new(color: 'black', homepage: '37signals.com')
989
- u.color # Accessor stored attribute
990
- u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor
1020
+ * Add type caster to `RuntimeReflection#alias_name`.
991
1021
 
1022
+ Fixes #28959.
992
1023
 
993
- * MySQL: case-insensitive uniqueness validation avoids calling LOWER when
994
- the column already uses a case-insensitive collation. Fixes #561.
1024
+ *Jon Moss*
995
1025
 
996
- *Joseph Palermo*
1026
+ * Deprecate `supports_statement_cache?`.
997
1027
 
998
- * Transactional fixtures enlist all active database connections. You can test
999
- models on different connections without disabling transactional fixtures.
1028
+ *Ryuta Kamizono*
1000
1029
 
1001
- *Jeremy Kemper*
1030
+ * Raise error `UnknownMigrationVersionError` on the movement of migrations
1031
+ when the current migration does not exist.
1002
1032
 
1003
- * Add first_or_create, first_or_create!, first_or_initialize methods to Active Record. This is a
1004
- better approach over the old find_or_create_by dynamic methods because it's clearer which
1005
- arguments are used to find the record and which are used to create it:
1033
+ *bogdanvlviv*
1006
1034
 
1007
- User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson")
1035
+ * Fix `bin/rails db:forward` first migration.
1008
1036
 
1009
- *Andrés Mejía*
1037
+ *bogdanvlviv*
1010
1038
 
1011
- * Fix nested attributes bug where _destroy parameter is taken into account
1012
- during :reject_if => :all_blank (fixes #2937)
1039
+ * Support Descending Indexes for MySQL.
1013
1040
 
1014
- *Aaron Christy*
1041
+ MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored.
1042
+ See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
1015
1043
 
1016
- * Add ActiveSupport::Cache::NullStore for use in development and testing.
1044
+ *Ryuta Kamizono*
1045
+
1046
+ * Fix inconsistency with changed attributes when overriding Active Record attribute reader.
1047
+
1048
+ *bogdanvlviv*
1049
+
1050
+ * When calling the dynamic fixture accessor method with no arguments, it now returns all fixtures of this type.
1051
+ Previously this method always returned an empty array.
1052
+
1053
+ *Kevin McPhillips*
1017
1054
 
1018
- *Brian Durand*
1019
1055
 
1020
- Please check [3-1-stable](https://github.com/rails/rails/blob/3-1-stable/activerecord/CHANGELOG.md) for previous changes.
1056
+ Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activerecord/CHANGELOG.md) for previous changes.