activerecord 5.0.7.2 → 6.0.6.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 (359) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +844 -1944
  3. data/MIT-LICENSE +3 -1
  4. data/README.rdoc +9 -7
  5. data/examples/performance.rb +31 -29
  6. data/examples/simple.rb +5 -3
  7. data/lib/active_record/advisory_lock_base.rb +18 -0
  8. data/lib/active_record/aggregations.rb +249 -247
  9. data/lib/active_record/association_relation.rb +18 -14
  10. data/lib/active_record/associations/alias_tracker.rb +24 -34
  11. data/lib/active_record/associations/association.rb +113 -55
  12. data/lib/active_record/associations/association_scope.rb +102 -96
  13. data/lib/active_record/associations/belongs_to_association.rb +58 -42
  14. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -12
  15. data/lib/active_record/associations/builder/association.rb +18 -25
  16. data/lib/active_record/associations/builder/belongs_to.rb +43 -54
  17. data/lib/active_record/associations/builder/collection_association.rb +7 -18
  18. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +41 -62
  19. data/lib/active_record/associations/builder/has_many.rb +4 -0
  20. data/lib/active_record/associations/builder/has_one.rb +37 -1
  21. data/lib/active_record/associations/builder/singular_association.rb +4 -0
  22. data/lib/active_record/associations/collection_association.rb +93 -254
  23. data/lib/active_record/associations/collection_proxy.rb +159 -122
  24. data/lib/active_record/associations/foreign_association.rb +9 -0
  25. data/lib/active_record/associations/has_many_association.rb +23 -30
  26. data/lib/active_record/associations/has_many_through_association.rb +58 -44
  27. data/lib/active_record/associations/has_one_association.rb +59 -54
  28. data/lib/active_record/associations/has_one_through_association.rb +20 -11
  29. data/lib/active_record/associations/join_dependency/join_association.rb +43 -85
  30. data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
  31. data/lib/active_record/associations/join_dependency/join_part.rb +14 -14
  32. data/lib/active_record/associations/join_dependency.rb +152 -177
  33. data/lib/active_record/associations/preloader/association.rb +101 -97
  34. data/lib/active_record/associations/preloader/through_association.rb +77 -76
  35. data/lib/active_record/associations/preloader.rb +94 -103
  36. data/lib/active_record/associations/singular_association.rb +12 -45
  37. data/lib/active_record/associations/through_association.rb +27 -15
  38. data/lib/active_record/associations.rb +1603 -1592
  39. data/lib/active_record/attribute_assignment.rb +54 -61
  40. data/lib/active_record/attribute_decorators.rb +38 -17
  41. data/lib/active_record/attribute_methods/before_type_cast.rb +12 -8
  42. data/lib/active_record/attribute_methods/dirty.rb +179 -109
  43. data/lib/active_record/attribute_methods/primary_key.rb +85 -92
  44. data/lib/active_record/attribute_methods/query.rb +4 -3
  45. data/lib/active_record/attribute_methods/read.rb +20 -49
  46. data/lib/active_record/attribute_methods/serialization.rb +29 -7
  47. data/lib/active_record/attribute_methods/time_zone_conversion.rb +39 -66
  48. data/lib/active_record/attribute_methods/write.rb +34 -33
  49. data/lib/active_record/attribute_methods.rb +66 -106
  50. data/lib/active_record/attributes.rb +38 -25
  51. data/lib/active_record/autosave_association.rb +58 -39
  52. data/lib/active_record/base.rb +27 -24
  53. data/lib/active_record/callbacks.rb +64 -35
  54. data/lib/active_record/coders/json.rb +2 -0
  55. data/lib/active_record/coders/yaml_column.rb +34 -13
  56. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +558 -323
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +23 -5
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +215 -94
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +59 -35
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +128 -75
  61. data/lib/active_record/connection_adapters/abstract/savepoints.rb +2 -0
  62. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +33 -28
  63. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +233 -147
  64. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +68 -80
  65. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +400 -213
  66. data/lib/active_record/connection_adapters/abstract/transaction.rb +169 -79
  67. data/lib/active_record/connection_adapters/abstract_adapter.rb +373 -202
  68. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +401 -562
  69. data/lib/active_record/connection_adapters/column.rb +41 -13
  70. data/lib/active_record/connection_adapters/connection_specification.rb +172 -139
  71. data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +11 -4
  72. data/lib/active_record/connection_adapters/mysql/column.rb +8 -31
  73. data/lib/active_record/connection_adapters/mysql/database_statements.rb +137 -49
  74. data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +24 -23
  75. data/lib/active_record/connection_adapters/mysql/quoting.rb +50 -20
  76. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +49 -45
  77. data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +58 -56
  78. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +70 -36
  79. data/lib/active_record/connection_adapters/mysql/schema_statements.rb +268 -0
  80. data/lib/active_record/connection_adapters/mysql/type_metadata.rb +12 -13
  81. data/lib/active_record/connection_adapters/mysql2_adapter.rb +48 -30
  82. data/lib/active_record/connection_adapters/postgresql/column.rb +19 -31
  83. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +64 -54
  84. data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +5 -3
  85. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +22 -11
  86. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +6 -5
  87. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
  88. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +2 -0
  89. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -1
  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 +12 -2
  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 -4
  94. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +19 -18
  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 +44 -0
  98. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -5
  99. data/lib/active_record/connection_adapters/postgresql/oid/{json.rb → oid.rb} +6 -1
  100. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +30 -9
  101. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +52 -30
  102. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -1
  103. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +58 -54
  104. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +8 -4
  105. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +2 -0
  106. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +2 -0
  107. data/lib/active_record/connection_adapters/postgresql/oid.rb +24 -21
  108. data/lib/active_record/connection_adapters/postgresql/quoting.rb +95 -35
  109. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +20 -26
  110. data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +76 -0
  111. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +147 -105
  112. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +34 -32
  113. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +378 -308
  114. data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +26 -25
  115. data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -6
  116. data/lib/active_record/connection_adapters/postgresql_adapter.rb +383 -275
  117. data/lib/active_record/connection_adapters/schema_cache.rb +46 -12
  118. data/lib/active_record/connection_adapters/sql_type_metadata.rb +13 -8
  119. data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +119 -0
  120. data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +3 -1
  121. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +72 -18
  122. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +3 -8
  123. data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
  124. data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
  125. data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +137 -0
  126. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +261 -267
  127. data/lib/active_record/connection_adapters/statement_pool.rb +9 -8
  128. data/lib/active_record/connection_handling.rb +143 -40
  129. data/lib/active_record/core.rb +207 -160
  130. data/lib/active_record/counter_cache.rb +60 -28
  131. data/lib/active_record/database_configurations/database_config.rb +37 -0
  132. data/lib/active_record/database_configurations/hash_config.rb +50 -0
  133. data/lib/active_record/database_configurations/url_config.rb +78 -0
  134. data/lib/active_record/database_configurations.rb +233 -0
  135. data/lib/active_record/define_callbacks.rb +22 -0
  136. data/lib/active_record/dynamic_matchers.rb +87 -87
  137. data/lib/active_record/enum.rb +67 -23
  138. data/lib/active_record/errors.rb +114 -18
  139. data/lib/active_record/explain.rb +4 -4
  140. data/lib/active_record/explain_registry.rb +3 -1
  141. data/lib/active_record/explain_subscriber.rb +9 -4
  142. data/lib/active_record/fixture_set/file.rb +13 -8
  143. data/lib/active_record/fixture_set/model_metadata.rb +33 -0
  144. data/lib/active_record/fixture_set/render_context.rb +17 -0
  145. data/lib/active_record/fixture_set/table_row.rb +152 -0
  146. data/lib/active_record/fixture_set/table_rows.rb +46 -0
  147. data/lib/active_record/fixtures.rb +194 -504
  148. data/lib/active_record/gem_version.rb +5 -3
  149. data/lib/active_record/inheritance.rb +150 -99
  150. data/lib/active_record/insert_all.rb +179 -0
  151. data/lib/active_record/integration.rb +116 -25
  152. data/lib/active_record/internal_metadata.rb +16 -19
  153. data/lib/active_record/legacy_yaml_adapter.rb +4 -2
  154. data/lib/active_record/locking/optimistic.rb +85 -86
  155. data/lib/active_record/locking/pessimistic.rb +18 -6
  156. data/lib/active_record/log_subscriber.rb +48 -29
  157. data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
  158. data/lib/active_record/middleware/database_selector/resolver.rb +87 -0
  159. data/lib/active_record/middleware/database_selector.rb +74 -0
  160. data/lib/active_record/migration/command_recorder.rb +134 -100
  161. data/lib/active_record/migration/compatibility.rb +174 -56
  162. data/lib/active_record/migration/join_table.rb +8 -7
  163. data/lib/active_record/migration.rb +369 -302
  164. data/lib/active_record/model_schema.rb +160 -127
  165. data/lib/active_record/nested_attributes.rb +213 -202
  166. data/lib/active_record/no_touching.rb +12 -3
  167. data/lib/active_record/null_relation.rb +12 -34
  168. data/lib/active_record/persistence.rb +446 -77
  169. data/lib/active_record/query_cache.rb +13 -12
  170. data/lib/active_record/querying.rb +37 -24
  171. data/lib/active_record/railtie.rb +128 -36
  172. data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
  173. data/lib/active_record/railties/console_sandbox.rb +2 -0
  174. data/lib/active_record/railties/controller_runtime.rb +34 -33
  175. data/lib/active_record/railties/databases.rake +312 -177
  176. data/lib/active_record/readonly_attributes.rb +5 -4
  177. data/lib/active_record/reflection.rb +214 -254
  178. data/lib/active_record/relation/batches/batch_enumerator.rb +3 -1
  179. data/lib/active_record/relation/batches.rb +98 -52
  180. data/lib/active_record/relation/calculations.rb +212 -173
  181. data/lib/active_record/relation/delegation.rb +73 -69
  182. data/lib/active_record/relation/finder_methods.rb +207 -247
  183. data/lib/active_record/relation/from_clause.rb +6 -8
  184. data/lib/active_record/relation/merger.rb +82 -61
  185. data/lib/active_record/relation/predicate_builder/array_handler.rb +20 -14
  186. data/lib/active_record/relation/predicate_builder/association_query_value.rb +43 -0
  187. data/lib/active_record/relation/predicate_builder/base_handler.rb +4 -3
  188. data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +6 -4
  189. data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +53 -0
  190. data/lib/active_record/relation/predicate_builder/range_handler.rb +7 -18
  191. data/lib/active_record/relation/predicate_builder/relation_handler.rb +6 -0
  192. data/lib/active_record/relation/predicate_builder.rb +83 -105
  193. data/lib/active_record/relation/query_attribute.rb +33 -2
  194. data/lib/active_record/relation/query_methods.rb +488 -332
  195. data/lib/active_record/relation/record_fetch_warning.rb +5 -3
  196. data/lib/active_record/relation/spawn_methods.rb +8 -8
  197. data/lib/active_record/relation/where_clause.rb +111 -96
  198. data/lib/active_record/relation/where_clause_factory.rb +6 -11
  199. data/lib/active_record/relation.rb +443 -318
  200. data/lib/active_record/result.rb +69 -40
  201. data/lib/active_record/runtime_registry.rb +5 -3
  202. data/lib/active_record/sanitization.rb +83 -99
  203. data/lib/active_record/schema.rb +7 -14
  204. data/lib/active_record/schema_dumper.rb +71 -69
  205. data/lib/active_record/schema_migration.rb +16 -6
  206. data/lib/active_record/scoping/default.rb +92 -95
  207. data/lib/active_record/scoping/named.rb +51 -26
  208. data/lib/active_record/scoping.rb +20 -20
  209. data/lib/active_record/secure_token.rb +4 -2
  210. data/lib/active_record/serialization.rb +2 -0
  211. data/lib/active_record/statement_cache.rb +63 -28
  212. data/lib/active_record/store.rb +121 -41
  213. data/lib/active_record/suppressor.rb +6 -3
  214. data/lib/active_record/table_metadata.rb +39 -18
  215. data/lib/active_record/tasks/database_tasks.rb +271 -81
  216. data/lib/active_record/tasks/mysql_database_tasks.rb +54 -91
  217. data/lib/active_record/tasks/postgresql_database_tasks.rb +77 -47
  218. data/lib/active_record/tasks/sqlite_database_tasks.rb +33 -16
  219. data/lib/active_record/test_databases.rb +23 -0
  220. data/lib/active_record/test_fixtures.rb +243 -0
  221. data/lib/active_record/timestamp.rb +70 -36
  222. data/lib/active_record/touch_later.rb +8 -6
  223. data/lib/active_record/transactions.rb +141 -157
  224. data/lib/active_record/translation.rb +3 -1
  225. data/lib/active_record/type/adapter_specific_registry.rb +44 -48
  226. data/lib/active_record/type/date.rb +2 -0
  227. data/lib/active_record/type/date_time.rb +2 -0
  228. data/lib/active_record/type/decimal_without_scale.rb +15 -0
  229. data/lib/active_record/type/hash_lookup_type_map.rb +5 -4
  230. data/lib/active_record/type/internal/timezone.rb +2 -0
  231. data/lib/active_record/type/json.rb +30 -0
  232. data/lib/active_record/type/serialized.rb +16 -9
  233. data/lib/active_record/type/text.rb +11 -0
  234. data/lib/active_record/type/time.rb +12 -1
  235. data/lib/active_record/type/type_map.rb +14 -17
  236. data/lib/active_record/type/unsigned_integer.rb +16 -0
  237. data/lib/active_record/type.rb +23 -18
  238. data/lib/active_record/type_caster/connection.rb +17 -12
  239. data/lib/active_record/type_caster/map.rb +5 -4
  240. data/lib/active_record/type_caster.rb +4 -2
  241. data/lib/active_record/validations/absence.rb +2 -0
  242. data/lib/active_record/validations/associated.rb +3 -2
  243. data/lib/active_record/validations/length.rb +2 -0
  244. data/lib/active_record/validations/presence.rb +4 -2
  245. data/lib/active_record/validations/uniqueness.rb +29 -42
  246. data/lib/active_record/validations.rb +7 -5
  247. data/lib/active_record/version.rb +3 -1
  248. data/lib/active_record.rb +37 -22
  249. data/lib/arel/alias_predication.rb +9 -0
  250. data/lib/arel/attributes/attribute.rb +37 -0
  251. data/lib/arel/attributes.rb +22 -0
  252. data/lib/arel/collectors/bind.rb +24 -0
  253. data/lib/arel/collectors/composite.rb +31 -0
  254. data/lib/arel/collectors/plain_string.rb +20 -0
  255. data/lib/arel/collectors/sql_string.rb +20 -0
  256. data/lib/arel/collectors/substitute_binds.rb +28 -0
  257. data/lib/arel/crud.rb +42 -0
  258. data/lib/arel/delete_manager.rb +18 -0
  259. data/lib/arel/errors.rb +9 -0
  260. data/lib/arel/expressions.rb +29 -0
  261. data/lib/arel/factory_methods.rb +49 -0
  262. data/lib/arel/insert_manager.rb +49 -0
  263. data/lib/arel/math.rb +45 -0
  264. data/lib/arel/nodes/and.rb +32 -0
  265. data/lib/arel/nodes/ascending.rb +23 -0
  266. data/lib/arel/nodes/binary.rb +52 -0
  267. data/lib/arel/nodes/bind_param.rb +36 -0
  268. data/lib/arel/nodes/case.rb +55 -0
  269. data/lib/arel/nodes/casted.rb +50 -0
  270. data/lib/arel/nodes/comment.rb +29 -0
  271. data/lib/arel/nodes/count.rb +12 -0
  272. data/lib/arel/nodes/delete_statement.rb +45 -0
  273. data/lib/arel/nodes/descending.rb +23 -0
  274. data/lib/arel/nodes/equality.rb +18 -0
  275. data/lib/arel/nodes/extract.rb +24 -0
  276. data/lib/arel/nodes/false.rb +16 -0
  277. data/lib/arel/nodes/full_outer_join.rb +8 -0
  278. data/lib/arel/nodes/function.rb +44 -0
  279. data/lib/arel/nodes/grouping.rb +8 -0
  280. data/lib/arel/nodes/in.rb +8 -0
  281. data/lib/arel/nodes/infix_operation.rb +80 -0
  282. data/lib/arel/nodes/inner_join.rb +8 -0
  283. data/lib/arel/nodes/insert_statement.rb +37 -0
  284. data/lib/arel/nodes/join_source.rb +20 -0
  285. data/lib/arel/nodes/matches.rb +18 -0
  286. data/lib/arel/nodes/named_function.rb +23 -0
  287. data/lib/arel/nodes/node.rb +50 -0
  288. data/lib/arel/nodes/node_expression.rb +13 -0
  289. data/lib/arel/nodes/outer_join.rb +8 -0
  290. data/lib/arel/nodes/over.rb +15 -0
  291. data/lib/arel/nodes/regexp.rb +16 -0
  292. data/lib/arel/nodes/right_outer_join.rb +8 -0
  293. data/lib/arel/nodes/select_core.rb +67 -0
  294. data/lib/arel/nodes/select_statement.rb +41 -0
  295. data/lib/arel/nodes/sql_literal.rb +16 -0
  296. data/lib/arel/nodes/string_join.rb +11 -0
  297. data/lib/arel/nodes/table_alias.rb +27 -0
  298. data/lib/arel/nodes/terminal.rb +16 -0
  299. data/lib/arel/nodes/true.rb +16 -0
  300. data/lib/arel/nodes/unary.rb +45 -0
  301. data/lib/arel/nodes/unary_operation.rb +20 -0
  302. data/lib/arel/nodes/unqualified_column.rb +22 -0
  303. data/lib/arel/nodes/update_statement.rb +41 -0
  304. data/lib/arel/nodes/values_list.rb +9 -0
  305. data/lib/arel/nodes/window.rb +126 -0
  306. data/lib/arel/nodes/with.rb +11 -0
  307. data/lib/arel/nodes.rb +68 -0
  308. data/lib/arel/order_predications.rb +13 -0
  309. data/lib/arel/predications.rb +256 -0
  310. data/lib/arel/select_manager.rb +271 -0
  311. data/lib/arel/table.rb +110 -0
  312. data/lib/arel/tree_manager.rb +72 -0
  313. data/lib/arel/update_manager.rb +34 -0
  314. data/lib/arel/visitors/depth_first.rb +203 -0
  315. data/lib/arel/visitors/dot.rb +296 -0
  316. data/lib/arel/visitors/ibm_db.rb +34 -0
  317. data/lib/arel/visitors/informix.rb +62 -0
  318. data/lib/arel/visitors/mssql.rb +156 -0
  319. data/lib/arel/visitors/mysql.rb +83 -0
  320. data/lib/arel/visitors/oracle.rb +158 -0
  321. data/lib/arel/visitors/oracle12.rb +65 -0
  322. data/lib/arel/visitors/postgresql.rb +109 -0
  323. data/lib/arel/visitors/sqlite.rb +38 -0
  324. data/lib/arel/visitors/to_sql.rb +888 -0
  325. data/lib/arel/visitors/visitor.rb +45 -0
  326. data/lib/arel/visitors/where_sql.rb +22 -0
  327. data/lib/arel/visitors.rb +20 -0
  328. data/lib/arel/window_predications.rb +9 -0
  329. data/lib/arel.rb +62 -0
  330. data/lib/rails/generators/active_record/application_record/application_record_generator.rb +26 -0
  331. data/lib/rails/generators/active_record/migration/migration_generator.rb +37 -35
  332. data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +1 -1
  333. data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +4 -2
  334. data/lib/rails/generators/active_record/migration.rb +17 -3
  335. data/lib/rails/generators/active_record/model/model_generator.rb +9 -30
  336. data/lib/rails/generators/active_record/model/templates/{model.rb → model.rb.tt} +10 -1
  337. data/lib/rails/generators/active_record.rb +7 -5
  338. metadata +138 -52
  339. data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
  340. data/lib/active_record/associations/preloader/collection_association.rb +0 -17
  341. data/lib/active_record/associations/preloader/has_many.rb +0 -17
  342. data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
  343. data/lib/active_record/associations/preloader/has_one.rb +0 -15
  344. data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
  345. data/lib/active_record/associations/preloader/singular_association.rb +0 -20
  346. data/lib/active_record/attribute/user_provided_default.rb +0 -28
  347. data/lib/active_record/attribute.rb +0 -213
  348. data/lib/active_record/attribute_mutation_tracker.rb +0 -70
  349. data/lib/active_record/attribute_set/builder.rb +0 -132
  350. data/lib/active_record/attribute_set.rb +0 -110
  351. data/lib/active_record/collection_cache_key.rb +0 -50
  352. data/lib/active_record/connection_adapters/postgresql/oid/rails_5_1_point.rb +0 -50
  353. data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
  354. data/lib/active_record/relation/predicate_builder/association_query_handler.rb +0 -88
  355. data/lib/active_record/relation/predicate_builder/class_handler.rb +0 -27
  356. data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +0 -57
  357. data/lib/active_record/type/internal/abstract_json.rb +0 -33
  358. /data/lib/rails/generators/active_record/{model/templates/application_record.rb → application_record/templates/application_record.rb.tt} +0 -0
  359. /data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
data/CHANGELOG.md CHANGED
@@ -1,2549 +1,1449 @@
1
- ## Rails 5.0.7.2 (March 11, 2019) ##
1
+ ## Rails 6.0.6.1 (January 17, 2023) ##
2
2
 
3
- * No changes.
4
-
5
-
6
- ## Rails 5.0.7.1 (November 27, 2018) ##
7
-
8
- * No changes.
9
-
10
-
11
- ## Rails 5.0.7 (March 29, 2018) ##
12
-
13
- * Apply time column precision on assignment.
3
+ * Make `sanitize_as_sql_comment` more strict
14
4
 
15
- PR #20317 changed the behavior of datetime columns so that when they
16
- have a specified precision then on assignment the value is rounded to
17
- that precision. This behavior is now applied to time columns as well.
5
+ Though this method was likely never meant to take user input, it was
6
+ attempting sanitization. That sanitization could be bypassed with
7
+ carefully crafted input.
18
8
 
19
- Fixes #30301.
9
+ This commit makes the sanitization more robust by replacing any
10
+ occurrances of "/*" or "*/" with "/ *" or "* /". It also performs a
11
+ first pass to remove one surrounding comment to avoid compatibility
12
+ issues for users relying on the existing removal.
20
13
 
21
- *Andrew White*
14
+ This also clarifies in the documentation of annotate that it should not
15
+ be provided user input.
22
16
 
23
- * Normalize time column values for SQLite database.
17
+ [CVE-2023-22794]
24
18
 
25
- For legacy reasons, time columns in SQLite are stored as full datetimes
26
- because until #24542 the quoting for time columns didn't remove the date
27
- component. To ensure that values are consistent we now normalize the
28
- date component to 2001-01-01 on reading and writing.
29
19
 
30
- *Andrew White*
20
+ ## Rails 6.0.6 (September 09, 2022) ##
31
21
 
32
- * Ensure that the date component is removed when quoting times.
22
+ * Symbol is allowed by default for YAML columns
33
23
 
34
- PR #24542 altered the quoting for time columns so that the date component
35
- was removed however it only removed it when it was 2001-01-01. Now the
36
- date component is removed irrespective of what the date is.
24
+ *Étienne Barrié*
37
25
 
38
- *Andrew White*
39
26
 
40
- * Query cache was unavailable when entering the `ActiveRecord::Base.cache` block
41
- without being connected.
27
+ ## Rails 6.0.5.1 (July 12, 2022) ##
42
28
 
43
- *Tsukasa Oishi*
29
+ * Change ActiveRecord::Coders::YAMLColumn default to safe_load
44
30
 
45
- * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
46
- ar_internal_metadata's data for a test database.
47
-
48
- Before:
49
- ```
50
- $ RAILS_ENV=test rails dbconsole
51
- > SELECT * FROM ar_internal_metadata;
52
- key|value|created_at|updated_at
53
- environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
54
- ```
55
-
56
- After:
31
+ This adds two new configuration options The configuration options are as
32
+ follows:
33
+
34
+ * `config.active_storage.use_yaml_unsafe_load`
35
+
36
+ When set to true, this configuration option tells Rails to use the old
37
+ "unsafe" YAML loading strategy, maintaining the existing behavior but leaving
38
+ the possible escalation vulnerability in place. Setting this option to true
39
+ is *not* recommended, but can aid in upgrading.
40
+
41
+ * `config.active_record.yaml_column_permitted_classes`
42
+
43
+ The "safe YAML" loading method does not allow all classes to be deserialized
44
+ by default. This option allows you to specify classes deemed "safe" in your
45
+ application. For example, if your application uses Symbol and Time in
46
+ serialized data, you can add Symbol and Time to the allowed list as follows:
47
+
57
48
  ```
58
- $ RAILS_ENV=test rails dbconsole
59
- > SELECT * FROM ar_internal_metadata;
60
- key|value|created_at|updated_at
61
- environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
49
+ config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
62
50
  ```
63
51
 
64
- Fixes #26731.
52
+ [CVE-2022-32224]
65
53
 
66
- *bogdanvlviv*
67
54
 
68
- * Fix longer sequence name detection for serial columns.
55
+ ## Rails 6.0.5 (May 09, 2022) ##
69
56
 
70
- Fixes #28332.
57
+ * No changes.
71
58
 
72
- *Ryuta Kamizono*
73
59
 
74
- * Use `max_identifier_length` for `index_name_length` in PostgreSQL adapter.
60
+ ## Rails 6.0.4.8 (April 26, 2022) ##
75
61
 
76
- *Ryuta Kamizono*
62
+ * No changes.
77
63
 
78
64
 
79
- ## Rails 5.0.6 (September 07, 2017) ##
65
+ ## Rails 6.0.4.7 (March 08, 2022) ##
80
66
 
81
67
  * No changes.
82
68
 
83
69
 
84
- ## Rails 5.0.6.rc1 (August 24, 2017) ##
85
-
86
- * Ensure `sum` honors `distinct` on `has_many :through` associations
70
+ ## Rails 6.0.4.6 (February 11, 2022) ##
87
71
 
88
- Fixes #16791
89
-
90
- *Aaron Wortham
72
+ * No changes.
91
73
 
92
74
 
93
- ## Rails 5.0.5 (July 31, 2017) ##
75
+ ## Rails 6.0.4.5 (February 11, 2022) ##
94
76
 
95
77
  * No changes.
96
78
 
97
79
 
98
- ## Rails 5.0.5.rc2 (July 25, 2017) ##
80
+ ## Rails 6.0.4.4 (December 15, 2021) ##
99
81
 
100
82
  * No changes.
101
83
 
102
84
 
103
- ## Rails 5.0.5.rc1 (July 19, 2017) ##
104
-
105
- * `Relation#joins` is no longer affected by the target model's
106
- `current_scope`, with the exception of `unscoped`.
107
-
108
- Fixes #29338.
85
+ ## Rails 6.0.4.3 (December 14, 2021) ##
109
86
 
110
- *Sean Griffin*
87
+ * No changes.
111
88
 
112
89
 
113
- ## Rails 5.0.4 (June 19, 2017) ##
90
+ ## Rails 6.0.4.2 (December 14, 2021) ##
114
91
 
115
- * Restore previous behavior of collection proxies: their values can have
116
- methods stubbed, and they respect extension modules applied by a default
117
- scope.
92
+ * No changes.
118
93
 
119
- *Ryuta Kamizono*
120
94
 
121
- * Loading model schema from database is now thread-safe.
95
+ ## Rails 6.0.4.1 (August 19, 2021) ##
122
96
 
123
- Fixes #28589.
97
+ * No changes.
124
98
 
125
- *Vikrant Chaudhary*, *David Abdemoulaie*
126
99
 
100
+ ## Rails 6.0.4 (June 15, 2021) ##
127
101
 
128
- ## Rails 5.0.3 (May 12, 2017) ##
102
+ * Only warn about negative enums if a positive form that would cause conflicts exists.
129
103
 
130
- * Check whether `Rails.application` defined before calling it
104
+ Fixes #39065.
131
105
 
132
- In #27674 we changed the migration generator to generate migrations at the
133
- path defined in `Rails.application.config.paths` however the code checked
134
- for the presence of the `Rails` constant but not the `Rails.application`
135
- method which caused problems when using Active Record and generators outside
136
- of the context of a Rails application.
106
+ *Alex Ghiculescu*
137
107
 
138
- Fixes #28325.
108
+ * Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
139
109
 
140
- * Fix `deserialize` with JSON array.
110
+ Fixes #34255.
141
111
 
142
- Fixes #28285.
112
+ *Steven Weber*
143
113
 
144
- *Ryuta Kamizono*
114
+ * Reset statement cache for association if `table_name` is changed.
145
115
 
146
- * Fix `rake db:schema:load` with subdirectories.
116
+ Fixes #36453.
147
117
 
148
118
  *Ryuta Kamizono*
149
119
 
150
- * Fix `rake db:migrate:status` with subdirectories.
120
+ * Type cast extra select for eager loading.
151
121
 
152
122
  *Ryuta Kamizono*
153
123
 
154
- * Don't share options between reference id and type columns
155
-
156
- When using a polymorphic reference column in a migration, sharing options
157
- between the two columns doesn't make sense since they are different types.
158
- The `reference_id` column is usually an integer and the `reference_type`
159
- column a string so options like `unsigned: true` will result in an invalid
160
- table definition.
161
-
162
- *Ryuta Kamizono*
124
+ * Prevent collection associations from being autosaved multiple times.
163
125
 
164
- * Fix regression of #1969 with SELECT aliases in HAVING clause.
126
+ Fixes #39173.
165
127
 
166
128
  *Eugene Kenny*
167
129
 
130
+ * Resolve issue with insert_all unique_by option when used with expression index.
168
131
 
169
- ## Rails 5.0.2 (March 01, 2017) ##
132
+ When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
133
+ `ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
134
+ was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
170
135
 
171
- * Fix `wait_timeout` to configurable for mysql2 adapter.
136
+ Usage:
172
137
 
173
- Fixes #26556.
138
+ ```ruby
139
+ create_table :books, id: :integer, force: true do |t|
140
+ t.column :name, :string
141
+ t.index "lower(name)", unique: true
142
+ end
174
143
 
175
- *Ryuta Kamizono*
144
+ Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
145
+ ```
176
146
 
177
- * Make `table_name=` reset current statement cache,
178
- so queries are not run against the previous table name.
147
+ Fixes #39516.
179
148
 
180
- *namusyaka*
149
+ *Austen Madden*
181
150
 
182
- * Allow ActiveRecord::Base#as_json to be passed a frozen Hash.
151
+ * Fix preloading for polymorphic association with custom scope.
183
152
 
184
- *Isaac Betesh*
153
+ *Ryuta Kamizono*
185
154
 
186
- * Fix inspection behavior when the :id column is not primary key.
155
+ * Allow relations with different SQL comments in the `or` method.
187
156
 
188
- *namusyaka*
157
+ *Takumi Shotoku*
189
158
 
190
- * Fix `association_primary_key_type` for reflections with symbol primary key
159
+ * Resolve conflict between counter cache and optimistic locking.
191
160
 
192
- Fixes #27864
161
+ Bump an Active Record instance's lock version after updating its counter
162
+ cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
163
+ upon subsequent transactions by maintaining parity with the corresponding
164
+ database record's `lock_version` column.
193
165
 
194
- *Daniel Colson*
166
+ Fixes #16449.
195
167
 
196
- * Place generated migrations into the path set by `config.paths["db/migrate"]`
168
+ *Aaron Lipman*
197
169
 
198
- *Kevin Glowacz*
170
+ * Fix through association with source/through scope which has joins.
199
171
 
200
- * Compare deserialized values for `PostgreSQL::OID::Hstore` types when
201
- calling `ActiveRecord::Dirty#changed_in_place?`
172
+ *Ryuta Kamizono*
202
173
 
203
- Fixes #27502.
174
+ * Fix through association to respect source scope for includes/preload.
204
175
 
205
- *Jon Moss*
176
+ *Ryuta Kamizono*
206
177
 
207
- * Respect precision option for arrays of timestamps.
178
+ * Fix eager load with Arel joins to maintain the original joins order.
208
179
 
209
- Fixes #27514.
180
+ *Ryuta Kamizono*
210
181
 
211
- *Sean Griffin*
182
+ * Fix group by count with eager loading + order + limit/offset.
212
183
 
184
+ *Ryuta Kamizono*
213
185
 
214
- ## Rails 5.0.1 (December 21, 2016) ##
186
+ * Fix left joins order when merging multiple left joins from different associations.
215
187
 
216
- * No changes.
188
+ *Ryuta Kamizono*
217
189
 
190
+ * Fix index creation to preserve index comment in bulk change table on MySQL.
218
191
 
219
- ## Rails 5.0.1.rc2 (December 10, 2016) ##
192
+ *Ryuta Kamizono*
220
193
 
221
- * Correct resolution of associated class in `has_many :through`
222
- associations' `*_ids` setters.
194
+ * Change `remove_foreign_key` to not check `:validate` option if database
195
+ doesn't support the feature.
223
196
 
224
- Fixes #27297.
197
+ *Ryuta Kamizono*
225
198
 
226
- *Matthew Draper*
199
+ * Fix the result of aggregations to maintain duplicated "group by" fields.
227
200
 
228
- * Support index length and order options using both string and symbol
229
- column names.
201
+ *Ryuta Kamizono*
230
202
 
231
- Fixes #27243.
203
+ * Do not return duplicated records when using preload.
232
204
 
233
- *Ryuta Kamizono*
205
+ *Bogdan Gusiev*
234
206
 
235
207
 
236
- ## Rails 5.0.1.rc1 (December 01, 2016) ##
208
+ ## Rails 6.0.3.7 (May 05, 2021) ##
237
209
 
238
- * Fix that unsigned with zerofill is treated as signed.
210
+ * No changes.
239
211
 
240
- Fixes #27125.
241
212
 
242
- *Ryuta Kamizono*
213
+ ## Rails 6.0.3.6 (March 26, 2021) ##
243
214
 
244
- * Fix the uniqueness validation scope with a polymorphic association.
215
+ * No changes.
245
216
 
246
- *Sergey Alekseev*
247
217
 
248
- * Raise ActiveRecord::RecordNotFound from collection `*_ids` setters
249
- for unknown IDs with a better error message.
218
+ ## Rails 6.0.3.5 (February 10, 2021) ##
250
219
 
251
- Changes the collection `*_ids` setters to cast provided IDs the data
252
- type of the primary key set in the association, not the model
253
- primary key.
220
+ * Fix possible DoS vector in PostgreSQL money type
254
221
 
255
- *Dominic Cleal*
222
+ Carefully crafted input can cause a DoS via the regular expressions used
223
+ for validating the money format in the PostgreSQL adapter. This patch
224
+ fixes the regexp.
256
225
 
257
- * Introduce `Model#reload_<association>` to bring back the behavior
258
- of `Article.category(true)` where `category` is a singular
259
- association.
226
+ Thanks to @dee-see from Hackerone for this patch!
260
227
 
261
- The force reloading of the association reader was deprecated
262
- in #20888. Unfortunately the suggested alternative of
263
- `article.reload.category` does not expose the same behavior.
228
+ [CVE-2021-22880]
264
229
 
265
- This patch adds a reader method with the prefix `reload_` for
266
- singular associations. This method has the same semantics as
267
- passing true to the association reader used to have.
230
+ *Aaron Patterson*
268
231
 
269
- *Yves Senn*
270
232
 
271
- * Make sure eager loading `ActiveRecord::Associations` also loads
272
- constants defined in `ActiveRecord::Associations::Preloader`.
233
+ ## Rails 6.0.3.4 (October 07, 2020) ##
273
234
 
274
- *Yves Senn*
235
+ * No changes.
275
236
 
276
- * Allow `ActionController::Parameters`-like objects to be passed as
277
- values for Postgres HStore columns.
278
237
 
279
- Fixes #26904.
238
+ ## Rails 6.0.3.3 (September 09, 2020) ##
280
239
 
281
- *Jon Moss*
240
+ * No changes.
282
241
 
283
- * Configure query caching (per thread) on the connection pool.
284
242
 
285
- Moving the configuration to the pool means we don't allocate a connection
286
- until it's actually needed.
243
+ ## Rails 6.0.3.2 (June 17, 2020) ##
287
244
 
288
- Applications that manually interact with the connection pool and/or query
289
- cache may notice that the connection's cache is now cleared and disabled
290
- when it gets returned to the pool, even if the request is not yet completed.
245
+ * No changes.
291
246
 
292
- *Samuel Cochran*, *Matthew Draper*
293
247
 
294
- * Fixed support for case insensitive comparisons of `text` columns in
295
- PostgreSQL.
248
+ ## Rails 6.0.3.1 (May 18, 2020) ##
296
249
 
297
- *Edho Arief*
250
+ * No changes.
298
251
 
299
- * Return `true` from `update_attribute` when the value of the attribute
300
- to be updated is unchanged.
301
252
 
302
- Fixes #26593.
253
+ ## Rails 6.0.3 (May 06, 2020) ##
303
254
 
304
- *Prathamesh Sonpatki*
255
+ * Recommend applications don't use the `database` kwarg in `connected_to`
305
256
 
306
- * Serialize JSON attribute value `nil` as SQL `NULL`, not JSON `null`
257
+ The database kwarg in `connected_to` was meant to be used for one-off scripts but is often used in requests. This is really dangerous because it re-establishes a connection every time. It's deprecated in 6.1 and will be removed in 6.2 without replacement. This change soft deprecates it in 6.0 by removing documentation.
307
258
 
308
- *Trung Duc Tran*
259
+ *Eileen M. Uchitelle*
309
260
 
310
- * Always store errors details information with symbols.
261
+ * Fix support for PostgreSQL 11+ partitioned indexes.
311
262
 
312
- When the association is autosaved we were storing the details with
313
- string keys. This was creating inconsistency with other details that are
314
- added using the `Errors#add` method. It was also inconsistent with the
315
- `Errors#messages` storage.
263
+ *Sebastián Palma*
316
264
 
317
- To fix this inconsistency we are always storing with symbols. This will
318
- cause a small breaking change because in those cases the details could
319
- be accessed as strings keys but now it can not.
265
+ * Add support for beginless ranges, introduced in Ruby 2.7.
320
266
 
321
- Fix #26499.
267
+ *Josh Goodall*
322
268
 
323
- *Rafael Mendonça França*, *Marcus Vieira*
269
+ * Fix insert_all with enum values
324
270
 
325
- * Using a mysql2 connection after it fails to reconnect will now have an error message
326
- saying the connection is closed rather than an undefined method error message.
271
+ Fixes #38716.
327
272
 
328
- *Dylan Thacker-Smith*
273
+ *Joel Blum*
329
274
 
330
- * Remove unnecessarily association load when a `belongs_to` association has already been
331
- loaded then the foreign key is changed directly and the record saved.
275
+ * Regexp-escape table name for MS SQL
332
276
 
333
- *James Coleman*
277
+ Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
334
278
 
335
- * PostgreSQL array columns will now respect the encoding of strings contained
336
- in the array.
279
+ *Larry Reid*
337
280
 
338
- Fixes #26326.
281
+ * Store advisory locks on their own named connection.
339
282
 
340
- *Sean Griffin*
283
+ Previously advisory locks were taken out against a connection when a migration started. This works fine in single database applications but doesn't work well when migrations need to open new connections which results in the lock getting dropped.
341
284
 
342
- * Inverse association instances will now be set before `after_find` or
343
- `after_initialize` callbacks are run.
285
+ In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
344
286
 
345
- Fixes #26320.
287
+ *Eileen M. Uchitelle*, *John Crepezzi*
346
288
 
347
- *Sean Griffin*
289
+ * Ensure `:reading` connections always raise if a write is attempted.
348
290
 
349
- * Avoid loading records from database when they are already loaded using
350
- the `pluck` method on a collection.
291
+ Now Rails will raise an `ActiveRecord::ReadOnlyError` if any connection on the reading handler attempts to make a write. If your reading role needs to write you should name the role something other than `:reading`.
351
292
 
352
- Fixes #25921.
293
+ *Eileen M. Uchitelle*
353
294
 
354
- *Ryuta Kamizono*
295
+ * Enforce fresh ETag header after a collection's contents change by adding
296
+ ActiveRecord::Relation#cache_key_with_version. This method will be used by
297
+ ActionController::ConditionalGet to ensure that when collection cache versioning
298
+ is enabled, requests using ConditionalGet don't return the same ETag header
299
+ after a collection is modified. Fixes #38078.
355
300
 
356
- * Sqlite3 migrations to add a column to an existing table can now be
357
- successfully rolled back when the column was given and invalid column
358
- type.
301
+ *Aaron Lipman*
359
302
 
360
- Fixes #26087
303
+ * A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgresSQL `options`.
361
304
 
362
- *Travis O'Neill*
305
+ *Joshua Flanagan*
363
306
 
364
- * Hashes can once again be passed to setters of `composed_of`, if all of the
365
- mapping methods are methods implemented on `Hash`.
307
+ * Retain explicit selections on the base model after applying `includes` and `joins`.
366
308
 
367
- Fixes #25978.
309
+ Resolves #34889.
368
310
 
369
- *Sean Griffin*
311
+ *Patrick Rebsch*
370
312
 
371
- * Doing count on relations that contain LEFT OUTER JOIN Arel node no longer
372
- force a DISTINCT. This solves issues when using count after a left_joins.
373
313
 
374
- *Maxime Handfield Lapointe*
314
+ ## Rails 6.0.2.2 (March 19, 2020) ##
375
315
 
376
- * RecordNotFound raised by association.find exposes `id`, `primary_key` and
377
- `model` methods to be consistent with RecordNotFound raised by Record.find.
316
+ * No changes.
378
317
 
379
- *Michel Pigassou*
380
318
 
381
- * Fix the SELECT statement in `#table_comment` for MySQL.
319
+ ## Rails 6.0.2.1 (December 18, 2019) ##
382
320
 
383
- *Takeshi Akima*
321
+ * No changes.
384
322
 
385
- * Virtual attributes will no longer raise when read on models loaded from the
386
- database
387
323
 
388
- *Sean Griffin*
324
+ ## Rails 6.0.2 (December 13, 2019) ##
389
325
 
390
- * Fixes multi-parameter attributes conversion with invalid params.
326
+ * Share the same connection pool for primary and replica databases in the
327
+ transactional tests for the same database.
391
328
 
392
- *Hiroyuki Ishii*
329
+ *Edouard Chin*
393
330
 
394
- * Add newline between each migration in `structure.sql`.
331
+ * Fix the preloader when one record is fetched using `after_initialize`
332
+ but not the entire collection.
395
333
 
396
- Keeps schema migration inserts as a single commit, but allows for easier
397
- git diff-ing. Fixes #25504.
334
+ *Bradley Price*
398
335
 
399
- *Grey Baker*, *Norberto Lopes*
336
+ * Fix collection callbacks not terminating when `:abort` is thrown.
400
337
 
401
- * Using `group` with an attribute that has a custom type will properly cast
402
- the hash keys after calling a calculation method like `count`.
338
+ *Edouard Chin*, *Ryuta Kamizono*
403
339
 
404
- Fixes #25595.
340
+ * Correctly deprecate `where.not` working as NOR for relations.
405
341
 
406
- *Sean Griffin*
342
+ 12a9664 deprecated where.not working as NOR, however
343
+ doing a relation query like `where.not(relation: { ... })`
344
+ wouldn't be properly deprecated and `where.not` would work as
345
+ NAND instead.
407
346
 
408
- * Ensure concurrent invocations of the connection reaper cannot allocate the
409
- same connection to two threads.
347
+ *Edouard Chin*
410
348
 
411
- Fixes #25585.
349
+ * Fix `db:migrate` task with multiple databases to restore the connection
350
+ to the previous database.
412
351
 
413
- *Matthew Draper*
352
+ The migrate task iterates and establish a connection over each db
353
+ resulting in the last one to be used by subsequent rake tasks.
354
+ We should reestablish a connection to the connection that was
355
+ established before the migrate tasks was run
414
356
 
415
- * Fixed dumping of foreign key's referential actions when MySQL connection
416
- uses `sql_mode = ANSI_QUOTES`.
357
+ *Edouard Chin*
417
358
 
418
- Fixes #25300.
359
+ * Fix multi-threaded issue for `AcceptanceValidator`.
419
360
 
420
361
  *Ryuta Kamizono*
421
362
 
422
363
 
423
- ## Rails 5.0.0 (June 30, 2016) ##
424
-
425
- * Inspecting an object with an associated array of over 10 elements no longer
426
- truncates the array, preventing `inspect` from looping infinitely in some
427
- cases.
364
+ ## Rails 6.0.1 (November 5, 2019) ##
428
365
 
429
- *Kevin McPhillips*
366
+ * Common Table Expressions are allowed on read-only connections.
430
367
 
431
- * Ensure hashes can be assigned to attributes created using `composed_of`.
368
+ *Chris Morris*
432
369
 
433
- Fixes #25210.
370
+ * New record instantiation respects `unscope`.
434
371
 
435
- *Sean Griffin*
372
+ *Ryuta Kamizono*
436
373
 
437
- * Fix logging edge case where if an attribute was of the binary type and
438
- was provided as a Hash.
374
+ * Fixed a case where `find_in_batches` could halt too early.
439
375
 
440
- *Jon Moss*
376
+ *Takayuki Nakata*
441
377
 
442
- * Handle JSON deserialization correctly if the column default from database
443
- adapter returns `''` instead of `nil`.
378
+ * Autosaved associations always perform validations when a custom validation
379
+ context is used.
444
380
 
445
- *Johannes Opper*
381
+ *Tekin Suleyman*
446
382
 
447
- * PostgreSQL: Support Expression Indexes and Operator Classes.
383
+ * `sql.active_record` notifications now include the `:connection` in
384
+ their payloads.
448
385
 
449
- Example:
386
+ *Eugene Kenny*
450
387
 
451
- create_table :users do |t|
452
- t.string :name
453
- t.index 'lower(name) varchar_pattern_ops'
454
- end
388
+ * A rollback encountered in an `after_commit` callback does not reset
389
+ previously-committed record state.
455
390
 
456
- Fixes #19090, #21765, #21819, #24359.
391
+ *Ryuta Kamizono*
457
392
 
458
- *Ryuta Kamizono*
393
+ * Fixed that join order was lost when eager-loading.
459
394
 
460
- * MySQL: Prepared statements support.
395
+ *Ryuta Kamizono*
461
396
 
462
- To enable, set `prepared_statements: true` in config/database.yml.
463
- Requires mysql2 0.4.4+.
397
+ * `DESCRIBE` queries are allowed on read-only connections.
464
398
 
465
- *Ryuta Kamizono*
399
+ *Dylan Thacker-Smith*
466
400
 
467
- * Schema dumper: Indexes are now included in the `create_table` block
468
- instead of listed afterward as separate `add_index` lines.
401
+ * Fixed that records that had been `inspect`ed could not be marshaled.
469
402
 
470
- This tidies up schema.rb and makes it easy to read as a list of tables.
403
+ *Eugene Kenny*
471
404
 
472
- Bonus: Allows databases that support it (MySQL) to perform as single
473
- `CREATE TABLE` query, no additional query per index.
405
+ * The connection pool reaper thread is respawned in forked processes. This
406
+ fixes that idle connections in forked processes wouldn't be reaped.
474
407
 
475
- *Ryuta Kamizono*
408
+ *John Hawthorn*
476
409
 
477
- * SQLite: Fix uniqueness validation when values exceed the column limit.
410
+ * The memoized result of `ActiveRecord::Relation#take` is properly cleared
411
+ when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
412
+ is called.
478
413
 
479
- SQLite doesn't impose length restrictions on strings, BLOBs, or numeric
480
- values. It treats them as helpful metadata. When we truncate strings
481
- before checking uniqueness, we'd miss values that exceed the column limit.
414
+ *Anmol Arora*
482
415
 
483
- Other databases enforce length limits. A large value will pass uniqueness
484
- validation since the column limit guarantees no value that long exists.
485
- When we insert the row, it'll raise `ActiveRecord::ValueTooLong` as we
486
- expect.
416
+ * Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
487
417
 
488
- This fixes edge-case incorrect validation failures for values that exceed
489
- the column limit but are identical to an existing value *when truncated*.
490
- Now these will pass validation and raise an exception.
418
+ *Hiroyuki Ishii*
491
419
 
492
- *Ryuta Kamizono*
420
+ * `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
493
421
 
494
- * Raise `ActiveRecord::ValueTooLong` when column limits are exceeded.
495
- Supported by MySQL and PostgreSQL adapters.
422
+ *Eugene Kenny*
496
423
 
497
- *Ryuta Kamizono*
424
+ * Call `while_preventing_writes` directly from `connected_to`.
498
425
 
499
- * Migrations: `#foreign_key` respects `table_name_prefix` and `_suffix`.
426
+ In some cases application authors want to use the database switching middleware and make explicit calls with `connected_to`. It's possible for an app to turn off writes and not turn them back on by the time we call `connected_to(role: :writing)`.
500
427
 
501
- *Ryuta Kamizono*
428
+ This change allows apps to fix this by assuming if a role is writing we want to allow writes, except in the case it's explicitly turned off.
502
429
 
503
- * SQLite: Force NOT NULL primary keys.
430
+ *Eileen M. Uchitelle*
504
431
 
505
- From SQLite docs: https://www.sqlite.org/lang_createtable.html
506
- According to the SQL standard, PRIMARY KEY should always imply NOT
507
- NULL. Unfortunately, due to a bug in some early versions, this is not
508
- the case in SQLite. Unless the column is an INTEGER PRIMARY KEY or the
509
- table is a WITHOUT ROWID table or the column is declared NOT NULL,
510
- SQLite allows NULL values in a PRIMARY KEY column. SQLite could be
511
- fixed to conform to the standard, but doing so might break legacy
512
- applications. Hence, it has been decided to merely document the fact
513
- that SQLite allowing NULLs in most PRIMARY KEY columns.
432
+ * Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
514
433
 
515
- Now we override column options to explicitly set NOT NULL rather than rely
516
- on implicit NOT NULL like MySQL and PostgreSQL adapters.
434
+ *Kir Shatrov*
517
435
 
518
- *Ryuta Kamizono*
519
436
 
520
- * Added notice when a database is successfully created or dropped.
437
+ ## Rails 6.0.0 (August 16, 2019) ##
521
438
 
522
- Example:
439
+ * Preserve user supplied joins order as much as possible.
523
440
 
524
- $ bin/rails db:create
525
- Created database 'blog_development'
526
- Created database 'blog_test'
441
+ Fixes #36761, #34328, #24281, #12953.
527
442
 
528
- $ bin/rails db:drop
529
- Dropped database 'blog_development'
530
- Dropped database 'blog_test'
443
+ *Ryuta Kamizono*
531
444
 
532
- Changed older notices
533
- `blog_development already exists` to `Database 'blog_development' already exists`.
534
- and
535
- `Couldn't drop blog_development` to `Couldn't drop database 'blog_development'`.
445
+ * Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
536
446
 
537
- *bogdanvlviv*
447
+ *John Crepezzi*, *Eileen Uchitelle*
538
448
 
539
- * Database comments. Annotate database objects (tables, columns, indexes)
540
- with comments stored in database metadata. PostgreSQL & MySQL support.
449
+ * Add a warning for enum elements with 'not_' prefix.
541
450
 
542
- create_table :pages, force: :cascade, comment: 'CMS content pages' do |t|
543
- t.string :path, comment: 'Path fragment of page URL used for routing'
544
- t.string :locale, comment: 'RFC 3066 locale code of website language section'
545
- t.index [:path, :locale], comment: 'Look up pages by URI'
451
+ class Foo
452
+ enum status: [:sent, :not_sent]
546
453
  end
547
454
 
548
- *Andrey Novikov*
455
+ *Edu Depetris*
549
456
 
550
- * Add `quoted_time` for truncating the date part of a TIME column value.
551
- This fixes queries on TIME column on MariaDB, as it doesn't ignore the
552
- date part of the string when it coerces to time.
457
+ * Make currency symbols optional for money column type in PostgreSQL
553
458
 
554
- *Ryuta Kamizono*
459
+ *Joel Schneider*
555
460
 
556
- * Properly accept all valid JSON primitives in the JSON data type.
557
461
 
558
- Fixes #24234
462
+ ## Rails 6.0.0.rc2 (July 22, 2019) ##
559
463
 
560
- *Sean Griffin*
464
+ * Add database_exists? method to connection adapters to check if a database exists.
561
465
 
562
- * MariaDB 5.3+ supports microsecond datetime precision.
466
+ *Guilherme Mansur*
563
467
 
564
- *Jeremy Daer*
468
+ * PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
565
469
 
566
- * Delegate `none?` and `one?`. Now they can be invoked as model class methods.
470
+ Fixes #36022.
567
471
 
568
- Example:
472
+ *Ryuta Kamizono*
569
473
 
570
- # When no record is found on the table
571
- Topic.none? # => true
474
+ * Make ActiveRecord `ConnectionPool.connections` method thread-safe.
572
475
 
573
- # When only one record is found on the table
574
- Topic.one? # => true
476
+ Fixes #36465.
575
477
 
576
- *Kenta Shirai*
478
+ *Jeff Doering*
577
479
 
578
- * The form builder now properly displays values when passing a proc form
579
- default to the attributes API.
480
+ * Fix sqlite3 collation parsing when using decimal columns.
580
481
 
581
- Fixes #24249.
482
+ *Martin R. Schuster*
582
483
 
583
- *Sean Griffin*
484
+ * Fix invalid schema when primary key column has a comment.
584
485
 
585
- * The schema cache is now cleared after the `db:migrate` task is run.
486
+ Fixes #29966.
586
487
 
587
- Closes #24273.
488
+ *Guilherme Goettems Schneider*
588
489
 
589
- *Chris Arcand*
490
+ * Fix table comment also being applied to the primary key column.
590
491
 
591
- * MySQL: strict mode respects other SQL modes rather than overwriting them.
592
- Setting `strict: true` adds `STRICT_ALL_TABLES` to `sql_mode`. Setting
593
- `strict: false` removes `STRICT_TRANS_TABLES`, `STRICT_ALL_TABLES`, and
594
- `TRADITIONAL` from `sql_mode`.
492
+ *Guilherme Goettems Schneider*
595
493
 
596
- *Ryuta Kamizono*
494
+ * Fix merging left_joins to maintain its own `join_type` context.
597
495
 
598
- * Execute default_scope defined by abstract class in the context of subclass.
496
+ Fixes #36103.
599
497
 
600
- Fixes #23413.
601
- Fixes #10658.
498
+ *Ryuta Kamizono*
602
499
 
603
- *Mehmet Emin İNAÇ*
604
500
 
605
- * Fix an issue when preloading associations with extensions.
606
- Previously every association with extension methods was transformed into an
607
- instance dependent scope. This is no longer the case.
501
+ ## Rails 6.0.0.rc1 (April 24, 2019) ##
608
502
 
609
- Fixes #23934.
503
+ * Add `touch` option to `has_one` association.
610
504
 
611
- *Yves Senn*
505
+ *Abhay Nikam*
612
506
 
613
- * Deprecate `{insert|update|delete}_sql` in `DatabaseStatements`.
614
- Use the `{insert|update|delete}` public methods instead.
507
+ * Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
615
508
 
616
- *Ryuta Kamizono*
509
+ ```ruby
510
+ all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
511
+ assert_equal all, PriceEstimate.all.map(&:estimate_of)
512
+ ```
617
513
 
618
- * Added a configuration option to have active record raise an ArgumentError
619
- if the order or limit is ignored in a batch query, rather than logging a
620
- warning message.
514
+ In Rails 6.0:
621
515
 
622
- *Scott Ringwelski*
516
+ ```ruby
517
+ sapphire = treasures(:sapphire)
623
518
 
624
- * Honour the order of the joining model in a `has_many :through` association when eager loading.
519
+ nor = all.reject { |e|
520
+ e.estimate_of_type == sapphire.class.polymorphic_name
521
+ }.reject { |e|
522
+ e.estimate_of_id == sapphire.id
523
+ }
524
+ assert_equal [cars(:honda)], nor
625
525
 
626
- Example:
526
+ without_sapphire = PriceEstimate.where.not(
527
+ estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
528
+ )
529
+ assert_equal nor, without_sapphire.map(&:estimate_of)
530
+ ```
627
531
 
628
- The below will now follow the order of `by_lines` when eager loading `authors`.
532
+ In Rails 6.1:
629
533
 
630
- class Article < ActiveRecord::Base
631
- has_many :by_lines, -> { order(:position) }
632
- has_many :authors, through: :by_lines
633
- end
534
+ ```ruby
535
+ sapphire = treasures(:sapphire)
634
536
 
635
- Fixes #17864.
537
+ nand = all - [sapphire]
538
+ assert_equal [treasures(:diamond), cars(:honda)], nand
636
539
 
637
- *Yasyf Mohamedali*, *Joel Turkel*
540
+ without_sapphire = PriceEstimate.where.not(
541
+ estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
542
+ )
543
+ assert_equal nand, without_sapphire.map(&:estimate_of)
544
+ ```
638
545
 
639
- * Ensure that the Suppressor runs before validations.
546
+ *Ryuta Kamizono*
640
547
 
641
- This moves the suppressor up to be run before validations rather than after
642
- validations. There's no reason to validate a record you aren't planning on saving.
548
+ * Fix dirty tracking after rollback.
643
549
 
644
- *Eileen M. Uchitelle*
550
+ Fixes #15018, #30167, #33868.
645
551
 
646
- * Save many-to-many objects based on association primary key.
552
+ *Ryuta Kamizono*
647
553
 
648
- Fixes #20995.
554
+ * Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
555
+ the versioned entries in `ActiveSupport::Cache`. This also means that
556
+ `ActiveRecord::Relation#cache_key` will now return a stable key that does not
557
+ include the max timestamp or count any more.
649
558
 
650
- *himesh-r*
559
+ NOTE: This feature is turned off by default, and `cache_key` will still return
560
+ cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
561
+ That's the setting for all new apps on Rails 6.0+
651
562
 
652
- * Ensure that mutations of the array returned from `ActiveRecord::Relation#to_a`
653
- do not affect the original relation, by returning a duplicate array each time.
563
+ *Lachlan Sylvester*
654
564
 
655
- This brings the behavior in line with `CollectionProxy#to_a`, which was
656
- already more careful.
565
+ * Fix dirty tracking for `touch` to track saved changes.
657
566
 
658
- *Matthew Draper*
567
+ Fixes #33429.
659
568
 
660
- * Fixed `where` for polymorphic associations when passed an array containing different types.
569
+ *Ryuta Kamzono*
661
570
 
662
- Fixes #17011.
571
+ * `change_column_comment` and `change_table_comment` are invertible only if
572
+ `to` and `from` options are specified.
663
573
 
664
- Example:
574
+ *Yoshiyuki Kinjo*
665
575
 
666
- PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)])
667
- # => SELECT "price_estimates".* FROM "price_estimates"
668
- WHERE (("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" = 1)
669
- OR ("price_estimates"."estimate_of_type" = 'Car' AND "price_estimates"."estimate_of_id" = 2))
576
+ * Don't call commit/rollback callbacks when a record isn't saved.
670
577
 
671
- *Philippe Huibonhoa*
578
+ Fixes #29747.
672
579
 
673
- * Fix a bug where using `t.foreign_key` twice with the same `to_table` within
674
- the same table definition would only create one foreign key.
580
+ *Ryuta Kamizono*
675
581
 
676
- *George Millo*
582
+ * Fix circular `autosave: true` causes invalid records to be saved.
677
583
 
678
- * Fix a regression on has many association, where calling a child from parent in child's callback
679
- results in same child records getting added repeatedly to target.
584
+ Prior to the fix, when there was a circular series of `autosave: true`
585
+ associations, the callback for a `has_many` association was run while
586
+ another instance of the same callback on the same association hadn't
587
+ finished running. When control returned to the first instance of the
588
+ callback, the instance variable had changed, and subsequent associated
589
+ records weren't saved correctly. Specifically, the ID field for the
590
+ `belongs_to` corresponding to the `has_many` was `nil`.
680
591
 
681
- Fixes #13387.
592
+ Fixes #28080.
682
593
 
683
- *Bogdan Gusiev*, *Jon Hinson*
594
+ *Larry Reid*
684
595
 
685
- * Rework `ActiveRecord::Relation#last`.
596
+ * Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
686
597
 
687
- 1. Never perform additional SQL on loaded relation
688
- 2. Use SQL reverse order instead of loading relation if relation doesn't have limit
689
- 3. Deprecated relation loading when SQL order can not be automatically reversed
598
+ Before:
690
599
 
691
- Topic.order("title").load.last(3)
692
- # before: SELECT ...
693
- # after: No SQL
600
+ ```ruby
601
+ add_column :items, :attr1, :binary, size: 10 # => ArgumentError
602
+ add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
603
+ add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
604
+ add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
605
+ ```
694
606
 
695
- Topic.order("title").last
696
- # before: SELECT * FROM `topics`
697
- # after: SELECT * FROM `topics` ORDER BY `topics`.`title` DESC LIMIT 1
607
+ After:
698
608
 
699
- Topic.order("coalesce(author, title)").last
700
- # before: SELECT * FROM `topics`
701
- # after: Deprecation Warning for irreversible order
609
+ ```ruby
610
+ add_column :items, :attr1, :binary, size: 10 # => ArgumentError
611
+ add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
612
+ add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
613
+ add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
614
+ ```
702
615
 
703
- *Bogdan Gusiev*
616
+ *Ryuta Kamizono*
704
617
 
705
- * Allow `joins` to be unscoped.
618
+ * Association loading isn't to be affected by scoping consistently
619
+ whether preloaded / eager loaded or not, with the exception of `unscoped`.
706
620
 
707
- Fixes #13775.
621
+ Before:
708
622
 
709
- *Takashi Kokubun*
623
+ ```ruby
624
+ Post.where("1=0").scoping do
625
+ Comment.find(1).post # => nil
626
+ Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
627
+ Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
628
+ end
629
+ ```
710
630
 
711
- * Add `#second_to_last` and `#third_to_last` finder methods.
631
+ After:
712
632
 
713
- *Brian Christian*
633
+ ```ruby
634
+ Post.where("1=0").scoping do
635
+ Comment.find(1).post # => #<Post id: 1, ...>
636
+ Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
637
+ Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
638
+ end
639
+ ```
714
640
 
715
- * Added `numeric` helper into migrations.
641
+ Fixes #34638, #35398.
716
642
 
717
- Example:
643
+ *Ryuta Kamizono*
718
644
 
719
- create_table(:numeric_types) do |t|
720
- t.numeric :numeric_type, precision: 10, scale: 2
721
- end
645
+ * Add `rails db:prepare` to migrate or setup a database.
722
646
 
723
- *Mehmet Emin İNAÇ*
647
+ Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
724
648
 
725
- * Bumped the minimum supported version of PostgreSQL to >= 9.1.
726
- Both PG 9.0 and 8.4 are past their end of life date:
727
- http://www.postgresql.org/support/versioning/
649
+ *Roberto Miranda*
728
650
 
729
- *Remo Mueller*
651
+ * Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
730
652
 
731
- * `ActiveRecord::Relation#reverse_order` throws `ActiveRecord::IrreversibleOrderError`
732
- when the order can not be reversed using current trivial algorithm.
733
- Also raises the same error when `#reverse_order` is called on
734
- relation without any order and table has no primary key:
653
+ *DHH*
735
654
 
736
- Topic.order("concat(author_name, title)").reverse_order
737
- # Before: SELECT `topics`.* FROM `topics` ORDER BY concat(author_name DESC, title) DESC
738
- # After: raises ActiveRecord::IrreversibleOrderError
739
- Edge.all.reverse_order
740
- # Before: SELECT `edges`.* FROM `edges` ORDER BY `edges`.`` DESC
741
- # After: raises ActiveRecord::IrreversibleOrderError
655
+ * Assign all attributes before calling `build` to ensure the child record is visible in
656
+ `before_add` and `after_add` callbacks for `has_many :through` associations.
742
657
 
743
- *Bogdan Gusiev*
658
+ Fixes #33249.
744
659
 
745
- * Improve schema_migrations insertion performance by inserting all versions
746
- in one INSERT SQL.
660
+ *Ryan H. Kerr*
747
661
 
748
- *Akira Matsuda*, *Naoto Koshikawa*
662
+ * Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
749
663
 
750
- * Using `references` or `belongs_to` in migrations will always add index
751
- for the referenced column by default, without adding `index: true` option
752
- to generated migration file. Users can opt out of this by passing
753
- `index: false`.
664
+ ```
665
+ account.memberships.extract_associated(:user)
666
+ # => Returns collection of User records
667
+ ```
754
668
 
755
- Fixes #18146.
669
+ *DHH*
756
670
 
757
- *Matthew Draper*, *Prathamesh Sonpatki*
671
+ * Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
758
672
 
759
- * Run `type` attributes through attributes API type-casting before
760
- instantiating the corresponding subclass. This makes it possible to define
761
- custom STI mappings.
673
+ For example:
762
674
 
763
- Fixes #21986.
675
+ ```
676
+ Post.where(id: 123).annotate("this is a comment").to_sql
677
+ # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
678
+ ```
764
679
 
765
- *Yves Senn*
680
+ This can be useful in instrumentation or other analysis of issued queries.
766
681
 
767
- * Don't try to quote functions or expressions passed to `:default` option if
768
- they are passed as procs.
682
+ *Matt Yoho*
769
683
 
770
- This will generate proper query with the passed function or expression for
771
- the default option, instead of trying to quote it in incorrect fashion.
684
+ * Support Optimizer Hints.
772
685
 
773
- Example:
686
+ In most databases, a way to control the optimizer is by using optimizer hints,
687
+ which can be specified within individual statements.
774
688
 
775
- create_table :posts do |t|
776
- t.datetime :published_at, default: -> { 'NOW()' }
777
- end
689
+ Example (for MySQL):
778
690
 
779
- *Ryuta Kamizono*
691
+ Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
692
+ # SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
780
693
 
781
- * Fix regression when loading fixture files with symbol keys.
694
+ Example (for PostgreSQL with pg_hint_plan):
782
695
 
783
- Fixes #22584.
696
+ Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
697
+ # SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
784
698
 
785
- *Yves Senn*
699
+ See also:
786
700
 
787
- * Use `version` column as primary key for schema_migrations table because
788
- `schema_migrations` versions are guaranteed to be unique.
701
+ * https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
702
+ * https://pghintplan.osdn.jp/pg_hint_plan.html
703
+ * https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
704
+ * https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
705
+ * https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
789
706
 
790
- This makes it possible to use `update_attributes` on models that do
791
- not have a primary key.
707
+ *Ryuta Kamizono*
792
708
 
793
- *Richard Schneeman*
709
+ * Fix query attribute method on user-defined attribute to be aware of typecasted value.
794
710
 
795
- * Add short-hand methods for text and blob types in MySQL.
711
+ For example, the following code no longer return false as casted non-empty string:
796
712
 
797
- In Pg and Sqlite3, `:text` and `:binary` have variable unlimited length.
798
- But in MySQL, these have limited length for each types (ref #21591, #21619).
799
- This change adds short-hand methods for each text and blob types.
713
+ ```
714
+ class Post < ActiveRecord::Base
715
+ attribute :user_defined_text, :text
716
+ end
800
717
 
801
- Example:
718
+ Post.new(user_defined_text: "false").user_defined_text? # => true
719
+ ```
802
720
 
803
- create_table :foos do |t|
804
- t.tinyblob :tiny_blob
805
- t.mediumblob :medium_blob
806
- t.longblob :long_blob
807
- t.tinytext :tiny_text
808
- t.mediumtext :medium_text
809
- t.longtext :long_text
810
- end
721
+ *Yuji Kamijima*
811
722
 
812
- *Ryuta Kamizono*
723
+ * Quote empty ranges like other empty enumerables.
813
724
 
814
- * Take into account UTC offset when assigning string representation of
815
- timestamp with offset specified to attribute of time type.
725
+ *Patrick Rebsch*
816
726
 
817
- *Andrey Novikov*
727
+ * Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
728
+ allowing bulk inserts akin to the bulk updates provided by `update_all` and
729
+ bulk deletes by `delete_all`.
818
730
 
819
- * When calling `first` with a `limit` argument, return directly from the
820
- `loaded?` records if available.
731
+ Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
732
+ for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
733
+ for MySQL.
821
734
 
822
- *Ben Woosley*
735
+ *Bob Lail*
823
736
 
824
- * Deprecate sending the `offset` argument to `find_nth`. Please use the
825
- `offset` method on relation instead.
737
+ * Add `rails db:seed:replant` that truncates tables of each database
738
+ for current environment and loads the seeds.
826
739
 
827
- *Ben Woosley*
740
+ *bogdanvlviv*, *DHH*
828
741
 
829
- * Limit record touching to once per transaction.
742
+ * Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
830
743
 
831
- If you have a parent/grand-parent relation like:
744
+ *bogdanvlviv*
832
745
 
833
- Comment belongs_to :message, touch: true
834
- Message belongs_to :project, touch: true
835
- Project belongs_to :account, touch: true
746
+ * Deprecate mismatched collation comparison for uniqueness validator.
836
747
 
837
- When the lowest entry(`Comment`) is saved, now, it won't repeat the touch
838
- call multiple times for the parent records.
748
+ Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
749
+ To continue case sensitive comparison on the case insensitive column,
750
+ pass `case_sensitive: true` option explicitly to the uniqueness validator.
839
751
 
840
- Related #18606.
752
+ *Ryuta Kamizono*
841
753
 
842
- *arthurnn*
754
+ * Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
843
755
 
844
- * Order the result of `find(ids)` to match the passed array, if the relation
845
- has no explicit order defined.
756
+ Fixes #27340.
846
757
 
847
- Fixes #20338.
758
+ *Willian Gustavo Veiga*
848
759
 
849
- *Miguel Grazziotin*, *Matthew Draper*
760
+ * Add negative scopes for all enum values.
850
761
 
851
- * Omit default limit values in dumped schema. It's tidier, and if the defaults
852
- change in the future, we can address that via Migration API Versioning.
762
+ Example:
853
763
 
854
- *Jean Boussier*
764
+ class Post < ActiveRecord::Base
765
+ enum status: %i[ drafted active trashed ]
766
+ end
855
767
 
856
- * Support passing the schema name as a prefix to table name in
857
- `ConnectionAdapters::SchemaStatements#indexes`. Previously the prefix would
858
- be considered a full part of the index name, and only the schema in the
859
- current search path would be considered.
768
+ Post.not_drafted # => where.not(status: :drafted)
769
+ Post.not_active # => where.not(status: :active)
770
+ Post.not_trashed # => where.not(status: :trashed)
860
771
 
861
- *Grey Baker*
772
+ *DHH*
862
773
 
863
- * Ignore index name in `index_exists?` and `remove_index` when not passed a
864
- name to check for.
774
+ * Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
865
775
 
866
- *Grey Baker*
776
+ Fixes #35214.
867
777
 
868
- * Extract support for the legacy `mysql` database adapter from core. It will
869
- live on in a separate gem for now, but most users should just use `mysql2`.
778
+ *Juani Villarejo*
870
779
 
871
- *Abdelkader Boudih*
872
780
 
873
- * ApplicationRecord is a new superclass for all app models, analogous to app
874
- controllers subclassing ApplicationController instead of
875
- ActionController::Base. This gives apps a single spot to configure app-wide
876
- model behavior.
781
+ ## Rails 6.0.0.beta3 (March 11, 2019) ##
877
782
 
878
- Newly generated applications have `app/models/application_record.rb`
879
- present by default.
783
+ * No changes.
880
784
 
881
- *Genadi Samokovarov*
882
785
 
883
- * Version the API presented to migration classes, so we can change parameter
884
- defaults without breaking existing migrations, or forcing them to be
885
- rewritten through a deprecation cycle.
786
+ ## Rails 6.0.0.beta2 (February 25, 2019) ##
886
787
 
887
- New migrations specify the Rails version they were written for:
788
+ * Fix prepared statements caching to be enabled even when query caching is enabled.
888
789
 
889
- class AddStatusToOrders < ActiveRecord::Migration[5.0]
890
- def change
891
- # ...
892
- end
893
- end
790
+ *Ryuta Kamizono*
894
791
 
895
- *Matthew Draper*, *Ravil Bayramgalin*
792
+ * Ensure `update_all` series cares about optimistic locking.
896
793
 
897
- * Use bind params for `limit` and `offset`. This will generate significantly
898
- fewer prepared statements for common tasks like pagination. To support this
899
- change, passing a string containing a comma to `limit` has been deprecated,
900
- and passing an Arel node to `limit` is no longer supported.
794
+ *Ryuta Kamizono*
901
795
 
902
- Fixes #22250.
796
+ * Don't allow `where` with non numeric string matches to 0 values.
903
797
 
904
- *Sean Griffin*
798
+ *Ryuta Kamizono*
905
799
 
906
- * Introduce after_{create,update,delete}_commit callbacks.
800
+ * Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
907
801
 
908
- Before:
802
+ `destroy_by` allows relation to find all the records matching the condition and perform
803
+ `destroy_all` on the matched records.
909
804
 
910
- after_commit :add_to_index_later, on: :create
911
- after_commit :update_in_index_later, on: :update
912
- after_commit :remove_from_index_later, on: :destroy
805
+ Example:
913
806
 
914
- After:
807
+ Person.destroy_by(name: 'David')
808
+ Person.destroy_by(name: 'David', rating: 4)
915
809
 
916
- after_create_commit :add_to_index_later
917
- after_update_commit :update_in_index_later
918
- after_destroy_commit :remove_from_index_later
810
+ david = Person.find_by(name: 'David')
811
+ david.posts.destroy_by(id: [1, 2, 3])
919
812
 
920
- Fixes #22515.
813
+ `delete_by` allows relation to find all the records matching the condition and perform
814
+ `delete_all` on the matched records.
921
815
 
922
- *Genadi Samokovarov*
816
+ Example:
923
817
 
924
- * Respect the column default values for `inheritance_column` when
925
- instantiating records through the base class.
818
+ Person.delete_by(name: 'David')
819
+ Person.delete_by(name: 'David', rating: 4)
926
820
 
927
- Fixes #17121.
821
+ david = Person.find_by(name: 'David')
822
+ david.posts.delete_by(id: [1, 2, 3])
928
823
 
929
- Example:
824
+ *Abhay Nikam*
930
825
 
931
- # The schema of BaseModel has `t.string :type, default: 'SubType'`
932
- subtype = BaseModel.new
933
- assert_equals SubType, subtype.class
826
+ * Don't allow `where` with invalid value matches to nil values.
934
827
 
935
- *Kuldeep Aggarwal*
828
+ Fixes #33624.
936
829
 
937
- * Fix `rake db:structure:dump` on Postgres when multiple schemas are used.
830
+ *Ryuta Kamizono*
938
831
 
939
- Fixes #22346.
832
+ * SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
940
833
 
941
- *Nick Muerdter*, *ckoenig*
834
+ *Ryuta Kamizono*
942
835
 
943
- * Add schema dumping support for PostgreSQL geometric data types.
836
+ * Deprecate using class level querying methods if the receiver scope
837
+ regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
944
838
 
945
839
  *Ryuta Kamizono*
946
840
 
947
- * Except keys of `build_record`'s argument from `create_scope` in `initialize_attributes`.
841
+ * Allow applications to automatically switch connections.
948
842
 
949
- Fixes #21893.
843
+ Adds a middleware and configuration options that can be used in your
844
+ application to automatically switch between the writing and reading
845
+ database connections.
950
846
 
951
- *Yuichiro Kaneko*
847
+ `GET` and `HEAD` requests will read from the replica unless there was
848
+ a write in the last 2 seconds, otherwise they will read from the primary.
849
+ Non-get requests will always write to the primary. The middleware accepts
850
+ an argument for a Resolver class and an Operations class where you are able
851
+ to change how the auto-switcher works to be most beneficial for your
852
+ application.
952
853
 
953
- * Deprecate `connection.tables` on the SQLite3 and MySQL adapters.
954
- Also deprecate passing arguments to `#tables`.
955
- And deprecate `table_exists?`.
854
+ To use the middleware in your application you can use the following
855
+ configuration options:
956
856
 
957
- The `#tables` method of some adapters (mysql, mysql2, sqlite3) would return
958
- both tables and views while others (postgresql) just return tables. To make
959
- their behavior consistent, `#tables` will return only tables in the future.
857
+ ```
858
+ config.active_record.database_selector = { delay: 2.seconds }
859
+ config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
860
+ config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
861
+ ```
960
862
 
961
- The `#table_exists?` method would check both tables and views. To make
962
- their behavior consistent with `#tables`, `#table_exists?` will check only
963
- tables in the future.
863
+ To change the database selection strategy, pass a custom class to the
864
+ configuration options:
964
865
 
965
- *Yuichiro Kaneko*
866
+ ```
867
+ config.active_record.database_selector = { delay: 10.seconds }
868
+ config.active_record.database_resolver = MyResolver
869
+ config.active_record.database_resolver_context = MyResolver::MyCookies
870
+ ```
966
871
 
967
- * Improve support for non Active Record objects on `validates_associated`
872
+ *Eileen M. Uchitelle*
968
873
 
969
- Skipping `marked_for_destruction?` when the associated object does not responds
970
- to it make easier to validate virtual associations built on top of Active Model
971
- objects and/or serialized objects that implement a `valid?` instance method.
874
+ * MySQL: Support `:size` option to change text and blob size.
972
875
 
973
- *Kassio Borges*, *Lucas Mazza*
876
+ *Ryuta Kamizono*
974
877
 
975
- * Change connection management middleware to return a new response with
976
- a body proxy, rather than mutating the original.
878
+ * Make `t.timestamps` with precision by default.
977
879
 
978
- *Kevin Buchanan*
880
+ *Ryuta Kamizono*
979
881
 
980
- * Make `db:migrate:status` to render `1_some.rb` format migrate files.
981
882
 
982
- These files are in `db/migrate`:
883
+ ## Rails 6.0.0.beta1 (January 18, 2019) ##
983
884
 
984
- * 1_valid_people_have_last_names.rb
985
- * 20150819202140_irreversible_migration.rb
986
- * 20150823202140_add_admin_flag_to_users.rb
987
- * 20150823202141_migration_tests.rb
988
- * 2_we_need_reminders.rb
989
- * 3_innocent_jointable.rb
885
+ * Remove deprecated `#set_state` from the transaction object.
990
886
 
991
- Before:
887
+ *Rafael Mendonça França*
992
888
 
993
- $ bundle exec rake db:migrate:status
994
- ...
889
+ * Remove deprecated `#supports_statement_cache?` from the database adapters.
995
890
 
996
- Status Migration ID Migration Name
997
- --------------------------------------------------
998
- up 001 ********** NO FILE **********
999
- up 002 ********** NO FILE **********
1000
- up 003 ********** NO FILE **********
1001
- up 20150819202140 Irreversible migration
1002
- up 20150823202140 Add admin flag to users
1003
- up 20150823202141 Migration tests
891
+ *Rafael Mendonça França*
1004
892
 
1005
- After:
893
+ * Remove deprecated `#insert_fixtures` from the database adapters.
1006
894
 
1007
- $ bundle exec rake db:migrate:status
1008
- ...
895
+ *Rafael Mendonça França*
1009
896
 
1010
- Status Migration ID Migration Name
1011
- --------------------------------------------------
1012
- up 001 Valid people have last names
1013
- up 002 We need reminders
1014
- up 003 Innocent jointable
1015
- up 20150819202140 Irreversible migration
1016
- up 20150823202140 Add admin flag to users
1017
- up 20150823202141 Migration tests
897
+ * Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
1018
898
 
1019
- *Yuichiro Kaneko*
899
+ *Rafael Mendonça França*
1020
900
 
1021
- * Define `ActiveRecord::Sanitization.sanitize_sql_for_order` and use it inside
1022
- `preprocess_order_args`.
901
+ * Do not allow passing the column name to `sum` when a block is passed.
1023
902
 
1024
- *Yuichiro Kaneko*
903
+ *Rafael Mendonça França*
1025
904
 
1026
- * Allow bigint with default nil for avoiding auto increment primary key.
905
+ * Do not allow passing the column name to `count` when a block is passed.
1027
906
 
1028
- *Ryuta Kamizono*
907
+ *Rafael Mendonça França*
1029
908
 
1030
- * Remove `DEFAULT_CHARSET` and `DEFAULT_COLLATION` in `MySQLDatabaseTasks`.
909
+ * Remove delegation of missing methods in a relation to arel.
1031
910
 
1032
- We should omit the collation entirely rather than providing a default.
1033
- Then the choice is the responsibility of the server and MySQL distribution.
911
+ *Rafael Mendonça França*
1034
912
 
1035
- *Ryuta Kamizono*
913
+ * Remove delegation of missing methods in a relation to private methods of the class.
1036
914
 
1037
- * Alias `ActiveRecord::Relation#left_joins` to
1038
- `ActiveRecord::Relation#left_outer_joins`.
915
+ *Rafael Mendonça França*
1039
916
 
1040
- *Takashi Kokubun*
917
+ * Deprecate `config.active_record.sqlite3.represent_boolean_as_integer`.
1041
918
 
1042
- * Use advisory locking to raise a `ConcurrentMigrationError` instead of
1043
- attempting to migrate when another migration is currently running.
919
+ *Rafael Mendonça França*
1044
920
 
1045
- *Sam Davies*
921
+ * Change `SQLite3Adapter` to always represent boolean values as integers.
1046
922
 
1047
- * Added `ActiveRecord::Relation#left_outer_joins`.
923
+ *Rafael Mendonça França*
1048
924
 
1049
- Example:
925
+ * Remove ability to specify a timestamp name for `#cache_key`.
1050
926
 
1051
- User.left_outer_joins(:posts)
1052
- # => SELECT "users".* FROM "users" LEFT OUTER JOIN "posts" ON
1053
- "posts"."user_id" = "users"."id"
927
+ *Rafael Mendonça França*
1054
928
 
1055
- *Florian Thomas*
929
+ * Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
1056
930
 
1057
- * Support passing an array to `order` for SQL parameter sanitization.
931
+ *Rafael Mendonça França*
1058
932
 
1059
- *Aaron Suggs*
933
+ * Remove deprecated `expand_hash_conditions_for_aggregates`.
1060
934
 
1061
- * Avoid disabling errors on the PostgreSQL connection when enabling the
1062
- `standard_conforming_strings` setting. Errors were previously disabled because
1063
- the setting wasn't writable in Postgres 8.1 and didn't exist in earlier
1064
- versions. Now Rails only supports Postgres 8.2+ we're fine to assume the
1065
- setting exists. Disabling errors caused problems when using a connection
1066
- pooling tool like PgBouncer because it's not guaranteed to have the same
1067
- connection between calls to `execute` and it could leave the connection
1068
- with errors disabled.
935
+ *Rafael Mendonça França*
1069
936
 
1070
- Fixes #22101.
937
+ * Set polymorphic type column to NULL on `dependent: :nullify` strategy.
1071
938
 
1072
- *Harry Marr*
939
+ On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
1073
940
 
1074
- * Set `scope.reordering_value` to `true` if `:reordering`-values are specified.
941
+ *Laerti Papa*
1075
942
 
1076
- Fixes #21886.
943
+ * Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
1077
944
 
1078
- *Hiroaki Izu*
945
+ *Gannon McGibbon*
1079
946
 
1080
- * Add support for bidirectional destroy dependencies.
947
+ * Add support for endless ranges introduces in Ruby 2.6.
1081
948
 
1082
- Fixes #13609.
949
+ *Greg Navis*
1083
950
 
1084
- Example:
951
+ * Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
1085
952
 
1086
- class Content < ActiveRecord::Base
1087
- has_one :position, dependent: :destroy
1088
- end
953
+ *Ryuta Kamizono*
1089
954
 
1090
- class Position < ActiveRecord::Base
1091
- belongs_to :content, dependent: :destroy
1092
- end
955
+ * MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
1093
956
 
1094
- *Seb Jacobs*
957
+ Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
958
+ format for InnoDB tables. The default setting is `DYNAMIC`.
959
+ The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
1095
960
 
1096
- * Includes HABTM returns correct size now. It's caused by the join dependency
1097
- only instantiates one HABTM object because the join table hasn't a primary key.
961
+ *Ryuta Kamizono*
1098
962
 
1099
- Fixes #16032.
963
+ * Fix join table column quoting with SQLite.
1100
964
 
1101
- Examples:
965
+ *Gannon McGibbon*
1102
966
 
1103
- before:
967
+ * Allow disabling scopes generated by `ActiveRecord.enum`.
1104
968
 
1105
- Project.first.salaried_developers.size # => 3
1106
- Project.includes(:salaried_developers).first.salaried_developers.size # => 1
969
+ *Alfred Dominic*
1107
970
 
1108
- after:
971
+ * Ensure that `delete_all` on collection proxy returns affected count.
1109
972
 
1110
- Project.first.salaried_developers.size # => 3
1111
- Project.includes(:salaried_developers).first.salaried_developers.size # => 3
973
+ *Ryuta Kamizono*
1112
974
 
1113
- *Bigxiang*
975
+ * Reset scope after delete on collection association to clear stale offsets of removed records.
1114
976
 
1115
- * Add option to index errors in nested attributes.
977
+ *Gannon McGibbon*
1116
978
 
1117
- For models which have nested attributes, errors within those models will
1118
- now be indexed if `:index_errors` option is set to true when defining a
1119
- `has_many` relationship or by setting the configuration option
1120
- `config.active_record.index_nested_attribute_errors` to true.
979
+ * Add the ability to prevent writes to a database for the duration of a block.
1121
980
 
1122
- Example:
981
+ Allows the application to prevent writes to a database. This can be useful when
982
+ you're building out multiple databases and want to make sure you're not sending
983
+ writes when you want a read.
1123
984
 
1124
- class Guitar < ActiveRecord::Base
1125
- has_many :tuning_pegs, index_errors: true
1126
- accepts_nested_attributes_for :tuning_pegs
1127
- end
985
+ If `while_preventing_writes` is called and the query is considered a write
986
+ query the database will raise an exception regardless of whether the database
987
+ user is able to write.
1128
988
 
1129
- class TuningPeg < ActiveRecord::Base
1130
- belongs_to :guitar
1131
- validates_numericality_of :pitch
1132
- end
989
+ This is not meant to be a catch-all for write queries but rather a way to enforce
990
+ read-only queries without opening a second connection. One purpose of this is to
991
+ catch accidental writes, not all writes.
1133
992
 
1134
- # Before
1135
- guitar.errors["tuning_pegs.pitch"] = ["is not a number"]
993
+ *Eileen M. Uchitelle*
1136
994
 
1137
- # After
1138
- guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"]
995
+ * Allow aliased attributes to be used in `#update_columns` and `#update`.
1139
996
 
1140
- *Michael Probber*, *Terence Sun*
997
+ *Gannon McGibbon*
1141
998
 
1142
- * Exit with non-zero status for failed database rake tasks.
999
+ * Allow spaces in postgres table names.
1143
1000
 
1144
- *Jay Hayes*
1001
+ Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
1145
1002
 
1146
- * Queries such as `Computer.joins(:monitor).group(:status).count` will now be
1147
- interpreted as `Computer.joins(:monitor).group('computers.status').count`
1148
- so that when `Computer` and `Monitor` have both `status` columns we don't
1149
- have conflicts in projection.
1003
+ *Gannon McGibbon*
1150
1004
 
1151
- *Rafael Sales*
1005
+ * Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
1152
1006
 
1153
- * Add ability to default to `uuid` as primary key when generating database migrations.
1007
+ PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
1008
+ was passing for SQLite and MySQL, but failed for PostgreSQL:
1154
1009
 
1155
- Example:
1010
+ ```ruby
1011
+ class DeveloperName < ActiveRecord::Type::String
1012
+ def deserialize(value)
1013
+ "Developer: #{value}"
1014
+ end
1015
+ end
1156
1016
 
1157
- config.generators do |g|
1158
- g.orm :active_record, primary_key_type: :uuid
1159
- end
1017
+ class AttributedDeveloper < ActiveRecord::Base
1018
+ self.table_name = "developers"
1160
1019
 
1161
- *Jon McCartie*
1020
+ attribute :name, DeveloperName.new
1162
1021
 
1163
- * Don't cache arguments in `#find_by` if they are an `ActiveRecord::Relation`.
1022
+ self.ignored_columns += ["name"]
1023
+ end
1164
1024
 
1165
- Fixes #20817.
1025
+ developer = AttributedDeveloper.create
1026
+ developer.update_column :name, "name"
1166
1027
 
1167
- *Hiroaki Izu*
1028
+ loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
1029
+ puts loaded_developer.name # should be "Developer: name" but it's just "name"
1030
+ ```
1168
1031
 
1169
- * Qualify column name inserted by `group` in calculation.
1032
+ *Dmitry Tsepelev*
1170
1033
 
1171
- Giving `group` an unqualified column name now works, even if the relation
1172
- has `JOIN` with another table which also has a column of the name.
1034
+ * Make the implicit order column configurable.
1173
1035
 
1174
- *Soutaro Matsumoto*
1036
+ When calling ordered finder methods such as `first` or `last` without an
1037
+ explicit order clause, ActiveRecord sorts records by primary key. This can
1038
+ result in unpredictable and surprising behaviour when the primary key is
1039
+ not an auto-incrementing integer, for example when it's a UUID. This change
1040
+ makes it possible to override the column used for implicit ordering such
1041
+ that `first` and `last` will return more predictable results.
1175
1042
 
1176
- * Don't cache prepared statements containing an IN clause or a SQL literal, as
1177
- these queries will change often and are unlikely to have a cache hit.
1043
+ Example:
1178
1044
 
1179
- *Sean Griffin*
1045
+ class Project < ActiveRecord::Base
1046
+ self.implicit_order_column = "created_at"
1047
+ end
1180
1048
 
1181
- * Fix `rewhere` in a `has_many` association.
1049
+ *Tekin Suleyman*
1182
1050
 
1183
- Fixes #21955.
1051
+ * Bump minimum PostgreSQL version to 9.3.
1184
1052
 
1185
- *Josh Branchaud*, *Kal*
1053
+ *Yasuo Honda*
1186
1054
 
1187
- * `where` raises ArgumentError on unsupported types.
1055
+ * Values of enum are frozen, raising an error when attempting to modify them.
1188
1056
 
1189
- Fixes #20473.
1057
+ *Emmanuel Byrd*
1190
1058
 
1191
- *Jake Worth*
1059
+ * Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
1192
1060
 
1193
- * Add an immutable string type to help reduce memory usage for apps which do
1194
- not need mutation detection on strings.
1061
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
1195
1062
 
1196
- *Sean Griffin*
1063
+ `ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
1197
1064
 
1198
- * Give `ActiveRecord::Relation#update` its own deprecation warning when
1199
- passed an `ActiveRecord::Base` instance.
1065
+ Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
1200
1066
 
1201
- Fixes #21945.
1067
+ Example:
1202
1068
 
1203
- *Ted Johansson*
1069
+ ```
1070
+ class MySubclassedError < ActiveRecord::StatementInvalid
1071
+ def initialize(message, sql:, binds:)
1072
+ super(message, sql: sql, binds: binds)
1073
+ end
1074
+ end
1075
+ ```
1204
1076
 
1205
- * Make it possible to pass `:to_table` when adding a foreign key through
1206
- `add_reference`.
1077
+ *Gannon McGibbon*
1207
1078
 
1208
- Fixes #21563.
1079
+ * Add an `:if_not_exists` option to `create_table`.
1209
1080
 
1210
- *Yves Senn*
1081
+ Example:
1211
1082
 
1212
- * No longer pass deprecated option `-i` to `pg_dump`.
1083
+ create_table :posts, if_not_exists: true do |t|
1084
+ t.string :title
1085
+ end
1213
1086
 
1214
- *Paul Sadauskas*
1087
+ That would execute:
1215
1088
 
1216
- * Concurrent `AR::Base#increment!` and `#decrement!` on the same record
1217
- are all reflected in the database rather than overwriting each other.
1089
+ CREATE TABLE IF NOT EXISTS posts (
1090
+ ...
1091
+ )
1218
1092
 
1219
- *Bogdan Gusiev*
1093
+ If the table already exists, `if_not_exists: false` (the default) raises an
1094
+ exception whereas `if_not_exists: true` does nothing.
1220
1095
 
1221
- * Avoid leaking the first relation we call `first` on, per model.
1096
+ *fatkodima*, *Stefan Kanev*
1222
1097
 
1223
- Fixes #21921.
1098
+ * Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
1224
1099
 
1225
- *Matthew Draper*, *Jean Boussier*
1100
+ *Christophe Maximin*
1226
1101
 
1227
- * Remove unused `pk_and_sequence_for` in `AbstractMysqlAdapter`.
1102
+ * Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
1228
1103
 
1229
- *Ryuta Kamizono*
1104
+ *Gannon McGibbon*
1230
1105
 
1231
- * Allow fixtures files to set the model class in the YAML file itself.
1106
+ * `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
1107
+ if the attribute does not exist.
1232
1108
 
1233
- To load the fixtures file `accounts.yml` as the `User` model, use:
1109
+ *Sean Griffin*
1234
1110
 
1235
- _fixture:
1236
- model_class: User
1237
- david:
1238
- name: David
1111
+ * Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
1239
1112
 
1240
- Fixes #9516.
1113
+ ````
1114
+ User.connected_to(database: { writing: "postgres://foo" }) do
1115
+ User.create!(name: "Gannon")
1116
+ end
1241
1117
 
1242
- *Roque Pinel*
1118
+ config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
1119
+ User.connected_to(database: { reading: config }) do
1120
+ User.count
1121
+ end
1122
+ ````
1243
1123
 
1244
- * Don't require a database connection to load a class which uses acceptance
1245
- validations.
1124
+ *Gannon McGibbon*
1246
1125
 
1247
- *Sean Griffin*
1126
+ * Support default expression for MySQL.
1248
1127
 
1249
- * Correctly apply `unscope` when preloading through associations.
1128
+ MySQL 8.0.13 and higher supports default value to be a function or expression.
1250
1129
 
1251
- *Jimmy Bourassa*
1130
+ https://dev.mysql.com/doc/refman/8.0/en/create-table.html
1252
1131
 
1253
- * Fixed taking precision into count when assigning a value to timestamp attribute.
1132
+ *Ryuta Kamizono*
1254
1133
 
1255
- Timestamp column can have less precision than ruby timestamp
1256
- In result in how big a fraction of a second can be stored in the
1257
- database.
1134
+ * Support expression indexes for MySQL.
1258
1135
 
1136
+ MySQL 8.0.13 and higher supports functional key parts that index
1137
+ expression values rather than column or column prefix values.
1259
1138
 
1260
- m = Model.create!
1261
- m.created_at.usec == m.reload.created_at.usec # => false
1262
- # due to different precision in Time.now and database column
1139
+ https://dev.mysql.com/doc/refman/8.0/en/create-index.html
1263
1140
 
1264
- If the precision is low enough, (mysql default is 0, so it is always low
1265
- enough by default) the value changes when model is reloaded from the
1266
- database. This patch fixes that issue ensuring that any timestamp
1267
- assigned as an attribute is converted to column precision under the
1268
- attribute.
1141
+ *Ryuta Kamizono*
1269
1142
 
1270
- *Bogdan Gusiev*
1143
+ * Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
1271
1144
 
1272
- * Introduce `connection.data_sources` and `connection.data_source_exists?`.
1273
- These methods determine what relations can be used to back Active Record
1274
- models (usually tables and views).
1145
+ Fixes #33056.
1275
1146
 
1276
- Also deprecate `SchemaCache#tables`, `SchemaCache#table_exists?` and
1277
- `SchemaCache#clear_table_cache!` in favor of their new data source
1278
- counterparts.
1147
+ *Federico Martinez*
1279
1148
 
1280
- *Yves Senn*, *Matthew Draper*
1149
+ * Add basic API for connection switching to support multiple databases.
1281
1150
 
1282
- * Add `ActiveRecord::Base.ignored_columns` to make some columns
1283
- invisible from Active Record.
1151
+ 1) Adds a `connects_to` method for models to connect to multiple databases. Example:
1284
1152
 
1285
- *Jean Boussier*
1153
+ ```
1154
+ class AnimalsModel < ApplicationRecord
1155
+ self.abstract_class = true
1286
1156
 
1287
- * `ActiveRecord::Tasks::MySQLDatabaseTasks` fails if shellout to
1288
- mysql commands (like `mysqldump`) is not successful.
1157
+ connects_to database: { writing: :animals_primary, reading: :animals_replica }
1158
+ end
1289
1159
 
1290
- *Steve Mitchell*
1160
+ class Dog < AnimalsModel
1161
+ # connected to both the animals_primary db for writing and the animals_replica for reading
1162
+ end
1163
+ ```
1291
1164
 
1292
- * Ensure `select` quotes aliased attributes, even when using `from`.
1165
+ 2) Adds a `connected_to` block method for switching connection roles or connecting to
1166
+ a database that the model didn't connect to. Connecting to the database in this block is
1167
+ useful when you have another defined connection, for example `slow_replica` that you don't
1168
+ want to connect to by default but need in the console, or a specific code block.
1293
1169
 
1294
- Fixes #21488.
1170
+ ```
1171
+ ActiveRecord::Base.connected_to(role: :reading) do
1172
+ Dog.first # finds dog from replica connected to AnimalsBase
1173
+ Book.first # doesn't have a reading connection, will raise an error
1174
+ end
1175
+ ```
1295
1176
 
1296
- *Sean Griffin*, *@johanlunds*
1177
+ ```
1178
+ ActiveRecord::Base.connected_to(database: :slow_replica) do
1179
+ SlowReplicaModel.first # if the db config has a slow_replica configuration this will be used to do the lookup, otherwise this will throw an exception
1180
+ end
1181
+ ```
1297
1182
 
1298
- * MySQL: support `unsigned` numeric data types.
1183
+ *Eileen M. Uchitelle*
1299
1184
 
1300
- Example:
1185
+ * Enum raises on invalid definition values
1301
1186
 
1302
- create_table :foos do |t|
1303
- t.unsigned_integer :quantity
1304
- t.unsigned_bigint :total
1305
- t.unsigned_float :percentage
1306
- t.unsigned_decimal :price, precision: 10, scale: 2
1307
- end
1187
+ When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
1188
+ commit checks that only valid definition values are provided, those can
1189
+ be a Hash, an array of Symbols or an array of Strings. Otherwise it
1190
+ raises an `ArgumentError`.
1308
1191
 
1309
- The `unsigned: true` option may be used for the primary key:
1192
+ Fixes #33961
1310
1193
 
1311
- create_table :foos, id: :bigint, unsigned: true do |t|
1312
-
1313
- end
1194
+ *Alberto Almagro*
1314
1195
 
1315
- *Ryuta Kamizono*
1196
+ * Reloading associations now clears the Query Cache like `Persistence#reload` does.
1316
1197
 
1317
- * Add `#views` and `#view_exists?` methods on connection adapters.
1198
+ ```
1199
+ class Post < ActiveRecord::Base
1200
+ has_one :category
1201
+ belongs_to :author
1202
+ has_many :comments
1203
+ end
1204
+
1205
+ # Each of the following will now clear the query cache.
1206
+ post.reload_category
1207
+ post.reload_author
1208
+ post.comments.reload
1209
+ ```
1318
1210
 
1319
- *Ryuta Kamizono*
1211
+ *Christophe Maximin*
1320
1212
 
1321
- * Correctly dump composite primary key.
1213
+ * Added `index` option for `change_table` migration helpers.
1214
+ With this change you can create indexes while adding new
1215
+ columns into the existing tables.
1322
1216
 
1323
1217
  Example:
1324
1218
 
1325
- create_table :barcodes, primary_key: ["region", "code"] do |t|
1326
- t.string :region
1327
- t.integer :code
1219
+ change_table(:languages) do |t|
1220
+ t.string :country_code, index: true
1328
1221
  end
1329
1222
 
1330
- *Ryuta Kamizono*
1223
+ *Mehmet Emin İNAÇ*
1331
1224
 
1332
- * Lookup the attribute name for `restrict_with_error` messages on the
1333
- model class that defines the association.
1225
+ * Fix `transaction` reverting for migrations.
1334
1226
 
1335
- *kuboon*, *Ronak Jangir*
1227
+ Before: Commands inside a `transaction` in a reverted migration ran uninverted.
1228
+ Now: This change fixes that by reverting commands inside `transaction` block.
1336
1229
 
1337
- * Correct query for PostgreSQL 8.2 compatibility.
1230
+ *fatkodima*, *David Verhasselt*
1338
1231
 
1339
- *Ben Murphy*, *Matthew Draper*
1232
+ * Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
1340
1233
 
1341
- * `bin/rails db:migrate` uses
1342
- `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of
1343
- `Migrator.migrations_paths`.
1234
+ *Gannon McGibbon*, *Max Albrecht*
1344
1235
 
1345
- *Tobias Bielohlawek*
1236
+ * Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
1237
+
1238
+ *Gannon McGibbon*
1346
1239
 
1347
- * Support dropping indexes concurrently in PostgreSQL.
1240
+ * Don't update counter cache unless the record is actually saved.
1348
1241
 
1349
- See http://www.postgresql.org/docs/9.4/static/sql-dropindex.html for more
1350
- details.
1242
+ Fixes #31493, #33113, #33117.
1351
1243
 
1352
- *Grey Baker*
1244
+ *Ryuta Kamizono*
1353
1245
 
1354
- * Deprecate passing conditions to `ActiveRecord::Relation#delete_all`
1355
- and `ActiveRecord::Relation#destroy_all`.
1246
+ * Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
1356
1247
 
1357
- *Wojciech Wnętrzak*
1248
+ *Gannon McGibbon*, *Kevin Cheng*
1358
1249
 
1359
- * Instantiating an AR model with `ActionController::Parameters` now raises
1360
- an `ActiveModel::ForbiddenAttributesError` if the parameters include a
1361
- `type` field that has not been explicitly permitted. Previously, the
1362
- `type` field was simply ignored in the same situation.
1250
+ * SQLite3 adapter supports expression indexes.
1363
1251
 
1364
- *Prem Sichanugrist*
1252
+ ```
1253
+ create_table :users do |t|
1254
+ t.string :email
1255
+ end
1365
1256
 
1366
- * PostgreSQL, `create_schema`, `drop_schema` and `rename_table` now quote
1367
- schema names.
1257
+ add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
1258
+ ```
1368
1259
 
1369
- Fixes #21418.
1260
+ *Gray Kemmey*
1370
1261
 
1371
- Example:
1262
+ * Allow subclasses to redefine autosave callbacks for associated records.
1372
1263
 
1373
- create_schema("my.schema")
1374
- # CREATE SCHEMA "my.schema";
1264
+ Fixes #33305.
1375
1265
 
1376
- *Yves Senn*
1266
+ *Andrey Subbota*
1377
1267
 
1378
- * PostgreSQL, add `:if_exists` option to `#drop_schema`. This makes it
1379
- possible to drop a schema that might exist without raising an exception if
1380
- it doesn't.
1268
+ * Bump minimum MySQL version to 5.5.8.
1381
1269
 
1382
- *Yves Senn*
1270
+ *Yasuo Honda*
1383
1271
 
1384
- * Only try to nullify has_one target association if the record is persisted.
1272
+ * Use MySQL utf8mb4 character set by default.
1385
1273
 
1386
- Fixes #21223.
1274
+ `utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
1275
+ The previous default 3-Byte encoding character set `utf8` is not enough to support them.
1387
1276
 
1388
- *Agis Anastasopoulos*
1277
+ *Yasuo Honda*
1389
1278
 
1390
- * Uniqueness validator raises descriptive error when running on a persisted
1391
- record without primary key.
1279
+ * Fix duplicated record creation when using nested attributes with `create_with`.
1392
1280
 
1393
- Fixes #21304.
1281
+ *Darwin Wu*
1394
1282
 
1395
- *Yves Senn*
1283
+ * Configuration item `config.filter_parameters` could also filter out
1284
+ sensitive values of database columns when calling `#inspect`.
1285
+ We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
1286
+ specify sensitive attributes to specific model.
1396
1287
 
1397
- * Add a native JSON data type support in MySQL.
1288
+ ```
1289
+ Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
1290
+ Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
1291
+ SecureAccount.filter_attributes += [:name]
1292
+ SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
1293
+ ```
1398
1294
 
1399
- Example:
1295
+ *Zhang Kang*, *Yoshiyuki Kinjo*
1400
1296
 
1401
- create_table :json_data_type do |t|
1402
- t.json :settings
1403
- end
1297
+ * Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
1298
+ `indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
1299
+ and `joins_per_query` methods in `DatabaseLimits`.
1404
1300
 
1405
1301
  *Ryuta Kamizono*
1406
1302
 
1407
- * Descriptive error message when fixtures contain a missing column.
1303
+ * `ActiveRecord::Base.configurations` now returns an object.
1408
1304
 
1409
- Fixes #21201.
1305
+ `ActiveRecord::Base.configurations` used to return a hash, but this
1306
+ is an inflexible data model. In order to improve multiple-database
1307
+ handling in Rails, we've changed this to return an object. Some methods
1308
+ are provided to make the object behave hash-like in order to ease the
1309
+ transition process. Since most applications don't manipulate the hash
1310
+ we've decided to add backwards-compatible functionality that will throw
1311
+ a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
1312
+ will use the new version internally and externally.
1410
1313
 
1411
- *Yves Senn*
1314
+ For example, the following `database.yml`:
1412
1315
 
1413
- * `ActiveRecord::Tasks::PostgreSQLDatabaseTasks` fail if shellout to
1414
- postgresql commands (like `pg_dump`) is not successful.
1415
-
1416
- *Bryan Paxton*, *Nate Berkopec*
1316
+ ```
1317
+ development:
1318
+ adapter: sqlite3
1319
+ database: db/development.sqlite3
1320
+ ```
1417
1321
 
1418
- * Add `ActiveRecord::Relation#in_batches` to work with records and relations
1419
- in batches.
1322
+ Used to become a hash:
1420
1323
 
1421
- Available options are `of` (batch size), `load`, `start`, and `finish`.
1324
+ ```
1325
+ { "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
1326
+ ```
1422
1327
 
1423
- Examples:
1328
+ Is now converted into the following object:
1424
1329
 
1425
- Person.in_batches.each_record(&:party_all_night!)
1426
- Person.in_batches.update_all(awesome: true)
1427
- Person.in_batches.delete_all
1428
- Person.in_batches.each do |relation|
1429
- relation.delete_all
1430
- sleep 10 # Throttles the delete queries
1431
- end
1330
+ ```
1331
+ #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
1332
+ #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
1333
+ @spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
1334
+ ]
1335
+ ```
1432
1336
 
1433
- Fixes #20933.
1337
+ Iterating over the database configurations has also changed. Instead of
1338
+ calling hash methods on the `configurations` hash directly, a new method `configs_for` has
1339
+ been provided that allows you to select the correct configuration. `env_name` and
1340
+ `spec_name` arguments are optional. For example, these return an array of
1341
+ database config objects for the requested environment and a single database config object
1342
+ will be returned for the requested environment and specification name respectively.
1434
1343
 
1435
- *Sina Siadat*
1344
+ ```
1345
+ ActiveRecord::Base.configurations.configs_for(env_name: "development")
1346
+ ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
1347
+ ```
1436
1348
 
1437
- * Added methods for PostgreSQL geometric data types to use in migrations.
1349
+ *Eileen M. Uchitelle*, *Aaron Patterson*
1438
1350
 
1439
- Example:
1351
+ * Add database configuration to disable advisory locks.
1440
1352
 
1441
- create_table :foo do |t|
1442
- t.line :foo_line
1443
- t.lseg :foo_lseg
1444
- t.box :foo_box
1445
- t.path :foo_path
1446
- t.polygon :foo_polygon
1447
- t.circle :foo_circle
1448
- end
1353
+ ```
1354
+ production:
1355
+ adapter: postgresql
1356
+ advisory_locks: false
1357
+ ```
1449
1358
 
1450
- *Mehmet Emin İNAÇ*
1359
+ *Guo Xiang*
1451
1360
 
1452
- * Add `cache_key` to `ActiveRecord::Relation`.
1361
+ * SQLite3 adapter `alter_table` method restores foreign keys.
1453
1362
 
1454
- Example:
1363
+ *Yasuo Honda*
1455
1364
 
1456
- @users = User.where("name like ?", "%Alberto%")
1457
- @users.cache_key
1458
- # => "/users/query-5942b155a43b139f2471b872ac54251f-3-20150714212107656125000"
1365
+ * Allow `:to_table` option to `invert_remove_foreign_key`.
1459
1366
 
1460
- *Alberto Fernández-Capel*
1367
+ Example:
1461
1368
 
1462
- * Properly allow uniqueness validations on primary keys.
1369
+ remove_foreign_key :accounts, to_table: :owners
1463
1370
 
1464
- Fixes #20966.
1371
+ *Nikolay Epifanov*, *Rich Chen*
1465
1372
 
1466
- *Sean Griffin*, *presskey*
1373
+ * Add environment & load_config dependency to `bin/rake db:seed` to enable
1374
+ seed load in environments without Rails and custom DB configuration
1467
1375
 
1468
- * Don't raise an error if an association failed to destroy when `destroy` was
1469
- called on the parent (as opposed to `destroy!`).
1376
+ *Tobias Bielohlawek*
1470
1377
 
1471
- Fixes #20991.
1378
+ * Fix default value for mysql time types with specified precision.
1472
1379
 
1473
- *Sean Griffin*
1380
+ *Nikolay Kondratyev*
1474
1381
 
1475
- * `ActiveRecord::RecordNotFound` modified to store model name, primary_key and
1476
- id of the caller model. It allows the catcher of this exception to make
1477
- a better decision to what to do with it.
1382
+ * Fix `touch` option to behave consistently with `Persistence#touch` method.
1478
1383
 
1479
- Example:
1384
+ *Ryuta Kamizono*
1480
1385
 
1481
- class SomeAbstractController < ActionController::Base
1482
- rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404
1386
+ * Migrations raise when duplicate column definition.
1483
1387
 
1484
- private def redirect_to_404(e)
1485
- return redirect_to(posts_url) if e.model == 'Post'
1486
- raise
1487
- end
1488
- end
1388
+ Fixes #33024.
1489
1389
 
1490
- *Sameer Rahmani*
1390
+ *Federico Martinez*
1491
1391
 
1492
- * Deprecate the keys for association `restrict_dependent_destroy` errors in favor
1493
- of new key names.
1392
+ * Bump minimum SQLite version to 3.8
1494
1393
 
1495
- Previously `has_one` and `has_many` associations were using the
1496
- `one` and `many` keys respectively. Both of these keys have special
1497
- meaning in I18n (they are considered to be pluralizations) so by
1498
- renaming them to `has_one` and `has_many` we make the messages more explicit
1499
- and most importantly they don't clash with linguistical systems that need to
1500
- validate translation keys (and their pluralizations).
1394
+ *Yasuo Honda*
1501
1395
 
1502
- The `:'restrict_dependent_destroy.one'` key should be replaced with
1503
- `:'restrict_dependent_destroy.has_one'`, and `:'restrict_dependent_destroy.many'`
1504
- with `:'restrict_dependent_destroy.has_many'`.
1396
+ * Fix parent record should not get saved with duplicate children records.
1505
1397
 
1506
- *Roque Pinel*, *Christopher Dell*
1398
+ Fixes #32940.
1507
1399
 
1508
- * Fix state being carried over from previous transaction.
1400
+ *Santosh Wadghule*
1509
1401
 
1510
- Considering the following example where `name` is a required attribute.
1511
- Before we had `new_record?` returning `true` for a persisted record:
1402
+ * Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
1512
1403
 
1513
- author = Author.create! name: 'foo'
1514
- author.name = nil
1515
- author.save # => false
1516
- author.new_record? # => true
1404
+ *Brian Durand*
1517
1405
 
1518
- Fixes #20824.
1406
+ * Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
1407
+ use loaded association ids if present.
1519
1408
 
1520
- *Roque Pinel*
1409
+ *Graham Turner*
1521
1410
 
1522
- * Correctly ignore `mark_for_destruction` when `autosave` isn't set to `true`
1523
- when validating associations.
1411
+ * Add support to preload associations of polymorphic associations when not all the records have the requested associations.
1524
1412
 
1525
- Fixes #20882.
1413
+ *Dana Sherson*
1526
1414
 
1527
- *Sean Griffin*
1415
+ * Add `touch_all` method to `ActiveRecord::Relation`.
1528
1416
 
1529
- * Fix a bug where counter_cache doesn't always work with polymorphic
1530
- relations.
1417
+ Example:
1531
1418
 
1532
- Fixes #16407.
1419
+ Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
1533
1420
 
1534
- *Stefan Kanev*, *Sean Griffin*
1421
+ *fatkodima*, *duggiefresh*
1535
1422
 
1536
- * Ensure that cyclic associations with autosave don't cause duplicate errors
1537
- to be added to the parent record.
1538
-
1539
- Fixes #20874.
1540
-
1541
- *Sean Griffin*
1542
-
1543
- * Ensure that `ActionController::Parameters` can still be passed to nested
1544
- attributes.
1545
-
1546
- Fixes #20922.
1547
-
1548
- *Sean Griffin*
1549
-
1550
- * Deprecate force association reload by passing a truthy argument to
1551
- association method.
1552
-
1553
- For collection association, you can call `#reload` on association proxy to
1554
- force a reload:
1555
-
1556
- @user.posts.reload # Instead of @user.posts(true)
1557
-
1558
- For singular association, you can call `#reload` on the parent object to
1559
- clear its association cache then call the association method:
1560
-
1561
- @user.reload.profile # Instead of @user.profile(true)
1562
-
1563
- Passing a truthy argument to force association to reload will be removed in
1564
- Rails 5.1.
1565
-
1566
- *Prem Sichanugrist*
1567
-
1568
- * Replaced `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch`
1569
- from the concurrent-ruby gem.
1570
-
1571
- *Jerry D'Antonio*
1572
-
1573
- * Fix through associations using scopes having the scope merged multiple
1574
- times.
1575
-
1576
- Fixes #20721.
1577
- Fixes #20727.
1578
-
1579
- *Sean Griffin*
1580
-
1581
- * `ActiveRecord::Base.dump_schema_after_migration` applies migration tasks
1582
- other than `db:migrate`. (eg. `db:rollback`, `db:migrate:dup`, ...)
1583
-
1584
- Fixes #20743.
1585
-
1586
- *Yves Senn*
1587
-
1588
- * Add alternate syntax to make `change_column_default` reversible.
1589
-
1590
- User can pass in `:from` and `:to` to make `change_column_default` command
1591
- become reversible.
1592
-
1593
- Example:
1594
-
1595
- change_column_default :posts, :status, from: nil, to: "draft"
1596
- change_column_default :users, :authorized, from: true, to: false
1597
-
1598
- *Prem Sichanugrist*
1599
-
1600
- * Prevent error when using `force_reload: true` on an unassigned polymorphic
1601
- belongs_to association.
1602
-
1603
- Fixes #20426.
1604
-
1605
- *James Dabbs*
1606
-
1607
- * Correctly raise `ActiveRecord::AssociationTypeMismatch` when assigning
1608
- a wrong type to a namespaced association.
1609
-
1610
- Fixes #20545.
1611
-
1612
- *Diego Carrion*
1613
-
1614
- * `validates_absence_of` respects `marked_for_destruction?`.
1615
-
1616
- Fixes #20449.
1617
-
1618
- *Yves Senn*
1619
-
1620
- * Include the `Enumerable` module in `ActiveRecord::Relation`
1621
-
1622
- *Sean Griffin*, *bogdan*
1623
-
1624
- * Use `Enumerable#sum` in `ActiveRecord::Relation` if a block is given.
1625
-
1626
- *Sean Griffin*
1627
-
1628
- * Let `WITH` queries (Common Table Expressions) be explainable.
1629
-
1630
- *Vladimir Kochnev*
1631
-
1632
- * Make `remove_index :table, :column` reversible.
1633
-
1634
- *Yves Senn*
1635
-
1636
- * Fixed an error which would occur in dirty checking when calling
1637
- `update_attributes` from a getter.
1638
-
1639
- Fixes #20531.
1640
-
1641
- *Sean Griffin*
1642
-
1643
- * Make `remove_foreign_key` reversible. Any foreign key options must be
1644
- specified, similar to `remove_column`.
1645
-
1646
- *Aster Ryan*
1647
-
1648
- * Add `:_prefix` and `:_suffix` options to `enum` definition.
1649
-
1650
- Fixes #17511, #17415.
1651
-
1652
- *Igor Kapkov*
1653
-
1654
- * Correctly handle decimal arrays with defaults in the schema dumper.
1655
-
1656
- Fixes #20515.
1657
-
1658
- *Sean Griffin*, *jmondo*
1659
-
1660
- * Deprecate the PostgreSQL `:point` type in favor of a new one which will return
1661
- `Point` objects instead of an `Array`
1662
-
1663
- *Sean Griffin*
1664
-
1665
- * Ensure symbols passed to `ActiveRecord::Relation#select` are always treated
1666
- as columns.
1667
-
1668
- Fixes #20360.
1669
-
1670
- *Sean Griffin*
1671
-
1672
- * Do not set `sql_mode` if `strict: :default` is specified.
1673
-
1674
- # config/database.yml
1675
- production:
1676
- adapter: mysql2
1677
- database: foo_prod
1678
- user: foo
1679
- strict: :default
1680
-
1681
- *Ryuta Kamizono*
1682
-
1683
- * Allow proc defaults to be passed to the attributes API. See documentation
1684
- for examples.
1685
-
1686
- *Sean Griffin*, *Kir Shatrov*
1687
-
1688
- * SQLite: `:collation` support for string and text columns.
1689
-
1690
- Example:
1691
-
1692
- create_table :foo do |t|
1693
- t.string :string_nocase, collation: 'NOCASE'
1694
- t.text :text_rtrim, collation: 'RTRIM'
1695
- end
1696
-
1697
- add_column :foo, :title, :string, collation: 'RTRIM'
1698
-
1699
- change_column :foo, :title, :string, collation: 'NOCASE'
1700
-
1701
- *Akshay Vishnoi*
1702
-
1703
- * Allow the use of symbols or strings to specify enum values in test
1704
- fixtures:
1705
-
1706
- awdr:
1707
- title: "Agile Web Development with Rails"
1708
- status: :proposed
1709
-
1710
- *George Claghorn*
1711
-
1712
- * Clear query cache when `ActiveRecord::Base#reload` is called.
1713
-
1714
- *Shane Hender, Pierre Nespo*
1715
-
1716
- * Include stored procedures and function on the MySQL structure dump.
1717
-
1718
- *Jonathan Worek*
1719
-
1720
- * Pass `:extend` option for `has_and_belongs_to_many` associations to the
1721
- underlying `has_many :through`.
1722
-
1723
- *Jaehyun Shin*
1724
-
1725
- * Deprecate `Relation#uniq` use `Relation#distinct` instead.
1726
-
1727
- See #9683.
1728
-
1729
- *Yves Senn*
1730
-
1731
- * Allow single table inheritance instantiation to work when storing
1732
- demodulized class names.
1733
-
1734
- *Alex Robbin*
1735
-
1736
- * Correctly pass MySQL options when using `structure_dump` or
1737
- `structure_load`.
1738
-
1739
- Specifically, it fixes an issue when using SSL authentication.
1740
-
1741
- *Alex Coomans*
1742
-
1743
- * Correctly dump `:options` on `create_table` for MySQL.
1744
-
1745
- *Ryuta Kamizono*
1746
-
1747
- * PostgreSQL: `:collation` support for string and text columns.
1748
-
1749
- Example:
1750
-
1751
- create_table :foos do |t|
1752
- t.string :string_en, collation: 'en_US.UTF-8'
1753
- t.text :text_ja, collation: 'ja_JP.UTF-8'
1754
- end
1755
-
1756
- *Ryuta Kamizono*
1757
-
1758
- * Remove `ActiveRecord::Serialization::XmlSerializer` from core.
1759
-
1760
- *Zachary Scott*
1761
-
1762
- * Make `unscope` aware of "less than" and "greater than" conditions.
1763
-
1764
- *TAKAHASHI Kazuaki*
1765
-
1766
- * `find_by` and `find_by!` raise `ArgumentError` when called without
1767
- arguments.
1768
-
1769
- *Kohei Suzuki*
1770
-
1771
- * Revert behavior of `db:schema:load` back to loading the full
1772
- environment. This ensures that initializers are run.
1773
-
1774
- Fixes #19545.
1775
-
1776
- *Yves Senn*
1777
-
1778
- * Fix missing index when using `timestamps` with the `index` option.
1779
-
1780
- The `index` option used with `timestamps` should be passed to both
1781
- `column` definitions for `created_at` and `updated_at` rather than just
1782
- the first.
1783
-
1784
- *Paul Mucur*
1785
-
1786
- * Rename `:class` to `:anonymous_class` in association options.
1787
-
1788
- Fixes #19659.
1789
-
1790
- *Andrew White*
1791
-
1792
- * Autosave existing records on a has many through association when the parent
1793
- is new.
1794
-
1795
- Fixes #19782.
1796
-
1797
- *Sean Griffin*
1798
-
1799
- * Fixed a bug where uniqueness validations would error on out of range values,
1800
- even if an validation should have prevented it from hitting the database.
1801
-
1802
- *Andrey Voronkov*
1803
-
1804
- * MySQL: `:charset` and `:collation` support for string and text columns.
1805
-
1806
- Example:
1807
-
1808
- create_table :foos do |t|
1809
- t.string :string_utf8_bin, charset: 'utf8', collation: 'utf8_bin'
1810
- t.text :text_ascii, charset: 'ascii'
1811
- end
1812
-
1813
- *Ryuta Kamizono*
1814
-
1815
- * Foreign key related methods in the migration DSL respect
1816
- `ActiveRecord::Base.pluralize_table_names = false`.
1817
-
1818
- Fixes #19643.
1819
-
1820
- *Mehmet Emin İNAÇ*
1821
-
1822
- * Reduce memory usage from loading types on PostgreSQL.
1823
-
1824
- Fixes #19578.
1825
-
1826
- *Sean Griffin*
1827
-
1828
- * Add `config.active_record.warn_on_records_fetched_greater_than` option.
1829
-
1830
- When set to an integer, a warning will be logged whenever a result set
1831
- larger than the specified size is returned by a query.
1832
-
1833
- Fixes #16463.
1834
-
1835
- *Jason Nochlin*
1836
-
1837
- * Ignore `.psqlrc` when loading database structure.
1838
-
1839
- *Jason Weathered*
1840
-
1841
- * Fix referencing wrong table aliases while joining tables of has many through
1842
- association (only when calling calculation methods).
1843
-
1844
- Fixes #19276.
1845
-
1846
- *pinglamb*
1847
-
1848
- * Correctly persist a serialized attribute that has been returned to
1849
- its default value by an in-place modification.
1850
-
1851
- Fixes #19467.
1852
-
1853
- *Matthew Draper*
1854
-
1855
- * Fix generating the schema file when using PostgreSQL `BigInt[]` data type.
1856
- Previously the `limit: 8` was not coming through, and this caused it to
1857
- become `Int[]` data type after rebuilding from the schema.
1858
-
1859
- Fixes #19420.
1860
-
1861
- *Jake Waller*
1862
-
1863
- * Reuse the `CollectionAssociation#reader` cache when the foreign key is
1864
- available prior to save.
1865
-
1866
- *Ben Woosley*
1867
-
1868
- * Add `config.active_record.dump_schemas` to fix `db:structure:dump`
1869
- when using schema_search_path and PostgreSQL extensions.
1870
-
1871
- Fixes #17157.
1872
-
1873
- *Ryan Wallace*
1874
-
1875
- * Renaming `use_transactional_fixtures` to `use_transactional_tests` for clarity.
1876
-
1877
- Fixes #18864.
1878
-
1879
- *Brandon Weiss*
1880
-
1881
- * Increase pg gem version requirement to `~> 0.18`. Earlier versions of the
1882
- pg gem are known to have problems with Ruby 2.2.
1883
-
1884
- *Matt Brictson*
1885
-
1886
- * Correctly dump `serial` and `bigserial`.
1887
-
1888
- *Ryuta Kamizono*
1889
-
1890
- * Fix default `format` value in `ActiveRecord::Tasks::DatabaseTasks#schema_file`.
1891
-
1892
- *James Cox*
1893
-
1894
- * Don't enroll records in the transaction if they don't have commit callbacks.
1895
- This was causing a memory leak when creating many records inside a transaction.
1896
-
1897
- Fixes #15549.
1898
-
1899
- *Will Bryant*, *Aaron Patterson*
1900
-
1901
- * Correctly create through records when created on a has many through
1902
- association when using `where`.
1903
-
1904
- Fixes #19073.
1905
-
1906
- *Sean Griffin*
1907
-
1908
- * Add `SchemaMigration.create_table` support for any unicode charsets with MySQL.
1909
-
1910
- *Ryuta Kamizono*
1911
-
1912
- * PostgreSQL no longer disables user triggers if system triggers can't be
1913
- disabled. Disabling user triggers does not fulfill what the method promises.
1914
- Rails currently requires superuser privileges for this method.
1915
-
1916
- If you absolutely rely on this behavior, consider patching
1917
- `disable_referential_integrity`.
1918
-
1919
- *Yves Senn*
1920
-
1921
- * Restore aborted transaction state when `disable_referential_integrity` fails
1922
- due to missing permissions.
1923
-
1924
- *Toby Ovod-Everett*, *Yves Senn*
1925
-
1926
- * In PostgreSQL, print a warning message if `disable_referential_integrity`
1927
- fails due to missing permissions.
1928
-
1929
- *Andrey Nering*, *Yves Senn*
1930
-
1931
- * Allow a `:limit` option for MySQL bigint primary key support.
1932
-
1933
- Example:
1934
-
1935
- create_table :foos, id: :primary_key, limit: 8 do |t|
1936
- end
1937
-
1938
- # or
1939
-
1940
- create_table :foos, id: false do |t|
1941
- t.primary_key :id, limit: 8
1942
- end
1943
-
1944
- *Ryuta Kamizono*
1945
-
1946
- * `belongs_to` will now trigger a validation error by default if the association is not present.
1947
- You can turn this off on a per-association basis with `optional: true`.
1948
- (Note this new default only applies to new Rails apps that will be generated with
1949
- `config.active_record.belongs_to_required_by_default = true` in initializer.)
1950
-
1951
- *Josef Šimánek*
1952
-
1953
- * Fixed `ActiveRecord::Relation#becomes!` and `changed_attributes` issues for type
1954
- columns.
1955
-
1956
- Fixes #17139.
1957
-
1958
- *Miklos Fazekas*
1959
-
1960
- * Format the time string according to the precision of the time column.
1961
-
1962
- *Ryuta Kamizono*
1963
-
1964
- * Allow a `:precision` option for time type columns.
1965
-
1966
- *Ryuta Kamizono*
1967
-
1968
- * Add `ActiveRecord::Base.suppress` to prevent the receiver from being saved
1969
- during the given block.
1970
-
1971
- For example, here's a pattern of creating notifications when new comments
1972
- are posted. (The notification may in turn trigger an email, a push
1973
- notification, or just appear in the UI somewhere):
1974
-
1975
- class Comment < ActiveRecord::Base
1976
- belongs_to :commentable, polymorphic: true
1977
- after_create -> { Notification.create! comment: self,
1978
- recipients: commentable.recipients }
1979
- end
1980
-
1981
- That's what you want the bulk of the time. A new comment creates a new
1982
- Notification. There may be edge cases where you don't want that, like
1983
- when copying a commentable and its comments, in which case write a
1984
- concern with something like this:
1985
-
1986
- module Copyable
1987
- def copy_to(destination)
1988
- Notification.suppress do
1989
- # Copy logic that creates new comments that we do not want triggering
1990
- # notifications.
1991
- end
1992
- end
1993
- end
1994
-
1995
- *Michael Ryan*
1996
-
1997
- * `:time` option added for `#touch`.
1998
-
1999
- Fixes #18905.
2000
-
2001
- *Hyonjee Joo*
2002
-
2003
- * Add `foreign_key_exists?` method.
2004
-
2005
- *Tõnis Simo*
2006
-
2007
- * Use SQL COUNT and LIMIT 1 queries for `none?` and `one?` methods
2008
- if no block or limit is given, instead of loading the entire
2009
- collection into memory. This applies to relations (e.g. `User.all`)
2010
- as well as associations (e.g. `account.users`)
2011
-
2012
- # Before:
2013
-
2014
- users.none?
2015
- # SELECT "users".* FROM "users"
2016
-
2017
- users.one?
2018
- # SELECT "users".* FROM "users"
2019
-
2020
- # After:
2021
-
2022
- users.none?
2023
- # SELECT 1 AS one FROM "users" LIMIT 1
2024
-
2025
- users.one?
2026
- # SELECT COUNT(*) FROM "users"
2027
-
2028
- *Eugene Gilburg*
2029
-
2030
- * Have `enum` perform type casting consistently with the rest of Active
2031
- Record, such as `where`.
2032
-
2033
- *Sean Griffin*
2034
-
2035
- * `scoping` no longer pollutes the current scope of sibling classes when using
2036
- STI.
2037
-
2038
- Fixes #18806.
2039
-
2040
- Example:
2041
-
2042
- StiOne.none.scoping do
2043
- StiTwo.all
2044
- end
2045
-
2046
-
2047
- *Sean Griffin*
2048
-
2049
- * `remove_reference` with `foreign_key: true` removes the foreign key before
2050
- removing the column. This fixes a bug where it was not possible to remove
2051
- the column on MySQL.
2052
-
2053
- Fixes #18664.
2054
-
2055
- *Yves Senn*
2056
-
2057
- * `find_in_batches` now accepts an `:finish` parameter that complements the `:start`
2058
- parameter to specify where to stop batch processing.
2059
-
2060
- *Vipul A M*
2061
-
2062
- * Fix a rounding problem for PostgreSQL timestamp columns.
2063
-
2064
- If a timestamp column has a precision specified, it needs to
2065
- format according to that.
2066
-
2067
- *Ryuta Kamizono*
2068
-
2069
- * Respect the database default charset for `schema_migrations` table.
2070
-
2071
- The charset of `version` column in `schema_migrations` table depends
2072
- on the database default charset and collation rather than the encoding
2073
- of the connection.
2074
-
2075
- *Ryuta Kamizono*
2076
-
2077
- * Raise `ArgumentError` when passing `nil` or `false` to `Relation#merge`.
2078
-
2079
- These are not valid values to merge in a relation, so it should warn users
2080
- early.
2081
-
2082
- *Rafael Mendonça França*
2083
-
2084
- * Use `SCHEMA` instead of `DB_STRUCTURE` for specifying a structure file.
2085
-
2086
- This makes the `db:structure` tasks consistent with `test:load_structure`.
2087
-
2088
- *Dieter Komendera*
2089
-
2090
- * Respect custom primary keys for associations when calling `Relation#where`
2091
-
2092
- Fixes #18813.
2093
-
2094
- *Sean Griffin*
2095
-
2096
- * Fix several edge cases which could result in a counter cache updating
2097
- twice or not updating at all for `has_many` and `has_many :through`.
2098
-
2099
- Fixes #10865.
2100
-
2101
- *Sean Griffin*
2102
-
2103
- * Foreign keys added by migrations were given random, generated names. This
2104
- meant a different `structure.sql` would be generated every time a developer
2105
- ran migrations on their machine.
2106
-
2107
- The generated part of foreign key names is now a hash of the table name and
2108
- column name, which is consistent every time you run the migration.
2109
-
2110
- *Chris Sinjakli*
2111
-
2112
- * Fix n+1 query problem when eager loading nil associations (fixes #18312)
2113
-
2114
- *Sammy Larbi*
2115
-
2116
- * Change the default error message from `can't be blank` to `must exist` for
2117
- the presence validator of the `:required` option on `belongs_to`/`has_one`
2118
- associations.
2119
-
2120
- *Henrik Nygren*
2121
-
2122
- * Fixed `ActiveRecord::Relation#group` method when an argument is an SQL
2123
- reserved keyword:
2124
-
2125
- Example:
2126
-
2127
- SplitTest.group(:key).count
2128
- Property.group(:value).count
1423
+ * Add `ActiveRecord::Base.base_class?` predicate.
2129
1424
 
2130
1425
  *Bogdan Gusiev*
2131
1426
 
2132
- * Added the `#or` method on `ActiveRecord::Relation`, allowing use of the OR
2133
- operator to combine WHERE or HAVING clauses.
2134
-
2135
- Example:
2136
-
2137
- Post.where('id = 1').or(Post.where('id = 2'))
2138
- # => SELECT * FROM posts WHERE (id = 1) OR (id = 2)
2139
-
2140
- *Sean Griffin*, *Matthew Draper*, *Gael Muller*, *Olivier El Mekki*
2141
-
2142
- * Don't define autosave association callbacks twice from
2143
- `accepts_nested_attributes_for`.
2144
-
2145
- Fixes #18704.
2146
-
2147
- *Sean Griffin*
2148
-
2149
- * Integer types will no longer raise a `RangeError` when assigning an
2150
- attribute, but will instead raise when going to the database.
2151
-
2152
- Fixes several vague issues which were never reported directly. See the
2153
- commit message from the commit which added this line for some examples.
2154
-
2155
- *Sean Griffin*
2156
-
2157
- * Values which would error while being sent to the database (such as an
2158
- ASCII-8BIT string with invalid UTF-8 bytes on SQLite3), no longer error on
2159
- assignment. They will still error when sent to the database, but you are
2160
- given the ability to re-assign it to a valid value.
2161
-
2162
- Fixes #18580.
2163
-
2164
- *Sean Griffin*
2165
-
2166
- * Don't remove join dependencies in `Relation#exists?`
2167
-
2168
- Fixes #18632.
2169
-
2170
- *Sean Griffin*
2171
-
2172
- * Invalid values assigned to a JSON column are assumed to be `nil`.
2173
-
2174
- Fixes #18629.
2175
-
2176
- *Sean Griffin*
2177
-
2178
- * Add `ActiveRecord::Base#accessed_fields`, which can be used to quickly
2179
- discover which fields were read from a model when you are looking to only
2180
- select the data you need from the database.
2181
-
2182
- *Sean Griffin*
2183
-
2184
- * Introduce the `:if_exists` option for `drop_table`.
2185
-
2186
- Example:
2187
-
2188
- drop_table(:posts, if_exists: true)
2189
-
2190
- That would execute:
2191
-
2192
- DROP TABLE IF EXISTS posts
2193
-
2194
- If the table doesn't exist, `if_exists: false` (the default) raises an
2195
- exception whereas `if_exists: true` does nothing.
2196
-
2197
- *Cody Cutrer*, *Stefan Kanev*, *Ryuta Kamizono*
2198
-
2199
- * Don't run SQL if attribute value is not changed for update_attribute method.
2200
-
2201
- *Prathamesh Sonpatki*
2202
-
2203
- * `time` columns can now get affected by `time_zone_aware_attributes`. If you have
2204
- set `config.time_zone` to a value other than `'UTC'`, they will be treated
2205
- as in that time zone by default in Rails 5.1. If this is not the desired
2206
- behavior, you can set
2207
-
2208
- ActiveRecord::Base.time_zone_aware_types = [:datetime]
2209
-
2210
- A deprecation warning will be emitted if you have a `:time` column, and have
2211
- not explicitly opted out.
2212
-
2213
- Fixes #3145.
2214
-
2215
- *Sean Griffin*
2216
-
2217
- * Tests now run after_commit callbacks. You no longer have to declare
2218
- `uses_transaction ‘test name’` to test the results of an after_commit.
2219
-
2220
- after_commit callbacks run after committing a transaction whose parent
2221
- is not `joinable?`: un-nested transactions, transactions within test cases,
2222
- and transactions in `console --sandbox`.
2223
-
2224
- *arthurnn*, *Ravil Bayramgalin*, *Matthew Draper*
2225
-
2226
- * `nil` as a value for a binary column in a query no longer logs as
2227
- "<NULL binary data>", and instead logs as just "nil".
2228
-
2229
- *Sean Griffin*
2230
-
2231
- * `attribute_will_change!` will no longer cause non-persistable attributes to
2232
- be sent to the database.
2233
-
2234
- Fixes #18407.
2235
-
2236
- *Sean Griffin*
2237
-
2238
- * Remove support for the `protected_attributes` gem.
2239
-
2240
- *Carlos Antonio da Silva*, *Roberto Miranda*
2241
-
2242
- * Fix accessing of fixtures having non-string labels like Fixnum.
2243
-
2244
- *Prathamesh Sonpatki*
2245
-
2246
- * Remove deprecated support to preload instance-dependent associations.
2247
-
2248
- *Yves Senn*
2249
-
2250
- * Remove deprecated support for PostgreSQL ranges with exclusive lower bounds.
2251
-
2252
- *Yves Senn*
2253
-
2254
- * Remove deprecation when modifying a relation with cached Arel.
2255
- This raises an `ImmutableRelation` error instead.
2256
-
2257
- *Yves Senn*
2258
-
2259
- * Added `ActiveRecord::SecureToken` in order to encapsulate generation of
2260
- unique tokens for attributes in a model using `SecureRandom`.
2261
-
2262
- *Roberto Miranda*
2263
-
2264
- * Change the behavior of boolean columns to be closer to Ruby's semantics.
2265
-
2266
- Before this change we had a small set of "truthy", and all others are "falsy".
2267
-
2268
- Now, we have a small set of "falsy" values and all others are "truthy" matching
2269
- Ruby's semantics.
2270
-
2271
- *Rafael Mendonça França*
2272
-
2273
- * Deprecate `ActiveRecord::Base.errors_in_transactional_callbacks=`.
2274
-
2275
- *Rafael Mendonça França*
2276
-
2277
- * Change transaction callbacks to not swallow errors.
2278
-
2279
- Before this change any errors raised inside a transaction callback
2280
- were getting rescued and printed in the logs.
2281
-
2282
- Now these errors are not rescued anymore and just bubble up, as the other callbacks.
2283
-
2284
- *Rafael Mendonça França*
2285
-
2286
- * Remove deprecated `sanitize_sql_hash_for_conditions`.
2287
-
2288
- *Rafael Mendonça França*
2289
-
2290
- * Remove deprecated `Reflection#source_macro`.
2291
-
2292
- *Rafael Mendonça França*
2293
-
2294
- * Remove deprecated `symbolized_base_class` and `symbolized_sti_name`.
2295
-
2296
- *Rafael Mendonça França*
2297
-
2298
- * Remove deprecated `ActiveRecord::Base.disable_implicit_join_references=`.
2299
-
2300
- *Rafael Mendonça França*
2301
-
2302
- * Remove deprecated access to connection specification using a string accessor.
2303
-
2304
- Now all strings will be handled as a URL.
2305
-
2306
- *Rafael Mendonça França*
2307
-
2308
- * Change the default `null` value for `timestamps` to `false`.
2309
-
2310
- *Rafael Mendonça França*
2311
-
2312
- * Return an array of pools from `connection_pools`.
2313
-
2314
- *Rafael Mendonça França*
2315
-
2316
- * Return a null column from `column_for_attribute` when no column exists.
2317
-
2318
- *Rafael Mendonça França*
2319
-
2320
- * Remove deprecated `serialized_attributes`.
2321
-
2322
- *Rafael Mendonça França*
2323
-
2324
- * Remove deprecated automatic counter caches on `has_many :through`.
2325
-
2326
- *Rafael Mendonça França*
2327
-
2328
- * Change the way in which callback chains can be halted.
2329
-
2330
- The preferred method to halt a callback chain from now on is to explicitly
2331
- `throw(:abort)`.
2332
- In the past, returning `false` in an Active Record `before_` callback had the
2333
- side effect of halting the callback chain.
2334
- This is not recommended anymore and, depending on the value of the
2335
- `ActiveSupport.halt_callback_chains_on_return_false` option, will
2336
- either not work at all or display a deprecation warning.
2337
-
2338
- *claudiob*
2339
-
2340
- * Clear query cache on rollback.
2341
-
2342
- *Florian Weingarten*
2343
-
2344
- * Fix setting of foreign_key for through associations when building a new record.
2345
-
2346
- Fixes #12698.
2347
-
2348
- *Ivan Antropov*
2349
-
2350
- * Improve dumping of the primary key. If it is not a default primary key,
2351
- correctly dump the type and options.
2352
-
2353
- Fixes #14169, #16599.
2354
-
2355
- *Ryuta Kamizono*
2356
-
2357
- * Format the datetime string according to the precision of the datetime field.
2358
-
2359
- Incompatible to rounding behavior between MySQL 5.6 and earlier.
2360
-
2361
- In 5.5, when you insert `2014-08-17 12:30:00.999999` the fractional part
2362
- is ignored. In 5.6, it's rounded to `2014-08-17 12:30:01`:
2363
-
2364
- http://bugs.mysql.com/bug.php?id=68760
2365
-
2366
- *Ryuta Kamizono*
2367
-
2368
- * Allow a precision option for MySQL datetimes.
2369
-
2370
- *Ryuta Kamizono*
2371
-
2372
- * Fixed automatic `inverse_of` for models nested in a module.
2373
-
2374
- *Andrew McCloud*
2375
-
2376
- * Change `ActiveRecord::Relation#update` behavior so that it can
2377
- be called without passing ids of the records to be updated.
2378
-
2379
- This change allows updating multiple records returned by
2380
- `ActiveRecord::Relation` with callbacks and validations.
2381
-
2382
- # Before
2383
- # ArgumentError: wrong number of arguments (1 for 2)
2384
- Comment.where(group: 'expert').update(body: "Group of Rails Experts")
2385
-
2386
- # After
2387
- # Comments with group expert updated with body "Group of Rails Experts"
2388
- Comment.where(group: 'expert').update(body: "Group of Rails Experts")
2389
-
2390
- *Prathamesh Sonpatki*
2391
-
2392
- * Fix `reaping_frequency` option when the value is a string.
2393
-
2394
- This usually happens when it is configured using `DATABASE_URL`.
2395
-
2396
- *korbin*
2397
-
2398
- * Fix error message when trying to create an associated record and the foreign
2399
- key is missing.
2400
-
2401
- Before this fix the following exception was being raised:
2402
-
2403
- NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218>
2404
-
2405
- Now the message is:
2406
-
2407
- ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
2408
-
2409
- *Rafael Mendonça França*
2410
-
2411
- * Fix change detection problem for PostgreSQL bytea type and
2412
- `ArgumentError: string contains null byte` exception with pg-0.18.
2413
-
2414
- Fixes #17680.
2415
-
2416
- *Lars Kanis*
2417
-
2418
- * When a table has a composite primary key, the `primary_key` method for
2419
- SQLite3 and PostgreSQL adapters was only returning the first field of the key.
2420
- Ensures that it will return nil instead, as Active Record doesn't support
2421
- composite primary keys.
2422
-
2423
- Fixes #18070.
2424
-
2425
- *arthurnn*
2426
-
2427
- * `validates_size_of` / `validates_length_of` do not count records
2428
- which are `marked_for_destruction?`.
2429
-
2430
- Fixes #7247.
2431
-
2432
- *Yves Senn*
2433
-
2434
- * Ensure `first!` and friends work on loaded associations.
2435
-
2436
- Fixes #18237.
2437
-
2438
- *Sean Griffin*
2439
-
2440
- * `eager_load` preserves readonly flag for associations.
2441
-
2442
- Fixes #15853.
2443
-
2444
- *Takashi Kokubun*
2445
-
2446
- * Provide `:touch` option to `save()` to accommodate saving without updating
2447
- timestamps.
2448
-
2449
- Fixes #18202.
2450
-
2451
- *Dan Olson*
2452
-
2453
- * Provide a more helpful error message when an unsupported class is passed to
2454
- `serialize`.
2455
-
2456
- Fixes #18224.
2457
-
2458
- *Sean Griffin*
2459
-
2460
- * Add bigint primary key support for MySQL.
2461
-
2462
- Example:
2463
-
2464
- create_table :foos, id: :bigint do |t|
2465
- end
2466
-
2467
- *Ryuta Kamizono*
2468
-
2469
- * Support for any type of primary key.
2470
-
2471
- Fixes #14194.
2472
-
2473
- *Ryuta Kamizono*
2474
-
2475
- * Dump the default `nil` for PostgreSQL UUID primary key.
2476
-
2477
- *Ryuta Kamizono*
2478
-
2479
- * Add a `:foreign_key` option to `references` and associated migration
2480
- methods. The model and migration generators now use this option, rather than
2481
- the `add_foreign_key` form.
2482
-
2483
- *Sean Griffin*
2484
-
2485
- * Don't raise when writing an attribute with an out-of-range datetime passed
2486
- by the user.
2487
-
2488
- *Grey Baker*
2489
-
2490
- * Replace deprecated `ActiveRecord::Tasks::DatabaseTasks#load_schema` with
2491
- `ActiveRecord::Tasks::DatabaseTasks#load_schema_for`.
2492
-
2493
- *Yves Senn*
2494
-
2495
- * Fix bug with `ActiveRecord::Type::Numeric` that caused negative values to
2496
- be marked as having changed when set to the same negative value.
2497
-
2498
- Fixes #18161.
2499
-
2500
- *Daniel Fox*
2501
-
2502
- * Introduce `force: :cascade` option for `create_table`. Using this option
2503
- will recreate tables even if they have dependent objects (like foreign keys).
2504
- `db/schema.rb` now uses `force: :cascade`. This makes it possible to
2505
- reload the schema when foreign keys are in place.
2506
-
2507
- *Matthew Draper*, *Yves Senn*
2508
-
2509
- * `db:schema:load` and `db:structure:load` no longer purge the database
2510
- before loading the schema. This is left for the user to do.
2511
- `db:test:prepare` will still purge the database.
2512
-
2513
- Fixes #17945.
2514
-
2515
- *Yves Senn*
2516
-
2517
- * Fix undesirable RangeError by `Type::Integer`. Add `Type::UnsignedInteger`.
2518
-
2519
- *Ryuta Kamizono*
2520
-
2521
- * Add `foreign_type` option to `has_one` and `has_many` association macros.
1427
+ * Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
2522
1428
 
2523
- This option enables to define the column name of associated object's type for polymorphic associations.
1429
+ *Tan Huynh*, *Yukio Mizuta*
2524
1430
 
2525
- *Ulisses Almeida*, *Kassio Borges*
1431
+ * Rails 6 requires Ruby 2.5.0 or newer.
2526
1432
 
2527
- * Remove deprecated behavior allowing nested arrays to be passed as query
2528
- values.
1433
+ *Jeremy Daer*, *Kasper Timm Hansen*
2529
1434
 
2530
- *Melanie Gilman*
1435
+ * Deprecate `update_attributes`/`!` in favor of `update`/`!`.
2531
1436
 
2532
- * Deprecate passing a class as a value in a query. Users should pass strings
2533
- instead.
1437
+ *Eddie Lebow*
2534
1438
 
2535
- *Melanie Gilman*
1439
+ * Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
1440
+ `ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
2536
1441
 
2537
- * `add_timestamps` and `remove_timestamps` now properly reversible with
2538
- options.
1442
+ *DHH*
2539
1443
 
2540
- *Noam Gagliardi-Rabinovich*
1444
+ * Add `Relation#pick` as short-hand for single-value plucks.
2541
1445
 
2542
- * `ActiveRecord::ConnectionAdapters::ColumnDumper#column_spec` and
2543
- `ActiveRecord::ConnectionAdapters::ColumnDumper#prepare_column_options` no
2544
- longer have a `types` argument. They should access
2545
- `connection#native_database_types` directly.
1446
+ *DHH*
2546
1447
 
2547
- *Yves Senn*
2548
1448
 
2549
- Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activerecord/CHANGELOG.md) for previous changes.
1449
+ Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.