activerecord 5.1.0 → 5.2.0.rc1

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