activerecord 4.2.11.3 → 6.0.2.2

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