activerecord 4.1.16 → 4.2.0.beta1

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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +634 -2185
  3. data/README.rdoc +15 -10
  4. data/lib/active_record.rb +2 -1
  5. data/lib/active_record/aggregations.rb +12 -8
  6. data/lib/active_record/associations.rb +58 -33
  7. data/lib/active_record/associations/association.rb +1 -1
  8. data/lib/active_record/associations/association_scope.rb +53 -21
  9. data/lib/active_record/associations/belongs_to_association.rb +15 -5
  10. data/lib/active_record/associations/builder/association.rb +16 -5
  11. data/lib/active_record/associations/builder/belongs_to.rb +7 -29
  12. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +2 -11
  13. data/lib/active_record/associations/builder/has_one.rb +2 -2
  14. data/lib/active_record/associations/builder/singular_association.rb +8 -1
  15. data/lib/active_record/associations/collection_association.rb +32 -44
  16. data/lib/active_record/associations/collection_proxy.rb +1 -10
  17. data/lib/active_record/associations/has_many_association.rb +60 -14
  18. data/lib/active_record/associations/has_many_through_association.rb +34 -23
  19. data/lib/active_record/associations/has_one_association.rb +0 -1
  20. data/lib/active_record/associations/join_dependency.rb +7 -9
  21. data/lib/active_record/associations/join_dependency/join_association.rb +18 -14
  22. data/lib/active_record/associations/preloader.rb +2 -2
  23. data/lib/active_record/associations/preloader/association.rb +9 -5
  24. data/lib/active_record/associations/preloader/through_association.rb +3 -3
  25. data/lib/active_record/associations/singular_association.rb +16 -1
  26. data/lib/active_record/associations/through_association.rb +6 -22
  27. data/lib/active_record/attribute.rb +131 -0
  28. data/lib/active_record/attribute_assignment.rb +19 -11
  29. data/lib/active_record/attribute_decorators.rb +66 -0
  30. data/lib/active_record/attribute_methods.rb +53 -90
  31. data/lib/active_record/attribute_methods/before_type_cast.rb +2 -2
  32. data/lib/active_record/attribute_methods/dirty.rb +85 -42
  33. data/lib/active_record/attribute_methods/primary_key.rb +6 -8
  34. data/lib/active_record/attribute_methods/read.rb +14 -57
  35. data/lib/active_record/attribute_methods/serialization.rb +12 -146
  36. data/lib/active_record/attribute_methods/time_zone_conversion.rb +32 -40
  37. data/lib/active_record/attribute_methods/write.rb +8 -23
  38. data/lib/active_record/attribute_set.rb +77 -0
  39. data/lib/active_record/attribute_set/builder.rb +32 -0
  40. data/lib/active_record/attributes.rb +122 -0
  41. data/lib/active_record/autosave_association.rb +11 -21
  42. data/lib/active_record/base.rb +9 -19
  43. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +69 -45
  44. data/lib/active_record/connection_adapters/abstract/database_statements.rb +22 -42
  45. data/lib/active_record/connection_adapters/abstract/quoting.rb +59 -60
  46. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +37 -2
  47. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +102 -21
  48. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +9 -33
  49. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +178 -55
  50. data/lib/active_record/connection_adapters/abstract/transaction.rb +120 -115
  51. data/lib/active_record/connection_adapters/abstract_adapter.rb +143 -57
  52. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +156 -107
  53. data/lib/active_record/connection_adapters/column.rb +13 -244
  54. data/lib/active_record/connection_adapters/connection_specification.rb +6 -20
  55. data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -15
  56. data/lib/active_record/connection_adapters/mysql_adapter.rb +55 -143
  57. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +15 -27
  58. data/lib/active_record/connection_adapters/postgresql/column.rb +20 -0
  59. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +39 -20
  60. data/lib/active_record/connection_adapters/postgresql/oid.rb +29 -388
  61. data/lib/active_record/connection_adapters/postgresql/oid/array.rb +96 -0
  62. data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +52 -0
  63. data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +13 -0
  64. data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +14 -0
  65. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +46 -0
  66. data/lib/active_record/connection_adapters/postgresql/oid/date.rb +11 -0
  67. data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +27 -0
  68. data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +13 -0
  69. data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +17 -0
  70. data/lib/active_record/connection_adapters/postgresql/oid/float.rb +21 -0
  71. data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +59 -0
  72. data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +13 -0
  73. data/lib/active_record/connection_adapters/postgresql/oid/infinity.rb +13 -0
  74. data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +11 -0
  75. data/lib/active_record/connection_adapters/postgresql/oid/json.rb +35 -0
  76. data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +23 -0
  77. data/lib/active_record/connection_adapters/postgresql/oid/money.rb +43 -0
  78. data/lib/active_record/connection_adapters/postgresql/oid/point.rb +43 -0
  79. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +76 -0
  80. data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +15 -0
  81. data/lib/active_record/connection_adapters/postgresql/oid/time.rb +11 -0
  82. data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +85 -0
  83. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +26 -0
  84. data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +26 -0
  85. data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +28 -0
  86. data/lib/active_record/connection_adapters/postgresql/quoting.rb +42 -122
  87. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +4 -4
  88. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +154 -0
  89. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +86 -34
  90. data/lib/active_record/connection_adapters/postgresql/utils.rb +66 -0
  91. data/lib/active_record/connection_adapters/postgresql_adapter.rb +188 -452
  92. data/lib/active_record/connection_adapters/schema_cache.rb +14 -28
  93. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +54 -47
  94. data/lib/active_record/connection_handling.rb +1 -1
  95. data/lib/active_record/core.rb +119 -22
  96. data/lib/active_record/counter_cache.rb +60 -6
  97. data/lib/active_record/enum.rb +9 -10
  98. data/lib/active_record/errors.rb +27 -26
  99. data/lib/active_record/explain.rb +1 -1
  100. data/lib/active_record/fixtures.rb +52 -45
  101. data/lib/active_record/gem_version.rb +3 -3
  102. data/lib/active_record/inheritance.rb +33 -8
  103. data/lib/active_record/integration.rb +4 -4
  104. data/lib/active_record/locking/optimistic.rb +34 -16
  105. data/lib/active_record/migration.rb +22 -32
  106. data/lib/active_record/migration/command_recorder.rb +19 -2
  107. data/lib/active_record/migration/join_table.rb +1 -1
  108. data/lib/active_record/model_schema.rb +39 -48
  109. data/lib/active_record/nested_attributes.rb +8 -18
  110. data/lib/active_record/persistence.rb +39 -22
  111. data/lib/active_record/query_cache.rb +3 -3
  112. data/lib/active_record/querying.rb +1 -8
  113. data/lib/active_record/railtie.rb +17 -10
  114. data/lib/active_record/railties/databases.rake +47 -42
  115. data/lib/active_record/readonly_attributes.rb +0 -1
  116. data/lib/active_record/reflection.rb +225 -92
  117. data/lib/active_record/relation.rb +35 -11
  118. data/lib/active_record/relation/batches.rb +0 -2
  119. data/lib/active_record/relation/calculations.rb +28 -32
  120. data/lib/active_record/relation/delegation.rb +1 -1
  121. data/lib/active_record/relation/finder_methods.rb +42 -20
  122. data/lib/active_record/relation/merger.rb +0 -1
  123. data/lib/active_record/relation/predicate_builder.rb +1 -22
  124. data/lib/active_record/relation/predicate_builder/array_handler.rb +16 -11
  125. data/lib/active_record/relation/predicate_builder/relation_handler.rb +0 -4
  126. data/lib/active_record/relation/query_methods.rb +98 -62
  127. data/lib/active_record/relation/spawn_methods.rb +6 -7
  128. data/lib/active_record/result.rb +16 -9
  129. data/lib/active_record/sanitization.rb +8 -1
  130. data/lib/active_record/schema.rb +0 -1
  131. data/lib/active_record/schema_dumper.rb +51 -9
  132. data/lib/active_record/schema_migration.rb +4 -0
  133. data/lib/active_record/scoping/default.rb +5 -4
  134. data/lib/active_record/serializers/xml_serializer.rb +3 -7
  135. data/lib/active_record/statement_cache.rb +79 -5
  136. data/lib/active_record/store.rb +5 -5
  137. data/lib/active_record/tasks/database_tasks.rb +37 -5
  138. data/lib/active_record/tasks/mysql_database_tasks.rb +10 -16
  139. data/lib/active_record/tasks/postgresql_database_tasks.rb +2 -2
  140. data/lib/active_record/timestamp.rb +9 -7
  141. data/lib/active_record/transactions.rb +35 -21
  142. data/lib/active_record/type.rb +20 -0
  143. data/lib/active_record/type/binary.rb +40 -0
  144. data/lib/active_record/type/boolean.rb +19 -0
  145. data/lib/active_record/type/date.rb +46 -0
  146. data/lib/active_record/type/date_time.rb +43 -0
  147. data/lib/active_record/type/decimal.rb +40 -0
  148. data/lib/active_record/type/decimal_without_scale.rb +11 -0
  149. data/lib/active_record/type/float.rb +19 -0
  150. data/lib/active_record/type/hash_lookup_type_map.rb +19 -0
  151. data/lib/active_record/type/integer.rb +23 -0
  152. data/lib/active_record/type/mutable.rb +16 -0
  153. data/lib/active_record/type/numeric.rb +36 -0
  154. data/lib/active_record/type/serialized.rb +51 -0
  155. data/lib/active_record/type/string.rb +36 -0
  156. data/lib/active_record/type/text.rb +11 -0
  157. data/lib/active_record/type/time.rb +26 -0
  158. data/lib/active_record/type/time_value.rb +38 -0
  159. data/lib/active_record/type/type_map.rb +48 -0
  160. data/lib/active_record/type/value.rb +101 -0
  161. data/lib/active_record/validations.rb +21 -16
  162. data/lib/active_record/validations/uniqueness.rb +9 -23
  163. data/lib/rails/generators/active_record/migration/migration_generator.rb +8 -4
  164. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +1 -1
  165. data/lib/rails/generators/active_record/model/templates/model.rb +1 -1
  166. metadata +71 -14
  167. data/lib/active_record/connection_adapters/postgresql/cast.rb +0 -168
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f07fb206d368add70db30330c97e2ebdb5ed0c0f
4
- data.tar.gz: 3ffedb5d0745eb03ed80655b3ba90f1ee5d9d497
3
+ metadata.gz: 57b65593b6cdbb77e81c448af2b0e2c0f0776680
4
+ data.tar.gz: cea842a9261ae06b3a9ee0c5d1e276743c496457
5
5
  SHA512:
6
- metadata.gz: 0af6121cd00b5c337bbb9ebf6795dede7b36e8cdb9c1b8198e5650e62e46f9caf82b99e1f32b6b8cfc41cf1711d5c2d260de4c8f38010e8b4383e36b5d05624f
7
- data.tar.gz: 5aa6ee735366e2c825ad3062955a9b0bd33cb58136075806cdb2f816398f201b3648a749c497e3b3af1d56cf57880c83603705b84aa50ea7fb0b2cd357659d24
6
+ metadata.gz: a95a9d12073d982417b4f08f02ac3492545e5096a3bea0b9400c933738709010f763a0961914bf0fa135013a4d315eb50efb38091d7cacf90f71c6c8bf1699b4
7
+ data.tar.gz: 345909347c2549c3be866f3cb335e561acafde1a26682705dd90d0d8022875a3fe19871e1402a43717dc28b2405a2450d224f39620ae7dd2a928bf76b0017af3
@@ -1,353 +1,374 @@
1
- ## Rails 4.1.16 (July 12, 2016) ##
1
+ * Fixed the `Relation#exists?` to work with polymorphic associations.
2
2
 
3
- * Correctly pass MySQL options when using structure_dump or structure_load
3
+ Fixes #15821.
4
4
 
5
- Specifically, it fixes an issue when using SSL authentication.
6
-
7
- *Alex Coomans*
8
-
9
-
10
- ## Rails 4.1.15 (March 07, 2016) ##
11
-
12
- * Fixes custom primary keys for associations when calling `Relation#where`
13
-
14
- Fixes #23327.
15
-
16
- *Rick Song*
17
-
18
- * No longer pass deprecated option `-i` to `pg_dump`.
19
-
20
- *Paul Sadauskas*
5
+ *Kassio Borges*
21
6
 
7
+ * Currently, Active Record will rescue any errors raised within
8
+ after_rollback/after_create callbacks and print them to the logs. Next versions of rails
9
+ will not rescue those errors anymore, and just bubble them up, as the other callbacks.
22
10
 
23
- ## Rails 4.1.14.2 (February 26, 2016) ##
11
+ This adds a opt-in flag to enable that behaviour, of not rescuing the errors.
12
+ Example:
24
13
 
25
- * No changes.
14
+ # For not swallow errors in after_commit/after_rollback callbacks.
15
+ config.active_record.raise_in_transactional_callbacks = true
26
16
 
17
+ Fixes #13460.
27
18
 
28
- ## Rails 4.1.14.1 (January 25, 2015) ##
19
+ *arthurnn*
29
20
 
30
- * No changes.
21
+ * Fixed an issue where custom accessor methods (such as those generated by
22
+ `enum`) with the same name as a global method are incorrectly overridden
23
+ when subclassing.
31
24
 
25
+ Fixes #16288.
32
26
 
33
- ## Rails 4.1.14 (November 12, 2015) ##
27
+ *Godfrey Chan*
34
28
 
35
- * No longer pass deprecated option `-i` to `pg_dump`.
29
+ * `*_was` and `changes` now work correctly for in-place attribute changes as
30
+ well.
36
31
 
37
- *Paul Sadauskas*
32
+ *Sean Griffin*
38
33
 
39
- * Includes HABTM returns correct size now. It's caused by the join dependency
40
- only instantiates one HABTM object because the join table hasn't a primary key.
34
+ * Fix regression on after_commit that didnt fire when having nested transactions.
41
35
 
42
- Fixes #16032.
36
+ Fixes #16425
43
37
 
44
- Examples:
38
+ *arthurnn*
45
39
 
46
- before:
40
+ * Do not try to write timestamps when a table has no timestamps columns.
47
41
 
48
- Project.first.salaried_developers.size # => 3
49
- Project.includes(:salaried_developers).first.salaried_developers.size # => 1
42
+ Fixes #8813.
50
43
 
51
- after:
44
+ *Sergey Potapov*
52
45
 
53
- Project.first.salaried_developers.size # => 3
54
- Project.includes(:salaried_developers).first.salaried_developers.size # => 3
46
+ * `index_exists?` with `:name` option does verify specified columns.
55
47
 
56
- *Bigxiang*
48
+ Example:
57
49
 
50
+ add_index :articles, :title, name: "idx_title"
58
51
 
59
- ## Rails 4.1.13 (August 24, 2015) ##
52
+ # Before:
53
+ index_exists? :articles, :title, name: "idx_title" # => `true`
54
+ index_exists? :articles, :body, name: "idx_title" # => `true`
60
55
 
61
- * Don't define autosave association callbacks twice from
62
- `accepts_nested_attributes_for`.
56
+ # After:
57
+ index_exists? :articles, :title, name: "idx_title" # => `true`
58
+ index_exists? :articles, :body, name: "idx_title" # => `false`
63
59
 
64
- Fixes #18704.
60
+ *Yves Senn*, *Matthew Draper*
65
61
 
66
- *Sean Griffin*
62
+ * When calling `update_columns` on a record that is not persisted, the error
63
+ message now reflects whether that object is a new record or has been
64
+ destroyed.
67
65
 
66
+ *Lachlan Sylvester*
68
67
 
69
- ## Rails 4.1.12 (June 25, 2015) ##
68
+ * Define `id_was` to get the previous value of the primary key.
70
69
 
71
- * Raises the right exception when declares a has many through
72
- association with missing source.
70
+ Currently when we call id_was and we have a custom primary key name
71
+ Active Record will return the current value of the primary key. This
72
+ make impossible to correctly do an update operation if you change the
73
+ id.
73
74
 
74
- *Mauro George*
75
+ Fixes #16413.
75
76
 
76
- * Revert behavior of `db:schema:load` back to loading the full
77
- environment. This ensures that initializers are run.
77
+ *Rafael Mendonça França*
78
78
 
79
- Fixes #19545.
79
+ * Deprecate `DatabaseTasks.load_schema` to act on the current connection.
80
+ Use `.load_schema_current` instead. In the future `load_schema` will
81
+ require the `configuration` to act on as an argument.
80
82
 
81
83
  *Yves Senn*
82
84
 
83
- * Rename `:class` to `:anonymous_class` in association options.
84
-
85
- Fixes #19659.
86
-
87
- *Andrew White*
88
-
89
- * Fix referencing wrong table aliases while joining tables of has many through
90
- association (only when calling calculation methods).
91
-
92
- Fixes #19276.
93
-
94
- *pinglamb*
95
-
96
-
97
- ## Rails 4.1.11 (June 16, 2015) ##
85
+ * Fixed automatic maintaining test schema to properly handle sql structure
86
+ schema format.
98
87
 
99
- * No changes.
88
+ Fixes #15394.
100
89
 
90
+ *Wojciech Wnętrzak*
101
91
 
102
- ## Rails 4.1.10 (March 19, 2015) ##
92
+ * Fix type casting to Decimal from Float with large precision.
103
93
 
104
- * Fixed ActiveRecord::Relation#becomes! and changed_attributes issues for type column
94
+ *Tomohiro Hashidate*
105
95
 
106
- Fixes #17139.
96
+ * Deprecate `Reflection#source_macro`
107
97
 
108
- *Miklos Fazekas*
98
+ `Reflection#source_macro` is no longer needed in Active Record
99
+ source so it has been deprecated. Code that used `source_macro`
100
+ was removed in #16353.
109
101
 
110
- * A `NullRelation` should represent nothing. This fixes a bug where
111
- `Comment.where(post_id: Post.none)` returned a non-empty result.
102
+ *Eileen M. Uchtitelle*, *Aaron Patterson*
112
103
 
113
- Closes #15176.
104
+ * No verbose backtrace by db:drop when database does not exist.
114
105
 
115
- *Matthew Draper*, *Yves Senn*
106
+ Fixes #16295.
116
107
 
117
- * Respect custom primary keys for associations when calling `Relation#where`
108
+ *Kenn Ejima*
118
109
 
119
- Fixes #18813.
110
+ * Add support for Postgresql JSONB.
120
111
 
121
- *Sean Griffin*
112
+ Example:
122
113
 
123
- * Fixed ActiveRecord::Relation#group method when argument is SQL reserved key word:
114
+ create_table :posts do |t|
115
+ t.jsonb :meta_data
116
+ end
124
117
 
125
- SplitTest.group(:key).count
126
- Property.group(:value).count
118
+ *Philippe Creux*, *Chris Teague*
127
119
 
128
- *Bogdan Gusiev*
120
+ * `db:purge` with MySQL respects `Rails.env`.
129
121
 
130
- * Fixed setting of foreign_key for through associations while building of new record.
122
+ *Yves Senn*
131
123
 
132
- Fixes #12698.
124
+ * `change_column_default :table, :column, nil` with PostgreSQL will issue a
125
+ `DROP DEFAULT` instead of a `DEFAULT NULL` query.
133
126
 
134
- *Ivan Antropov*
127
+ Fixes #16261.
135
128
 
136
- * Fixed automatic inverse_of for models nested in module.
129
+ *Matthew Draper*, *Yves Senn*
137
130
 
138
- *Andrew McCloud*
131
+ * Allow to specify a type for the foreign key column in `references`
132
+ and `add_reference`.
139
133
 
140
- * Fix `reaping_frequency` option when the value is a string.
134
+ Example:
141
135
 
142
- This usually happens when it is configured using `DATABASE_URL`.
136
+ change_table :vehicle do |t|
137
+ t.references :station, type: :uuid
138
+ end
143
139
 
144
- *korbin*
140
+ *Andrey Novikov*, *Łukasz Sarnacki*
145
141
 
142
+ * `create_join_table` removes a common prefix when generating the join table.
143
+ This matches the existing behavior of HABTM associations.
146
144
 
147
- ## Rails 4.1.9 (January 6, 2015) ##
145
+ Fixes #13683.
148
146
 
149
- * `db:schema:load` and `db:structure:load` no longer purge the database
150
- before loading the schema. This is left for the user to do.
151
- `db:test:prepare` will still purge the database.
147
+ *Stefan Kanev*
152
148
 
153
- Closes #17945.
149
+ * Dont swallow errors on compute_type when having a bad alias_method on
150
+ a class.
154
151
 
155
- *Yves Senn*
152
+ *arthurnn*
156
153
 
157
- * Bring back `db:test:prepare` to synchronize the test database schema.
154
+ * PostgreSQL invalid `uuid` are convert to nil.
158
155
 
159
- Manual synchronization using `bin/rake db:test:prepare` is required
160
- when a migration is rolled-back, edited and reapplied.
156
+ *Abdelkader Boudih*
161
157
 
162
- `ActiveRecord::Base.maintain_test_schema` now uses `db:test:prepare`
163
- to synchronize the schema. Plugins can use this task as a hook to
164
- provide custom behavior after the schema has been loaded.
158
+ * Restore 4.0 behavior for using serialize attributes with `JSON` as coder.
165
159
 
166
- NOTE: `test:prepare` runs before the schema was synchronized.
160
+ With 4.1.x, `serialize` started returning a string when `JSON` was passed as
161
+ the second attribute. It will now return a hash as per previous versions.
167
162
 
168
- Fixes #17171, #15787.
163
+ Example:
169
164
 
170
- *Yves Senn*
165
+ class Post < ActiveRecord::Base
166
+ serialize :comment, JSON
167
+ end
171
168
 
172
- * Renaming a table in pg also renames the primary key index.
169
+ class Comment
170
+ include ActiveModel::Model
171
+ attr_accessor :category, :text
172
+ end
173
173
 
174
- Fixes #12856
174
+ post = Post.create!
175
+ post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
176
+ post.save!
175
177
 
176
- *Sean Griffin*
178
+ # 4.0
179
+ post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
177
180
 
178
- * Make it possible to access fixtures excluded by a `default_scope`.
181
+ # 4.1 before
182
+ post.comment # => "#<Comment:0x007f80ab48ff98>"
179
183
 
180
- *Yves Senn*
184
+ # 4.1 after
185
+ post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
181
186
 
182
- * `timestamps` and `add_timestamps` passes additional options along.
183
- (like `null: false`)
187
+ When using `JSON` as the coder in `serialize`, Active Record will use the
188
+ new `ActiveRecord::Coders::JSON` coder which delegates its `dump/load` to
189
+ `ActiveSupport::JSON.encode/decode`. This ensures special objects are dumped
190
+ correctly using the `#as_json` hook.
184
191
 
185
- Closes #17624.
192
+ To keep the previous behaviour, supply a custom coder instead
193
+ ([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
186
194
 
187
- *Yves Senn*
195
+ Fixes #15594.
188
196
 
197
+ *Jenn Cooper*
189
198
 
190
- ## Rails 4.1.8 (November 16, 2014) ##
199
+ * Do not use `RENAME INDEX` syntax for MariaDB 10.0.
191
200
 
192
- * Cache `CollectionAssociation#reader` proxies separately before and after
193
- the owner has been saved so that the proxy is not cached without the
194
- owner's id.
201
+ Fixes #15931.
195
202
 
196
- *Ben Woosley*
203
+ *Jeff Browning*
197
204
 
198
- * Fix preloading of associations which unscope a default scope.
205
+ * Calling `#empty?` on a `has_many` association would use the value from the
206
+ counter cache if one exists.
199
207
 
200
- Fixes #11036.
208
+ *David Verhasselt*
201
209
 
202
- *Byron Bischoff*
210
+ * Fix the schema dump generated for tables without constraints and with
211
+ primary key with default value of custom PostgreSQL function result.
203
212
 
204
- * Do not use `RENAME INDEX` syntax for MariaDB 10.0.
213
+ Fixes #16111.
205
214
 
206
- Fixes #15931.
215
+ *Andrey Novikov*
207
216
 
208
- *Jeff Browning*
217
+ * Fix the SQL generated when a `delete_all` is run on an association to not
218
+ produce an `IN` statements.
209
219
 
210
- * Allow included modules to override association methods.
220
+ Before:
211
221
 
212
- Fixes #16684.
222
+ UPDATE "categorizations" SET "category_id" = NULL WHERE
223
+ "categorizations"."category_id" = 1 AND "categorizations"."id" IN (1, 2)
213
224
 
214
- *Yves Senn*
225
+ After:
215
226
 
216
- * Schema loading rake tasks (like `db:schema:load` and `db:setup`) maintain
217
- the database connection to the current environment.
227
+ UPDATE "categorizations" SET "category_id" = NULL WHERE
228
+ "categorizations"."category_id" = 1
218
229
 
219
- Fixes #16757.
230
+ *Eileen M. Uchitelle, Aaron Patterson*
220
231
 
221
- *Joshua Cody*, *Yves Senn*
232
+ * Avoid type casting boolean and ActiveSupport::Duration values to numeric
233
+ values for string columns. Otherwise, in some database, the string column
234
+ values will be coerced to a numeric allowing false or 0.seconds match any
235
+ string starting with a non-digit.
222
236
 
223
- * `db:purge` with MySQL respects `Rails.env`.
237
+ Example:
224
238
 
225
- *Yves Senn*
239
+ App.where(apikey: false) # => SELECT * FROM users WHERE apikey = '0'
226
240
 
227
- * Fixed automatic maintaining test schema to properly handle sql structure
228
- schema format.
241
+ *Dylan Thacker-Smith*
229
242
 
230
- Fixes #15394.
243
+ * Add a `:required` option to singular associations, providing a nicer
244
+ API for presence validations on associations.
231
245
 
232
- *Wojciech Wnętrzak*
246
+ *Sean Griffin*
233
247
 
234
- * Fix has_many :through relation merging failing when dynamic conditions are
235
- passed as a lambda with an arity of one.
248
+ * Fixed error in `reset_counters` when associations have `select` scope.
249
+ (Call to `count` generates invalid SQL.)
236
250
 
237
- Fixes #16128.
251
+ *Cade Truitt*
238
252
 
239
- *Agis Anastasopoulos*
253
+ * After a successful `reload`, `new_record?` is always false.
240
254
 
255
+ Fixes #12101.
241
256
 
242
- ## Rails 4.1.7.1 (November 19, 2014) ##
257
+ *Matthew Draper*
243
258
 
244
- * No changes.
259
+ * PostgreSQL renaming table doesn't attempt to rename non existent sequences.
245
260
 
261
+ *Abdelkader Boudih*
246
262
 
247
- ## Rails 4.1.7 (October 29, 2014) ##
263
+ * Move 'dependent: :destroy' handling for 'belongs_to'
264
+ from 'before_destroy' to 'after_destroy' callback chain
248
265
 
249
- * No changes.
266
+ Fixes #12380.
250
267
 
268
+ *Ivan Antropov*
251
269
 
252
- ## Rails 4.1.6 (September 11, 2014) ##
270
+ * Detect in-place modifications on String attributes.
253
271
 
254
- * Fixed a regression where whitespaces were stripped from DISTINCT queries in
255
- PostgreSQL.
272
+ Before this change user have to mark the attribute as changed to it be persisted
273
+ in the database. Now it is not required anymore.
256
274
 
257
- *Agis Anastasopoulos*
275
+ Before:
258
276
 
259
- Fixes #16623.
277
+ user = User.first
278
+ user.name << ' Griffin'
279
+ user.name_will_change!
280
+ user.save
281
+ user.reload.name # => "Sean Griffin"
260
282
 
261
- * Fixed an issue where custom accessor methods (such as those generated by
262
- `enum`) with the same name as a global method are incorrectly overridden
263
- when subclassing.
283
+ After:
264
284
 
265
- Fixes #16288.
285
+ user = User.first
286
+ user.name << ' Griffin'
287
+ user.save
288
+ user.reload.name # => "Sean Griffin"
266
289
 
267
- * Baseclass becomes! subclass.
290
+ *Sean Griffin*
268
291
 
269
- Before this change, a record which changed its STI type, could not be found when updated.
270
- Setting update_record to the base class, ensures the record can be found.
292
+ * Add `ActiveRecord::Base#validate!` that raises `RecordInvalid` if the record
293
+ is invalid.
271
294
 
272
- Fixes #14785.
295
+ *Bogdan Gusiev*, *Marc Schütz*
273
296
 
274
- *Matthew Draper*, *Earl St Sauver*, *Edo Balvers*
297
+ * Support for adding and removing foreign keys. Foreign keys are now
298
+ a part of `schema.rb`. This is supported by Mysql2Adapter, MysqlAdapter
299
+ and PostgreSQLAdapter.
275
300
 
276
- * Fix regression on after_commit that didnt fire when having nested transactions.
301
+ Many thanks to *Matthew Higgins* for laying the foundation with his work on
302
+ [foreigner](https://github.com/matthuhiggins/foreigner).
277
303
 
278
- Fixes #16425.
304
+ Example:
279
305
 
280
- *arthurnn*
306
+ # within your migrations:
307
+ add_foreign_key :articles, :authors
308
+ remove_foreign_key :articles, :authors
281
309
 
282
- * Define `id_was` to get the previous value of the primary key.
310
+ *Yves Senn*
283
311
 
284
- Currently when we call id_was and we have a custom primary key name
285
- Active Record will return the current value of the primary key. This
286
- make impossible to correctly do an update operation if you change the
287
- id.
312
+ * Fix subtle bugs regarding attribute assignment on models with no primary
313
+ key. `'id'` will no longer be part of the attributes hash.
288
314
 
289
- Fixes #16413.
315
+ *Sean Griffin*
290
316
 
291
- *Rafael Mendonça França*
317
+ * Deprecate automatic counter caches on `has_many :through`. The behavior was
318
+ broken and inconsistent.
292
319
 
293
- * Fix the schema dump generated for tables without constraints and with
294
- primary key with default value of custom PostgreSQL function result.
320
+ *Sean Griffin*
295
321
 
296
- Fixes #16111.
322
+ * `preload` preserves readonly flag for associations.
297
323
 
298
- *Andrey Novikov*
324
+ See #15853.
299
325
 
300
- * Restore 4.0 behavior for using serialize attributes with `JSON` as coder.
326
+ *Yves Senn*
301
327
 
302
- With 4.1.x, `serialize` started returning a string when `JSON` was passed as
303
- the second attribute. It will now return a hash as per previous versions.
328
+ * Assume numeric types have changed if they were assigned to a value that
329
+ would fail numericality validation, regardless of the old value. Previously
330
+ this would only occur if the old value was 0.
304
331
 
305
332
  Example:
306
333
 
307
- class Post < ActiveRecord::Base
308
- serialize :comment, JSON
309
- end
334
+ model = Model.create!(number: 5)
335
+ model.number = '5wibble'
336
+ model.number_changed? # => true
310
337
 
311
- class Comment
312
- include ActiveModel::Model
313
- attr_accessor :category, :text
314
- end
338
+ Fixes #14731.
315
339
 
316
- post = Post.create!
317
- post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
318
- post.save!
340
+ *Sean Griffin*
319
341
 
320
- # 4.0
321
- post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
342
+ * `reload` no longer merges with the existing attributes.
343
+ The attribute hash is fully replaced. The record is put into the same state
344
+ as it would be with `Model.find(model.id)`.
322
345
 
323
- # 4.1 before
324
- post.comment # => "#<Comment:0x007f80ab48ff98>"
346
+ *Sean Griffin*
325
347
 
326
- # 4.1 after
327
- post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
348
+ * The object returned from `select_all` must respond to `column_types`.
349
+ If this is not the case a `NoMethodError` is raised.
328
350
 
329
- When using `JSON` as the coder in `serialize`, Active Record will use the
330
- new `ActiveRecord::Coders::JSON` coder which delegates its `dump/load` to
331
- `ActiveSupport::JSON.encode/decode`. This ensures special objects are dumped
332
- correctly using the `#as_json` hook.
351
+ *Sean Griffin*
333
352
 
334
- To keep the previous behaviour, supply a custom coder instead
335
- ([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
353
+ * `has_many :through` associations will no longer save the through record
354
+ twice when added in an `after_create` callback defined before the
355
+ associations.
336
356
 
337
- Fixes #15594.
357
+ Fixes #3798.
338
358
 
339
- *Jenn Cooper*
359
+ *Sean Griffin*
340
360
 
341
- * Fixed error in `reset_counters` when associations have `select` scope.
342
- (Call to `count` generates invalid SQL.)
361
+ * Detect in-place modifications of PG array types
343
362
 
344
- *Cade Truitt*
363
+ *Sean Griffin*
345
364
 
346
- * After a successful `reload`, `new_record?` is always false.
365
+ * Add `bin/rake db:purge` task to empty the current database.
347
366
 
348
- Fixes #12101.
367
+ *Yves Senn*
349
368
 
350
- *Matthew Draper*
369
+ * Deprecate `serialized_attributes` without replacement.
370
+
371
+ *Sean Griffin*
351
372
 
352
373
  * Correctly extract IPv6 addresses from `DATABASE_URI`: the square brackets
353
374
  are part of the URI structure, not the actual host.
@@ -356,14 +377,16 @@
356
377
 
357
378
  *Andy Bakun*, *Aaron Stone*
358
379
 
359
- * Don't error when quoting user defined types in PostgreSQL.
360
-
361
- Fixes #15697.
380
+ * Ensure both parent IDs are set on join records when both sides of a
381
+ through association are new.
362
382
 
363
383
  *Sean Griffin*
364
384
 
365
- * Ensure both parent IDs are set on join records when both sides of a
366
- through association are new.
385
+ * `ActiveRecord::Dirty` now detects in-place changes to mutable values.
386
+ Serialized attributes on ActiveRecord models will no longer save when
387
+ unchanged.
388
+
389
+ Fixes #8328.
367
390
 
368
391
  *Sean Griffin*
369
392
 
@@ -374,6 +397,14 @@
374
397
 
375
398
  *Sean Griffin*
376
399
 
400
+ * Remove `cache_attributes` and friends. All attributes are cached.
401
+
402
+ *Sean Griffin*
403
+
404
+ * Remove deprecated method `ActiveRecord::Base.quoted_locking_column`.
405
+
406
+ *Akshay Vishnoi*
407
+
377
408
  * `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
378
409
  `Enumerable#find` does.
379
410
 
@@ -381,6 +412,12 @@
381
412
 
382
413
  *James Yang*
383
414
 
415
+ * Make timezone aware attributes work with PostgreSQL array columns.
416
+
417
+ Fixes #13402.
418
+
419
+ *Kuldeep Aggarwal*, *Sean Griffin*
420
+
384
421
  * `ActiveRecord::SchemaMigration` has no primary key regardless of the
385
422
  `primary_key_prefix_type` configuration.
386
423
 
@@ -394,52 +431,72 @@
394
431
 
395
432
  *Yves Senn*
396
433
 
397
- * Fixed `columns_for_distinct` of postgresql adapter to work correctly
398
- with orders without sort direction modifiers.
434
+ * Baseclass becomes! subclass.
399
435
 
400
- *Nikolay Kondratyev*
436
+ Before this change, a record which changed its STI type, could not be
437
+ updated.
401
438
 
402
- * Keep PostgreSQL `hstore` and `json` attributes as `Hash` in `@attributes`.
403
- Fixes duplication in combination with `store_accessor`.
439
+ Fixes #14785.
404
440
 
405
- Fixes #15369.
441
+ *Matthew Draper*, *Earl St Sauver*, *Edo Balvers*
406
442
 
407
- *Yves Senn*
443
+ * Remove deprecated `ActiveRecord::Migrator.proper_table_name`. Use the
444
+ `proper_table_name` instance method on `ActiveRecord::Migration` instead.
408
445
 
409
- * `rake railties:install:migrations` respects the order of railties.
446
+ *Akshay Vishnoi*
410
447
 
411
- *Arun Agrawal*
448
+ * Fix regression on eager loading association based on SQL query rather than
449
+ existing column.
412
450
 
451
+ Fixes #15480.
413
452
 
414
- ## Rails 4.1.5 (August 18, 2014) ##
453
+ *Lauro Caetano*, *Carlos Antonio da Silva*
415
454
 
416
- * No changes.
455
+ * Deprecate returning `nil` from `column_for_attribute` when no column exists.
456
+ It will return a null object in Rails 5.0
417
457
 
458
+ *Sean Griffin*
418
459
 
419
- ## Rails 4.1.4 (July 2, 2014) ##
460
+ * Implemented ActiveRecord::Base#pretty_print to work with PP.
420
461
 
421
- * Fix regression added from the latest security fix.
462
+ *Ethan*
422
463
 
423
- *Sean Griffin*, *Matthew Draper*
464
+ * Preserve type when dumping PostgreSQL point, bit, bit varying and money
465
+ columns.
424
466
 
467
+ *Yves Senn*
425
468
 
426
- ## Rails 4.1.3 (July 2, 2014) ##
469
+ * New records remain new after YAML serialization.
427
470
 
428
- * Fix SQL Injection Vulnerability in 'range' quoting.
471
+ *Sean Griffin*
429
472
 
430
- Fixes CVE-2014-3483
473
+ * PostgreSQL support default values for enum types. Fixes #7814.
431
474
 
432
- *Rafael Mendonça França*
475
+ *Yves Senn*
433
476
 
477
+ * PostgreSQL `default_sequence_name` respects schema. Fixes #7516.
434
478
 
435
- ## Rails 4.1.2 (June 26, 2014) ##
479
+ *Yves Senn*
436
480
 
437
- * Fix regression on eager loading association based on SQL query rather than
438
- existing column.
481
+ * Fixed `columns_for_distinct` of postgresql adapter to work correctly
482
+ with orders without sort direction modifiers.
439
483
 
440
- Fixes #15480.
484
+ *Nikolay Kondratyev*
441
485
 
442
- *Lauro Caetano*, *Carlos Antonio da Silva*
486
+ * PostgreSQL `reset_pk_sequence!` respects schemas. Fixes #14719.
487
+
488
+ *Yves Senn*
489
+
490
+ * Keep PostgreSQL `hstore` and `json` attributes as `Hash` in `@attributes`.
491
+ Fixes duplication in combination with `store_accessor`.
492
+
493
+ Fixes #15369.
494
+
495
+ *Yves Senn*
496
+
497
+ * `rake railties:install:migrations` respects the order of railties.
498
+
499
+ *Arun Agrawal*
443
500
 
444
501
  * Fix redefine a has_and_belongs_to_many inside inherited class
445
502
  Fixing regression case, where redefining the same has_an_belongs_to_many
@@ -463,2220 +520,612 @@
463
520
 
464
521
  *Godfrey Chan*
465
522
 
466
- * Fixed serialized fields returning serialized data after being updated with
467
- `update_column`.
468
-
469
- *Simon Hørup Eskildsen*
470
-
471
523
  * When a `group` is set, `sum`, `size`, `average`, `minimum` and `maximum`
472
524
  on a NullRelation should return a Hash.
473
525
 
474
526
  *Kuldeep Aggarwal*
475
527
 
476
- * Fixed polymorphic eager loading when using a String as foreign key.
477
-
478
- Fixes #14734.
479
-
480
- *Lauro Caetano*
481
-
482
- * Fixed the inferred table name of a has_and_belongs_to_many auxiliar
483
- table inside a schema.
484
-
485
- Fixes #14824
486
-
487
- *Eric Chahin*
488
-
489
- * Fix bug that added `table_name_prefix` and `table_name_suffix` to
490
- extension names in PostgreSQL when migrating.
491
-
492
- *Joao Carlos*
493
-
494
- * Floats with limit >= 25 that get turned into doubles in MySQL no longer have
495
- their limit dropped from the schema.
496
-
497
- Fixes #14135.
498
-
499
- *Aaron Nelson*
500
-
501
- * Fix how to calculate associated class name when using namespaced has_and_belongs_to_many
502
- association.
503
-
504
- Fixes #14709.
505
-
506
- *Kassio Borges*
507
-
508
- * `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and
509
- strings in column names as equal.
510
-
511
- This fixes a rare case in which more bind values are passed than there are
512
- placeholders for them in the generated SQL statement, which can make PostgreSQL
513
- throw a `StatementInvalid` exception.
514
-
515
- *Nat Budin*
516
-
517
- * Fix `stored_attributes` to correctly merge the details of stored
518
- attributes defined in parent classes.
519
-
520
- Fixes #14672.
521
-
522
- *Brad Bennett*, *Jessica Yao*, *Lakshmi Parthasarathy*
523
-
524
- * `change_column_default` allows `[]` as argument to `change_column_default`.
525
-
526
- Fixes #11586.
527
-
528
- *Yves Senn*
529
-
530
- * Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and
531
- NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
532
-
533
- Example:
534
-
535
- # Before
536
- Point.create(value: 1.0/0)
537
- Point.last.value # => 0.0
538
-
539
- # After
540
- Point.create(value: 1.0/0)
541
- Point.last.value # => Infinity
542
-
543
- *Innokenty Mikhailov*
544
-
545
- * Allow the PostgreSQL adapter to handle bigserial primary key types again.
546
-
547
- Fixes #10410.
548
-
549
- *Patrick Robertson*
550
-
551
- * Fixed has_and_belongs_to_many's CollectionAssociation size calculation.
552
-
553
- has_and_belongs_to_many should fall back to using the normal CollectionAssociation's
554
- size calculation if the collection is not cached or loaded.
555
-
556
- Fixes #14913 and #14914.
557
-
558
- *Fred Wu*
559
-
560
- * Revert the behaviour of `ActiveRecord::Relation#join` changed through 4.0 => 4.1 to 4.0.
561
-
562
- In 4.1.0 `Relation#join` is delegated to `Arel#SelectManager`.
563
- In 4.0 series it is delegated to `Array#join`.
564
-
565
- *Bogdan Gusiev*
566
-
567
- * Log nil binary column values correctly.
568
-
569
- When an object with a binary column is updated with a nil value
570
- in that column, the SQL logger would throw an exception when trying
571
- to log that nil value. This only occurs when updating a record
572
- that already has a non-nil value in that column since an initial nil
573
- value isn't included in the SQL anyway (at least, when dirty checking
574
- is enabled.) The column's new value will now be logged as `<NULL binary data>`
575
- to parallel the existing `<N bytes of binary data>` for non-nil values.
576
-
577
- *James Coleman*
578
-
579
- * Stringify all variables keys of MySQL connection configuration.
580
-
581
- When `sql_mode` variable for MySQL adapters set in configuration as `String`
582
- was ignored and overwritten by strict mode option.
583
-
584
- Fixes #14895.
585
-
586
- *Paul Nikitochkin*
587
-
588
- * Ensure SQLite3 statements are closed on errors.
589
-
590
- Fixes #13631.
591
-
592
- *Timur Alperovich*
593
-
594
- * Fix excluding lower bounds of PostgreSQL date and int ranges.
595
-
596
- *River MacLeod*, *Yves Senn*
597
-
598
- * When using a custom `join_table` name on a `habtm`, rails was not saving it
599
- on Reflections. This causes a problem when rails loads fixtures, because it
600
- uses the reflections to set database with fixtures.
601
-
602
- Fixes #14845.
603
-
604
- *Kassio Borges*
605
-
606
- * `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.
607
-
608
- Fixes #14841.
609
-
610
- *Lucas Mazza*
611
-
612
- * Fix name collision with `Array#select!` with `Relation#select!`.
613
-
614
- Fixes #14752.
615
-
616
- *Earl St Sauver*
617
-
618
- * Fixed unexpected behavior for `has_many :through` associations going through a scoped `has_many`.
619
-
620
- If a `has_many` association is adjusted using a scope, and another `has_many :through`
621
- uses this association, then the scope adjustment is unexpectedly neglected.
622
-
623
- Fixes #14537.
624
-
625
- *Jan Habermann*
626
-
627
- * When a destroyed record is duped, the dup is not `destroyed?`.
628
-
629
- *Kuldeep Aggarwal*
630
-
631
- * Fixed has_many association to make it support irregular inflections.
632
-
633
- Fixes #8928.
634
-
635
- *arthurnn*, *Javier Goizueta*
636
-
637
- * Calling `delete_all` on an unloaded `CollectionProxy` no longer
638
- generates a SQL statement containing each id of the collection:
639
-
640
- Before:
641
-
642
- DELETE FROM `model` WHERE `model`.`parent_id` = 1
643
- AND `model`.`id` IN (1, 2, 3...)
644
-
645
- After:
646
-
647
- DELETE FROM `model` WHERE `model`.`parent_id` = 1
648
-
649
- *Eileen M. Uchitelle*, *Aaron Patterson*
650
-
651
- * Fixed a problem where count used with a grouping was not returning a Hash.
652
-
653
- Fixes #14721.
654
-
655
- *Eric Chahin*
656
-
657
- * Do not quote uuid default value on `change_column`.
658
-
659
- Fixes #14604.
660
-
661
- *Eric Chahin*
662
-
663
- * The comparison between `Relation` and `CollectionProxy` should be consistent.
664
-
665
- Example:
666
-
667
- author.posts == Post.where(author_id: author.id)
668
- # => true
669
- Post.where(author_id: author.id) == author.posts
670
- # => true
671
-
672
- Fixes #13506.
673
-
674
- *Lauro Caetano*
675
-
676
- * PostgreSQL adapter only warns once for every missing OID per connection.
677
-
678
- Fixes #14275.
679
-
680
- *Matthew Draper*, *Yves Senn*
681
-
682
- * Fixed error for aggregate methods (`empty?`, `any?`, `count`) with `select`
683
- which created invalid SQL.
684
-
685
- Fixes #13648.
686
-
687
- *Simon Woker*
688
-
689
- * Fix insertion of records via `has_many :through` association with scope.
690
-
691
- Fixes #3548.
692
-
693
- *Ivan Antropov*
694
-
695
- * Make possible to have an association called `records`.
696
-
697
- Fixes #11645.
698
-
699
- *prathamesh-sonpatki*
700
-
701
- * `to_sql` on an association now matches the query that is actually executed, where it
702
- could previously have incorrectly accrued additional conditions (e.g. as a result of
703
- a previous query). CollectionProxy now always defers to the association scope's
704
- `arel` method so the (incorrect) inherited one should be entirely concealed.
705
-
706
- Fixes #14003.
707
-
708
- *Jefferson Lai*
709
-
710
- * Fixed error when using `with_options` with lambda.
711
-
712
- Fixes #9805.
713
-
714
- *Lauro Caetano*
715
-
716
- * Fixed error when specifying a non-empty default value on a PostgreSQL array column.
717
-
718
- Fixes #10613.
719
-
720
- *Luke Steensen*
721
-
722
- * Fixed error where .persisted? throws SystemStackError for an unsaved model with a
723
- custom primary key that didn't save due to validation error.
724
-
725
- Fixes #14393.
726
-
727
- *Chris Finne*
728
-
729
- * `rake db:structure:dump` only dumps schema information if the schema
730
- migration table exists.
731
-
732
- Fixes #14217.
733
-
734
- *Yves Senn*
735
-
736
- * Add support for `Relation` be passed as parameter on `QueryCache#select_all`.
737
-
738
- Fixes #14361.
739
-
740
- *arthurnn*
741
-
742
- * Only save `has_one` associations if record has changes. Previously after save
743
- related callbacks, such as `#after_commit`, were triggered when the
744
- `has_one` object did not get saved to the db.
745
-
746
- *Alan Kennedy*
747
-
748
-
749
- ## Rails 4.1.1 (May 6, 2014) ##
750
-
751
- * No changes.
752
-
753
-
754
- ## Rails 4.1.0 (April 8, 2014) ##
755
-
756
- * Fixed a problem where an enum would overwrite values of another enum
757
- with the same name in an unrelated class.
758
-
759
- Fixes #14607.
760
-
761
- *Evan Whalen*
762
-
763
-
764
- * Block a few default Class methods as scope name.
765
-
766
- For instance, this will raise:
767
-
768
- scope :public, -> { where(status: 1) }
769
-
770
- *arthurnn*
771
-
772
- * Deprecate SQLite database URLs containing an
773
- authority.
774
-
775
- The current "correct" spellings for in-memory, relative, and
776
- absolute URLs, respectively, are:
777
-
778
- sqlite3::memory:
779
- sqlite3:relative/path
780
- sqlite3:/full/path
781
-
782
- The previous spelling (`sqlite3:///relative/path`) continues to work
783
- as it did in Rails 4.0, but with a deprecation warning: in the next
784
- release, that spelling will instead be interpreted as an absolute
785
- path.
786
-
787
- *Matthew Draper*
788
-
789
- * `where.not` adds `references` for `includes` like normal `where` calls do.
790
-
791
- Fixes #14406.
792
-
793
- *Yves Senn*
794
-
795
- * `includes` is able to detect the right preloading strategy when string
796
- joins are involved.
797
-
798
- Fixes #14109.
799
-
800
- *Aaron Patterson*, *Yves Senn*
801
-
802
- * Fixed error with validation with enum fields for records where the
803
- value for any enum attribute is always evaluated as 0 during
804
- uniqueness validation.
805
-
806
- Fixes #14172.
807
-
808
- *Vilius Luneckas* *Ahmed AbouElhamayed*
809
-
810
- * `before_add` callbacks are fired before the record is saved on
811
- `has_and_belongs_to_many` assocations *and* on `has_many :through`
812
- associations. Before this change, `before_add` callbacks would be fired
813
- before the record was saved on `has_and_belongs_to_many` associations, but
814
- *not* on `has_many :through` associations.
815
-
816
- Fixes #14144.
817
-
818
- * Fixed STI classes not defining an attribute method if there is a
819
- conflicting private method defined on its ancestors.
820
-
821
- Fixes #11569.
822
-
823
- *Godfrey Chan*
824
-
825
- * Default scopes are no longer overriden by chained conditions.
826
-
827
- Before this change when you defined a `default_scope` in a model
828
- it was overriden by chained conditions in the same field. Now it
829
- is merged like any other scope.
830
-
831
- Before:
832
-
833
- class User < ActiveRecord::Base
834
- default_scope { where state: 'pending' }
835
- scope :active, -> { where state: 'active' }
836
- scope :inactive, -> { where state: 'inactive' }
837
- end
838
-
839
- User.all
840
- # SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
841
-
842
- User.active
843
- # SELECT "users".* FROM "users" WHERE "users"."state" = 'active'
844
-
845
- User.where(state: 'inactive')
846
- # SELECT "users".* FROM "users" WHERE "users"."state" = 'inactive'
847
-
848
- After:
849
-
850
- class User < ActiveRecord::Base
851
- default_scope { where state: 'pending' }
852
- scope :active, -> { where state: 'active' }
853
- scope :inactive, -> { where state: 'inactive' }
854
- end
855
-
856
- User.all
857
- # SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
858
-
859
- User.active
860
- # SELECT "users".* FROM "users" WHERE "users"."state" = 'pending' AND "users"."state" = 'active'
861
-
862
- User.where(state: 'inactive')
863
- # SELECT "users".* FROM "users" WHERE "users"."state" = 'pending' AND "users"."state" = 'inactive'
864
-
865
- To get the previous behavior it is needed to explicitly remove the
866
- `default_scope` condition using `unscoped`, `unscope`, `rewhere` or
867
- `except`.
868
-
869
- Example:
870
-
871
- class User < ActiveRecord::Base
872
- default_scope { where state: 'pending' }
873
- scope :active, -> { unscope(where: :state).where(state: 'active') }
874
- scope :inactive, -> { rewhere state: 'inactive' }
875
- end
876
-
877
- User.all
878
- # SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
879
-
880
- User.active
881
- # SELECT "users".* FROM "users" WHERE "users"."state" = 'active'
882
-
883
- User.inactive
884
- # SELECT "users".* FROM "users" WHERE "users"."state" = 'inactive'
885
-
886
- * Perform necessary deeper encoding when hstore is inside an array.
887
-
888
- Fixes #11135.
889
-
890
- *Josh Goodall*, *Genadi Samokovarov*
891
-
892
- * Properly detect if a connection is still active before using it
893
- in multi-threaded environments.
894
-
895
- Fixes #12867.
896
-
897
- *Kevin Casey*, *Matthew Draper*, *William (B.J.) Snow Orvis*
898
-
899
- * When inverting add_index use the index name if present instead of
900
- the columns.
901
-
902
- If there are two indices with matching columns and one of them is
903
- explicitly named then reverting the migration adding the named one
904
- would instead drop the unnamed one.
905
-
906
- The inversion of add_index will now drop the index by its name if
907
- it is present.
908
-
909
- *Hubert Dąbrowski*
910
-
911
- * Add flag to disable schema dump after migration.
912
-
913
- Add a config parameter on Active Record named `dump_schema_after_migration`
914
- which is true by default. Now schema dump does not happen at the
915
- end of migration rake task if `dump_schema_after_migration` is false.
916
-
917
- *Emil Soman*
918
-
919
- * `find_in_batches`, `find_each`, `Result#each` and `Enumerable#index_by` now
920
- return an `Enumerator` that can calculate its size.
921
-
922
- See also #13938.
923
-
924
- *Marc-André Lafortune*
925
-
926
- * Make sure transaction state gets reset after a commit operation on the record.
927
-
928
- If a new transaction was open inside a callback, the record was loosing track
929
- of the transaction level state, and it was leaking that state.
930
-
931
- Fixes #12566.
932
-
933
- *arthurnn*
934
-
935
- * Pass `has_and_belongs_to_many` `:autosave` option to
936
- the underlying `has_many :through` association.
937
-
938
- Fixes #13923.
939
-
940
- *Yves Senn*
941
-
942
- * PostgreSQL implementation of `SchemaStatements#index_name_exists?`.
943
-
944
- The database agnostic implementation does not detect with indexes that are
945
- not supported by the ActiveRecord schema dumper. For example, expressions
946
- indexes would not be detected.
947
-
948
- Fixes #11018.
949
-
950
- *Jonathan Baudanza*
951
-
952
- * Parsing PostgreSQL arrays with empty strings now works correctly.
953
-
954
- Previously, if you tried to parse `{"1","","2","","3"}` the result
955
- would be `["1","2","3"]`, removing the empty strings from the array,
956
- which would be incorrect. Now it will correctly produce `["1","","2","","3"]`
957
- as the result of parsing the above PostgreSQL array.
958
-
959
- Fixes #13907.
960
-
961
- *Maurício Linhares*
962
-
963
- * Associations now raise `ArgumentError` on name conflicts.
964
-
965
- Dangerous association names conflicts include instance or class methods already
966
- defined by `ActiveRecord::Base`.
967
-
968
- Example:
969
-
970
- class Car < ActiveRecord::Base
971
- has_many :errors
972
- end
973
- # Will raise ArgumentError.
974
-
975
- Fixes #13217.
976
-
977
- *Lauro Caetano*
978
-
979
- * Fix regressions on `select_*` methods.
980
- When `select_*` methods receive a `Relation` object, they should be able to
981
- get the arel/binds from it.
982
- Also fix regressions on `select_rows` that was ignoring the binds.
983
-
984
- Fixes #7538, #12017, #13731, #12056.
985
-
986
- *arthurnn*
987
-
988
- * Active Record objects can now be correctly dumped, loaded and dumped again
989
- without issues.
990
-
991
- Previously, if you did `YAML.dump`, `YAML.load` and then `YAML.dump` again
992
- in an Active Record model that used serialization it would fail at the last
993
- dump due to the fields not being correctly serialized before being dumped
994
- to YAML. Now it is possible to dump and load the same object as many times
995
- as needed without any issues.
996
-
997
- Fixes #13861.
998
-
999
- *Maurício Linhares*
1000
-
1001
- * `find_in_batches` now returns an `Enumerator` when called without a block, so that it
1002
- can be chained with other `Enumerable` methods.
1003
-
1004
- *Marc-André Lafortune*
1005
-
1006
- * `enum` now raises on "dangerous" name conflicts.
1007
-
1008
- Dangerous name conflicts includes instance or class method conflicts
1009
- with methods defined within `ActiveRecord::Base` but not its ancestors,
1010
- as well as conflicts with methods generated by other enums on the same
1011
- class.
1012
-
1013
- Fixes #13389.
1014
-
1015
- *Godfrey Chan*
1016
-
1017
- * `scope` now raises on "dangerous" name conflicts.
1018
-
1019
- Similar to dangerous attribute methods, a scope name conflict is
1020
- dangerous if it conflicts with an existing class method defined within
1021
- `ActiveRecord::Base` but not its ancestors.
1022
-
1023
- See also #13389.
1024
-
1025
- *Godfrey Chan*, *Philippe Creux*
1026
-
1027
- * Correctly send an user provided statement to a `lock!()` call.
1028
-
1029
- person.lock! 'FOR SHARE NOWAIT'
1030
- # Before: SELECT * ... LIMIT 1 FOR UPDATE
1031
- # After: SELECT * ... LIMIT 1 FOR SHARE NOWAIT
1032
-
1033
- Fixes #13788.
1034
-
1035
- *Maurício Linhares*
1036
-
1037
- * Handle aliased attributes `select()`, `order()` and `reorder()`.
1038
-
1039
- *Tsutomu Kuroda*
1040
-
1041
- * Reset the collection association when calling `reset` on it.
1042
-
1043
- Before:
1044
-
1045
- post.comments.loaded? # => true
1046
- post.comments.reset
1047
- post.comments.loaded? # => true
1048
-
1049
- After:
1050
-
1051
- post.comments.loaded? # => true
1052
- post.comments.reset
1053
- post.comments.loaded? # => false
1054
-
1055
- Fixes #13777.
1056
-
1057
- *Kelsey Schlarman*
1058
-
1059
- * Make enum fields work as expected with the `ActiveModel::Dirty` API.
1060
-
1061
- Before this change, using the dirty API would have surprising results:
1062
-
1063
- conversation = Conversation.new
1064
- conversation.status = :active
1065
- conversation.status = :archived
1066
- conversation.status_was # => 0
1067
-
1068
- After this change, the same code would result in:
1069
-
1070
- conversation = Conversation.new
1071
- conversation.status = :active
1072
- conversation.status = :archived
1073
- conversation.status_was # => "active"
1074
-
1075
- *Rafael Mendonça França*
1076
-
1077
- * `has_one` and `belongs_to` accessors don't add ORDER BY to the queries
1078
- anymore.
1079
-
1080
- Since Rails 4.0, we add an ORDER BY in the `first` method to ensure
1081
- consistent results among different database engines. But for singular
1082
- associations this behavior is not needed since we will have one record to
1083
- return. As this ORDER BY option can lead some performance issues we are
1084
- removing it for singular associations accessors.
1085
-
1086
- Fixes #12623.
1087
-
1088
- *Rafael Mendonça França*
1089
-
1090
- * Prepend table name for column names passed to `Relation#select`.
1091
-
1092
- Example:
1093
-
1094
- Post.select(:id)
1095
- # Before: => SELECT id FROM "posts"
1096
- # After: => SELECT "posts"."id" FROM "posts"
1097
-
1098
- *Yves Senn*
1099
-
1100
- * Fail early with "Primary key not included in the custom select clause"
1101
- in `find_in_batches`.
1102
-
1103
- Before this patch, the exception was raised after the first batch was
1104
- yielded to the block. This means that you only get it, when you hit the
1105
- `batch_size` treshold. This could shadow the issue in development.
1106
-
1107
- *Alexander Balashov*
1108
-
1109
- * Ensure `second` through `fifth` methods act like the `first` finder.
1110
-
1111
- The famous ordinal Array instance methods defined in ActiveSupport
1112
- (`first`, `second`, `third`, `fourth`, and `fifth`) are now available as
1113
- full-fledged finders in ActiveRecord. The biggest benefit of this is ordering
1114
- of the records returned now defaults to the table's primary key in ascending order.
1115
-
1116
- Fixes #13743.
1117
-
1118
- Example:
1119
-
1120
- User.all.second
1121
-
1122
- # Before
1123
- # => 'SELECT "users".* FROM "users"'
1124
-
1125
- # After
1126
- # => SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 OFFSET 1'
1127
-
1128
- User.offset(3).second
1129
-
1130
- # Before
1131
- # => 'SELECT "users".* FROM "users" LIMIT -1 OFFSET 3' # sqlite3 gem
1132
- # => 'SELECT "users".* FROM "users" OFFSET 3' # pg gem
1133
- # => 'SELECT `users`.* FROM `users` LIMIT 18446744073709551615 OFFSET 3' # mysql2 gem
1134
-
1135
- # After
1136
- # => SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 OFFSET 4'
1137
-
1138
- *Jason Meller*
1139
-
1140
- * ActiveRecord states are now correctly restored after a rollback for
1141
- models that did not define any transactional callbacks (i.e.
1142
- `after_commit`, `after_rollback` or `after_create`).
1143
-
1144
- Fixes #13744.
1145
-
1146
- *Godfrey Chan*
1147
-
1148
- * Make `touch` fire the `after_commit` and `after_rollback` callbacks.
1149
-
1150
- *Harry Brundage*
1151
-
1152
- * Enable partial indexes for `sqlite >= 3.8.0`.
1153
-
1154
- See http://www.sqlite.org/partialindex.html
1155
-
1156
- *Cody Cutrer*
1157
-
1158
- * Don't try to get the subclass if the inheritance column doesn't exist
1159
-
1160
- The `subclass_from_attrs` method is called even if the column specified by
1161
- the `inheritance_column` setting doesn't exist. This prevents setting associations
1162
- via the attributes hash if the association name clashes with the value of the setting,
1163
- typically `:type`. This worked previously in Rails 3.2.
1164
-
1165
- *Ujjwal Thaakar*
1166
-
1167
- * Enum mappings are now exposed via class methods instead of constants.
1168
-
1169
- Example:
1170
-
1171
- class Conversation < ActiveRecord::Base
1172
- enum status: [ :active, :archived ]
1173
- end
1174
-
1175
- Before:
1176
-
1177
- Conversation::STATUS # => { "active" => 0, "archived" => 1 }
1178
-
1179
- After:
1180
-
1181
- Conversation.statuses # => { "active" => 0, "archived" => 1 }
1182
-
1183
- *Godfrey Chan*
1184
-
1185
- * Set `NameError#name` when STI-class-lookup fails.
1186
-
1187
- *Chulki Lee*
1188
-
1189
- * Fix bug in `becomes!` when changing from the base model to a STI sub-class.
1190
-
1191
- Fixes #13272.
1192
-
1193
- *the-web-dev*, *Yves Senn*
1194
-
1195
- * Currently Active Record can be configured via the environment variable
1196
- `DATABASE_URL` or by manually injecting a hash of values which is what Rails does,
1197
- reading in `database.yml` and setting Active Record appropriately. Active Record
1198
- expects to be able to use `DATABASE_URL` without the use of Rails, and we cannot
1199
- rip out this functionality without deprecating. This presents a problem though
1200
- when both config is set, and a `DATABASE_URL` is present. Currently the
1201
- `DATABASE_URL` should "win" and none of the values in `database.yml` are
1202
- used. This is somewhat unexpected, if one were to set values such as
1203
- `pool` in the `production:` group of `database.yml` they are ignored.
1204
-
1205
- There are many ways that Active Record initiates a connection today:
1206
-
1207
- - Stand Alone (without rails)
1208
- - `rake db:<tasks>`
1209
- - `ActiveRecord.establish_connection`
1210
-
1211
- - With Rails
1212
- - `rake db:<tasks>`
1213
- - `rails <server> | <console>`
1214
- - `rails dbconsole`
1215
-
1216
- Now all of these behave exactly the same way. The best way to do
1217
- this is to put all of this logic in one place so it is guaranteed to be used.
1218
-
1219
- Here is the matrix of how this behavior works:
1220
-
1221
- ```
1222
- No database.yml
1223
- No DATABASE_URL
1224
- => Error
1225
- ```
1226
-
1227
- ```
1228
- database.yml present
1229
- No DATABASE_URL
1230
- => Use database.yml configuration
1231
- ```
1232
-
1233
- ```
1234
- No database.yml
1235
- DATABASE_URL present
1236
- => use DATABASE_URL configuration
1237
- ```
1238
-
1239
- ```
1240
- database.yml present
1241
- DATABASE_URL present
1242
- => Merged into `url` sub key. If both specify `url` sub key, the `database.yml` `url`
1243
- sub key "wins". If other paramaters `adapter` or `database` are specified in YAML,
1244
- they are discarded as the `url` sub key "wins".
1245
- ```
1246
-
1247
- Current implementation uses `ActiveRecord::Base.configurations` to resolve and merge
1248
- all connection information before returning. This is achieved through a utility
1249
- class: `ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig`.
1250
-
1251
- To understand the exact behavior of this class, it is best to review the
1252
- behavior in `activerecord/test/cases/connection_adapters/connection_handler_test.rb`.
1253
-
1254
- *Richard Schneeman*
1255
-
1256
- * Make `change_column_null` revertable. Fixes #13576.
1257
-
1258
- *Yves Senn*, *Nishant Modak*, *Prathamesh Sonpatki*
1259
-
1260
- * Don't create/drop the test database if RAILS_ENV is specified explicitly.
1261
-
1262
- Previously, when the environment was development, we would always
1263
- create or drop both the test and development databases.
1264
-
1265
- Now, if RAILS_ENV is explicitly defined as development, we don't create
1266
- the test database.
1267
-
1268
- *Damien Mathieu*
1269
-
1270
- * Initialize version on Migration objects so that it can be used in a migration,
1271
- and it will be included in the announce message.
1272
-
1273
- *Dylan Thacker-Smith*
1274
-
1275
- * `change_table` now uses the current adapter's `update_table_definition`
1276
- method to retrieve a specific table definition.
1277
- This ensures that `change_table` and `create_table` will use
1278
- similar objects.
1279
-
1280
- Fixes #13577, #13503.
1281
-
1282
- *Nishant Modak*, *Prathamesh Sonpatki*, *Rafael Mendonça França*
1283
-
1284
- * Fixed ActiveRecord::Store nil conversion TypeError when using YAML coder.
1285
- In case the YAML passed as paramter is nil, uses an empty string.
1286
-
1287
- Fixes #13570.
1288
-
1289
- *Thales Oliveira*
1290
-
1291
- * Deprecate unused `ActiveRecord::Base.symbolized_base_class`
1292
- and `ActiveRecord::Base.symbolized_sti_name` without replacement.
1293
-
1294
- *Yves Senn*
1295
-
1296
- * Since the `test_help.rb` file in Railties now automatically maintains
1297
- your test schema, the `rake db:test:*` tasks are deprecated. This
1298
- doesn't stop you manually running other tasks on your test database
1299
- if needed:
1300
-
1301
- rake db:schema:load RAILS_ENV=test
1302
-
1303
- *Jon Leighton*
1304
-
1305
- * Fix presence validator for association when the associated record responds to `to_a`.
1306
-
1307
- *gmarik*
1308
-
1309
- * Fixed regression on preload/includes with multiple arguments failing in certain conditions,
1310
- raising a NoMethodError internally by calling `reflect_on_association` for `NilClass:Class`.
1311
-
1312
- Fixes #13437.
1313
-
1314
- *Vipul A M*, *khustochka*
1315
-
1316
- * Add the ability to nullify the `enum` column.
1317
-
1318
- Example:
1319
-
1320
- class Conversation < ActiveRecord::Base
1321
- enum gender: [:female, :male]
1322
- end
1323
-
1324
- Conversation::GENDER # => { female: 0, male: 1 }
1325
-
1326
- # conversation.update! gender: 0
1327
- conversation.female!
1328
- conversation.female? # => true
1329
- conversation.gender # => "female"
1330
-
1331
- # conversation.update! gender: nil
1332
- conversation.gender = nil
1333
- conversation.gender.nil? # => true
1334
- conversation.gender # => nil
1335
-
1336
- *Amr Tamimi*
1337
-
1338
- * Connection specification now accepts a "url" key. The value of this
1339
- key is expected to contain a database URL. The database URL will be
1340
- expanded into a hash and merged.
1341
-
1342
- *Richard Schneeman*
1343
-
1344
- * An `ArgumentError` is now raised on a call to `Relation#where.not(nil)`.
1345
-
1346
- Example:
1347
-
1348
- User.where.not(nil)
1349
-
1350
- # Before
1351
- # => 'SELECT `users`.* FROM `users` WHERE (NOT (NULL))'
1352
-
1353
- # After
1354
- # => ArgumentError, 'Invalid argument for .where.not(), got nil.'
1355
-
1356
- *Kuldeep Aggarwal*
1357
-
1358
- * Deprecated use of string argument as a configuration lookup in
1359
- `ActiveRecord::Base.establish_connection`. Instead, a symbol must be given.
1360
-
1361
- *José Valim*
1362
-
1363
- * Fixed `update_column`, `update_columns`, and `update_all` to correctly serialize
1364
- values for `array`, `hstore` and `json` column types in PostgreSQL.
1365
-
1366
- Fixes #12261.
1367
-
1368
- *Tadas Tamosauskas*, *Carlos Antonio da Silva*
1369
-
1370
- * Do not consider PostgreSQL array columns as number or text columns.
1371
-
1372
- The code uses these checks in several places to know what to do with a
1373
- particular column, for instance AR attribute query methods has a branch
1374
- like this:
1375
-
1376
- if column.number?
1377
- !value.zero?
1378
- end
1379
-
1380
- This should never be true for array columns, since it would be the same
1381
- as running [].zero?, which results in a NoMethodError exception.
1382
-
1383
- Fixing this by ensuring that array columns in PostgreSQL never return
1384
- true for number?/text? checks.
1385
-
1386
- *Carlos Antonio da Silva*
1387
-
1388
- * When connecting to a non-existant database, the error:
1389
- `ActiveRecord::NoDatabaseError` will now be raised. When being used with Rails
1390
- the error message will include information on how to create a database:
1391
- `rake db:create`. Supported adapters: postgresql, mysql, mysql2, sqlite3
1392
-
1393
- *Richard Schneeman*
1394
-
1395
- * Do not raise `'cannot touch on a new record object'` exception on destroying
1396
- already destroyed `belongs_to` association with `touch: true` option.
1397
-
1398
- Fixes #13445.
1399
-
1400
- Example:
1401
-
1402
- # Given Comment has belongs_to :post, touch: true
1403
- comment.post.destroy
1404
- comment.destroy # no longer raises an error
1405
-
1406
- *Paul Nikitochkin*
1407
-
1408
- * Fix a bug when assigning an array containing string numbers to a
1409
- PostgreSQL integer array column.
1410
-
1411
- Fixes #13444.
1412
-
1413
- Example:
1414
-
1415
- # Given Book#ratings is of type :integer, array: true
1416
- Book.new(ratings: [1, 2]) # worked before
1417
- Book.new(ratings: ['1', '2']) # now works as well
1418
-
1419
- *Damien Mathieu*
1420
-
1421
- * Fix `PostgreSQL` insert to properly extract table name from multiline string SQL.
1422
-
1423
- Previously, executing an insert SQL in `PostgreSQL` with a command like this:
1424
-
1425
- insert into articles(
1426
- number)
1427
- values(
1428
- 5152
1429
- )
1430
-
1431
- would not work because the adapter was unable to extract the correct `articles`
1432
- table name.
1433
-
1434
- *Kuldeep Aggarwal*
1435
-
1436
- * Correctly escape PostgreSQL arrays.
1437
-
1438
- Fixes: CVE-2014-0080
1439
-
1440
- * `Relation` no longer has mutator methods like `#map!` and `#delete_if`. Convert
1441
- to an `Array` by calling `#to_a` before using these methods.
1442
-
1443
- It intends to prevent odd bugs and confusion in code that call mutator
1444
- methods directly on the `Relation`.
1445
-
1446
- Example:
1447
-
1448
- # Instead of this
1449
- Author.where(name: 'Hank Moody').compact!
1450
-
1451
- # Now you have to do this
1452
- authors = Author.where(name: 'Hank Moody').to_a
1453
- authors.compact!
1454
-
1455
- *Lauro Caetano*
1456
-
1457
- * Better support for `where()` conditions that use a `belongs_to`
1458
- association name.
1459
-
1460
- Using the name of an association in `where` previously worked only
1461
- if the value was a single `ActiveRecord::Base` object. e.g.
1462
-
1463
- Post.where(author: Author.first)
1464
-
1465
- Any other values, including `nil`, would cause invalid SQL to be
1466
- generated. This change supports arguments in the `where` query
1467
- conditions where the key is a `belongs_to` association name and the
1468
- value is `nil`, an `Array` of `ActiveRecord::Base` objects, or an
1469
- `ActiveRecord::Relation` object.
1470
-
1471
- class Post < ActiveRecord::Base
1472
- belongs_to :author
1473
- end
1474
-
1475
- `nil` value finds records where the association is not set:
1476
-
1477
- Post.where(author: nil)
1478
- # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL
1479
-
1480
- `Array` values find records where the association foreign key
1481
- matches the ids of the passed ActiveRecord models, resulting
1482
- in the same query as `Post.where(author_id: [1,2])`:
1483
-
1484
- authors_array = [Author.find(1), Author.find(2)]
1485
- Post.where(author: authors_array)
1486
- # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IN (1, 2)
1487
-
1488
- `ActiveRecord::Relation` values find records using the same
1489
- query as `Post.where(author_id: Author.where(last_name: "Emde"))`
1490
-
1491
- Post.where(author: Author.where(last_name: "Emde"))
1492
- # SELECT "posts".* FROM "posts"
1493
- # WHERE "posts"."author_id" IN (
1494
- # SELECT "authors"."id" FROM "authors"
1495
- # WHERE "authors"."last_name" = 'Emde')
1496
-
1497
- Polymorphic `belongs_to` associations will continue to be handled
1498
- appropriately, with the polymorphic `association_type` field added
1499
- to the query to match the base class of the value. This feature
1500
- previously only worked when the value was a single `ActveRecord::Base`.
1501
-
1502
- class Post < ActiveRecord::Base
1503
- belongs_to :author, polymorphic: true
1504
- end
1505
-
1506
- Post.where(author: Author.where(last_name: "Emde"))
1507
- # Generates a query similar to:
1508
- Post.where(author_id: Author.where(last_name: "Emde"), author_type: "Author")
1509
-
1510
- *Martin Emde*
1511
-
1512
- * Respect temporary option when dropping tables with MySQL.
1513
-
1514
- Normal DROP TABLE also works, but commits the transaction.
1515
-
1516
- drop_table :temporary_table, temporary: true
1517
-
1518
- *Cody Cutrer*
1519
-
1520
- * Add option to create tables from a query.
1521
-
1522
- create_table(:long_query, temporary: true,
1523
- as: "SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id")
1524
-
1525
- Generates:
1526
-
1527
- CREATE TEMPORARY TABLE long_query AS
1528
- SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id
1529
-
1530
- *Cody Cutrer*
1531
-
1532
- * `db:test:clone` and `db:test:prepare` must load Rails environment.
1533
-
1534
- `db:test:clone` and `db:test:prepare` use `ActiveRecord::Base`. configurations,
1535
- so we need to load the Rails environment, otherwise the config wont be in place.
1536
-
1537
- *arthurnn*
1538
-
1539
- * Use the right column to type cast grouped calculations with custom expressions.
1540
-
1541
- Fixes #13230.
1542
-
1543
- Example:
1544
-
1545
- # Before
1546
- Account.group(:firm_name).sum('0.01 * credit_limit')
1547
- # => { '37signals' => '0.5' }
1548
-
1549
- # After
1550
- Account.group(:firm_name).sum('0.01 * credit_limit')
1551
- # => { '37signals' => 0.5 }
1552
-
1553
- *Paul Nikitochkin*
1554
-
1555
- * Polymorphic `belongs_to` associations with the `touch: true` option set update the timestamps of
1556
- the old and new owner correctly when moved between owners of different types.
1557
-
1558
- Example:
1559
-
1560
- class Rating < ActiveRecord::Base
1561
- belongs_to :rateable, polymorphic: true, touch: true
1562
- end
1563
-
1564
- rating = Rating.create rateable: Song.find(1)
1565
- rating.update_attributes rateable: Book.find(2) # => timestamps of Song(1) and Book(2) are updated
1566
-
1567
- *Severin Schoepke*
1568
-
1569
- * Improve formatting of migration exception messages: make them easier to read
1570
- with line breaks before/after, and improve the error for pending migrations.
1571
-
1572
- *John Bachir*
1573
-
1574
- * Fix `last` with `offset` to return the proper record instead of always the last one.
1575
-
1576
- Example:
1577
-
1578
- Model.offset(4).last
1579
- # => returns the 4th record from the end.
1580
-
1581
- Fixes #7441.
1582
-
1583
- *kostya*, *Lauro Caetano*
1584
-
1585
- * `type_to_sql` returns a `String` for unmapped columns. This fixes an error
1586
- when using unmapped PostgreSQL array types.
1587
-
1588
- Example:
1589
-
1590
- change_colum :table, :column, :bigint, array: true
1591
-
1592
- Fixes #13146.
1593
-
1594
- *Jens Fahnenbruck*, *Yves Senn*
1595
-
1596
- * Fix `QueryCache` to work with nested blocks, so that it will only clear the existing cache
1597
- after leaving the outer block instead of clearing it right after the inner block is finished.
1598
-
1599
- *Vipul A M*
1600
-
1601
- * The ERB in fixture files is no longer evaluated in the context of the main
1602
- object. Helper methods used by multiple fixtures should be defined on the
1603
- class object returned by `ActiveRecord::FixtureSet.context_class`.
1604
-
1605
- *Victor Costan*
1606
-
1607
- * Previously, the `has_one` macro incorrectly accepted the `counter_cache`
1608
- option, but never actually supported it. Now it will raise an `ArgumentError`
1609
- when using `has_one` with `counter_cache`.
1610
-
1611
- *Godfrey Chan*
1612
-
1613
- * Implement `rename_index` natively for MySQL >= 5.7.
1614
-
1615
- *Cody Cutrer*
1616
-
1617
- * Fix bug when validating the uniqueness of an aliased attribute.
1618
-
1619
- Fixes #12402.
1620
-
1621
- *Lauro Caetano*
1622
-
1623
- * Update counter cache on a `has_many` relationship regardless of default scope.
1624
-
1625
- Fixes #12952.
1626
-
1627
- *Uku Taht*
1628
-
1629
- * `rename_index` adds the new index before removing the old one. This allows to
1630
- rename indexes on columns with a foreign key and prevents the following error:
1631
-
1632
- Cannot drop index 'index_engines_on_car_id': needed in a foreign key constraint
1633
-
1634
- *Cody Cutrer*, *Yves Senn*
1635
-
1636
- * Raise `ActiveRecord::RecordNotDestroyed` when a replaced child
1637
- marked with `dependent: destroy` fails to be destroyed.
1638
-
1639
- Fixes #12812.
1640
-
1641
- *Brian Thomas Storti*
1642
-
1643
- * Fix validation on uniqueness of empty association.
1644
-
1645
- *Evgeny Li*
1646
-
1647
- * Make `ActiveRecord::Relation#unscope` affect relations it is merged in to.
1648
-
1649
- *Jon Leighton*
1650
-
1651
- * Use strings to represent non-string `order_values`.
1652
-
1653
- *Yves Senn*
1654
-
1655
- * Checks to see if the record contains the foreign key to set the inverse automatically.
1656
-
1657
- *Edo Balvers*
1658
-
1659
- * Added `ActiveRecord::Base.to_param` for convenient "pretty" URLs derived from a model's attribute or method.
1660
-
1661
- Example:
1662
-
1663
- class User < ActiveRecord::Base
1664
- to_param :name
1665
- end
1666
-
1667
- user = User.find_by(name: 'Fancy Pants')
1668
- user.id # => 123
1669
- user.to_param # => "123-fancy-pants"
1670
-
1671
- *Javan Makhmali*
1672
-
1673
- * Added `ActiveRecord::Base.no_touching`, which allows ignoring touch on models.
1674
-
1675
- Example:
1676
-
1677
- Post.no_touching do
1678
- Post.first.touch
1679
- end
1680
-
1681
- *Sam Stephenson*, *Damien Mathieu*
1682
-
1683
- * Prevent the counter cache from being decremented twice when destroying
1684
- a record on a `has_many :through` association.
1685
-
1686
- Fixes #11079.
1687
-
1688
- *Dmitry Dedov*
1689
-
1690
- * Unify boolean type casting for `MysqlAdapter` and `Mysql2Adapter`.
1691
- `type_cast` will return `1` for `true` and `0` for `false`.
1692
-
1693
- Fixes #11119.
1694
-
1695
- *Adam Williams*, *Yves Senn*
1696
-
1697
- * Fix bug where `has_one` association record update result in crash, when replaced with itself.
1698
-
1699
- Fixes #12834.
1700
-
1701
- *Denis Redozubov*, *Sergio Cambra*
1702
-
1703
- * Log bind variables after they are type casted. This makes it more
1704
- transparent what values are actually sent to the database.
1705
-
1706
- irb(main):002:0> Event.find("im-no-integer")
1707
- # Before: ... WHERE "events"."id" = $1 LIMIT 1 [["id", "im-no-integer"]]
1708
- # After: ... WHERE "events"."id" = $1 LIMIT 1 [["id", 0]]
1709
-
1710
- *Yves Senn*
1711
-
1712
- * Fix uninitialized constant `TransactionState` error when `Marshall.load` is used on an Active Record result.
1713
-
1714
- Fixes #12790.
1715
-
1716
- *Jason Ayre*
1717
-
1718
- * `.unscope` now removes conditions specified in `default_scope`.
1719
-
1720
- *Jon Leighton*
1721
-
1722
- * Added `ActiveRecord::QueryMethods#rewhere` which will overwrite an existing, named where condition.
1723
-
1724
- Examples:
1725
-
1726
- Post.where(trashed: true).where(trashed: false) #=> WHERE `trashed` = 1 AND `trashed` = 0
1727
- Post.where(trashed: true).rewhere(trashed: false) #=> WHERE `trashed` = 0
1728
- Post.where(active: true).where(trashed: true).rewhere(trashed: false) #=> WHERE `active` = 1 AND `trashed` = 0
1729
-
1730
- *DHH*
1731
-
1732
- * Extend `ActiveRecord::Base#cache_key` to take an optional list of timestamp attributes of which the highest will be used.
1733
-
1734
- Example:
1735
-
1736
- # last_reviewed_at will be used, if that's more recent than updated_at, or vice versa
1737
- Person.find(5).cache_key(:updated_at, :last_reviewed_at)
1738
-
1739
- *DHH*
1740
-
1741
- * Added `ActiveRecord::Base#enum` for declaring enum attributes where the values map to integers in the database, but can be queried by name.
1742
-
1743
- Example:
1744
-
1745
- class Conversation < ActiveRecord::Base
1746
- enum status: [:active, :archived]
1747
- end
1748
-
1749
- Conversation::STATUS # => { active: 0, archived: 1 }
1750
-
1751
- # conversation.update! status: 0
1752
- conversation.active!
1753
- conversation.active? # => true
1754
- conversation.status # => "active"
1755
-
1756
- # conversation.update! status: 1
1757
- conversation.archived!
1758
- conversation.archived? # => true
1759
- conversation.status # => "archived"
1760
-
1761
- # conversation.update! status: 1
1762
- conversation.status = :archived
1763
-
1764
- *DHH*
1765
-
1766
- * `ActiveRecord::Base#attribute_for_inspect` now truncates long arrays (more than 10 elements).
1767
-
1768
- *Jan Bernacki*
1769
-
1770
- * Allow for the name of the `schema_migrations` table to be configured.
1771
-
1772
- *Jerad Phelps*
1773
-
1774
- * Do not add to scope includes values from through associations.
1775
- Fixed bug when providing `includes` in through association scope, and fetching targets.
1776
-
1777
- Example:
1778
-
1779
- class Vendor < ActiveRecord::Base
1780
- has_many :relationships, -> { includes(:user) }
1781
- has_many :users, through: :relationships
1782
- end
1783
-
1784
- vendor = Vendor.first
1785
-
1786
- # Before
1787
-
1788
- vendor.users.to_a # => Raises exception: not found `:user` for `User`
1789
-
1790
- # After
1791
-
1792
- vendor.users.to_a # => No exception is raised
1793
-
1794
- Fixes #12242, #9517, #10240.
1795
-
1796
- *Paul Nikitochkin*
1797
-
1798
- * Type cast json values on write, so that the value is consistent
1799
- with reading from the database.
1800
-
1801
- Example:
1802
-
1803
- x = JsonDataType.new tags: {"string" => "foo", :symbol => :bar}
1804
-
1805
- # Before:
1806
- x.tags # => {"string" => "foo", :symbol => :bar}
1807
-
1808
- # After:
1809
- x.tags # => {"string" => "foo", "symbol" => "bar"}
1810
-
1811
- *Severin Schoepke*
1812
-
1813
- * `ActiveRecord::Store` works together with PostgreSQL `hstore` columns.
1814
-
1815
- Fixes #12452.
1816
-
1817
- *Yves Senn*
1818
-
1819
- * Fix bug where `ActiveRecord::Store` used a global `Hash` to keep track of
1820
- all registered `stored_attributes`. Now every subclass of
1821
- `ActiveRecord::Base` has it's own `Hash`.
1822
-
1823
- *Yves Senn*
1824
-
1825
- * Save `has_one` association when primary key is manually set.
1826
-
1827
- Fixes #12302.
1828
-
1829
- *Lauro Caetano*
1830
-
1831
- * Allow any version of BCrypt when using `has_secure_password`.
1832
-
1833
- *Mike Perham*
1834
-
1835
- * Sub-query generated for `Relation` passed as array condition did not take in account
1836
- bind values and have invalid syntax.
1837
-
1838
- Generate sub-query with inline bind values.
1839
-
1840
- Fixes #12586.
1841
-
1842
- *Paul Nikitochkin*
1843
-
1844
- * Fix a bug where rake db:structure:load crashed when the path contained
1845
- spaces.
1846
-
1847
- *Kevin Mook*
1848
-
1849
- * `ActiveRecord::QueryMethods#unscope` unscopes negative equality
1850
-
1851
- Allows you to call `#unscope` on a relation with negative equality
1852
- operators, i.e. `Arel::Nodes::NotIn` and `Arel::Nodes::NotEqual` that have
1853
- been generated through the use of `where.not`.
1854
-
1855
- *Eric Hankins*
1856
-
1857
- * Raise an exception when model without primary key calls `.find_with_ids`.
1858
-
1859
- *Shimpei Makimoto*
1860
-
1861
- * Make `Relation#empty?` use `exists?` instead of `count`.
1862
-
1863
- *Szymon Nowak*
1864
-
1865
- * `rake db:structure:dump` no longer crashes when the port was specified as `Fixnum`.
1866
-
1867
- *Kenta Okamoto*
1868
-
1869
- * `NullRelation#pluck` takes a list of columns
1870
-
1871
- The method signature in `NullRelation` was updated to mimic that in
1872
- `Calculations`.
1873
-
1874
- *Derek Prior*
1875
-
1876
- * `scope_chain` should not be mutated for other reflections.
1877
-
1878
- Currently `scope_chain` uses same array for building different
1879
- `scope_chain` for different associations. During processing
1880
- these arrays are sometimes mutated and because of in-place
1881
- mutation the changed `scope_chain` impacts other reflections.
1882
-
1883
- Fix is to dup the value before adding to the `scope_chain`.
1884
-
1885
- Fixes #3882.
1886
-
1887
- *Neeraj Singh*
1888
-
1889
- * Prevent the inversed association from being reloaded on save.
1890
-
1891
- Fixes #9499.
1892
-
1893
- *Dmitry Polushkin*
1894
-
1895
- * Generate subquery for `Relation` if it passed as array condition for `where`
1896
- method.
1897
-
1898
- Example:
1899
-
1900
- # Before
1901
- Blog.where('id in (?)', Blog.where(id: 1))
1902
- # => SELECT "blogs".* FROM "blogs" WHERE "blogs"."id" = 1
1903
- # => SELECT "blogs".* FROM "blogs" WHERE (id IN (1))
1904
-
1905
- # After
1906
- Blog.where('id in (?)', Blog.where(id: 1).select(:id))
1907
- # => SELECT "blogs".* FROM "blogs"
1908
- # WHERE "blogs"."id" IN (SELECT "blogs"."id" FROM "blogs" WHERE "blogs"."id" = 1)
1909
-
1910
- Fixes #12415.
1911
-
1912
- *Paul Nikitochkin*
1913
-
1914
- * For missed association exception message
1915
- which is raised in `ActiveRecord::Associations::Preloader` class
1916
- added owner record class name in order to simplify to find problem code.
1917
-
1918
- *Paul Nikitochkin*
1919
-
1920
- * `has_and_belongs_to_many` is now transparently implemented in terms of
1921
- `has_many :through`. Behavior should remain the same, if not, it is a bug.
1922
-
1923
- * `create_savepoint`, `rollback_to_savepoint` and `release_savepoint` accept
1924
- a savepoint name.
1925
-
1926
- *Yves Senn*
1927
-
1928
- * Make `next_migration_number` accessible for third party generators.
1929
-
1930
- *Yves Senn*
1931
-
1932
- * Objects instantiated using a null relationship will now retain the
1933
- attributes of the where clause.
1934
-
1935
- Fixes #11676, #11675, #11376.
1936
-
1937
- *Paul Nikitochkin*, *Peter Brown*, *Nthalk*
1938
-
1939
- * Fixed `ActiveRecord::Associations::CollectionAssociation#find`
1940
- when using `has_many` association with `:inverse_of` and finding an array of one element,
1941
- it should return an array of one element too.
1942
-
1943
- *arthurnn*
1944
-
1945
- * Callbacks on has_many should access the in memory parent if a inverse_of is set.
1946
-
1947
- *arthurnn*
1948
-
1949
- * `ActiveRecord::ConnectionAdapters.string_to_time` respects
1950
- string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
1951
-
1952
- Fixes #12278.
1953
-
1954
- *kennyj*
1955
-
1956
- * Calling `update_attributes` will now throw an `ArgumentError` whenever it
1957
- gets a `nil` argument. More specifically, it will throw an error if the
1958
- argument that it gets passed does not respond to to `stringify_keys`.
1959
-
1960
- Example:
1961
-
1962
- @my_comment.update_attributes(nil) # => raises ArgumentError
1963
-
1964
- *John Wang*
1965
-
1966
- * Deprecate `quoted_locking_column` method, which isn't used anywhere.
1967
-
1968
- *kennyj*
1969
-
1970
- * Migration dump UUID default functions to schema.rb.
1971
-
1972
- Fixes #10751.
1973
-
1974
- *kennyj*
1975
-
1976
- * Fixed a bug in `ActiveRecord::Associations::CollectionAssociation#find_by_scan`
1977
- when using `has_many` association with `:inverse_of` option and UUID primary key.
1978
-
1979
- Fixes #10450.
1980
-
1981
- *kennyj*
1982
-
1983
- * Fix: joins association, with defined in the scope block constraints by using several
1984
- where constraints and at least of them is not `Arel::Nodes::Equality`,
1985
- generates invalid SQL expression.
1986
-
1987
- Fixes #11963.
1988
-
1989
- *Paul Nikitochkin*
1990
-
1991
- * `CollectionAssociation#first`/`#last` (e.g. `has_many`) use a `LIMIT`ed
1992
- query to fetch results rather than loading the entire collection.
1993
-
1994
- *Lann Martin*
1995
-
1996
- * Make possible to run SQLite rake tasks without the `Rails` constant defined.
1997
-
1998
- *Damien Mathieu*
1999
-
2000
- * Allow Relation#from to accept other relations with bind values.
2001
-
2002
- *Ryan Wallace*
2003
-
2004
- * Fix inserts with prepared statements disabled.
2005
-
2006
- Fixes #12023.
2007
-
2008
- *Rafael Mendonça França*
2009
-
2010
- * Setting a has_one association on a new record no longer causes an empty
2011
- transaction.
2012
-
2013
- *Dylan Thacker-Smith*
2014
-
2015
- * Fix `AR::Relation#merge` sometimes failing to preserve `readonly(false)` flag.
2016
-
2017
- *thedarkone*
2018
-
2019
- * Re-use `order` argument pre-processing for `reorder`.
2020
-
2021
- *Paul Nikitochkin*
528
+ * Fixed serialized fields returning serialized data after being updated with
529
+ `update_column`.
2022
530
 
2023
- * Fix PredicateBuilder so polymorphic association keys in `where` clause can
2024
- accept objects other than direct descendants of `ActiveRecord::Base` (decorated
2025
- models, for example).
531
+ *Simon Hørup Eskildsen*
2026
532
 
2027
- *Mikhail Dieterle*
533
+ * Fixed polymorphic eager loading when using a String as foreign key.
2028
534
 
2029
- * PostgreSQL adapter recognizes negative money values formatted with
2030
- parentheses (eg. `($1.25) # => -1.25`)).
2031
- Fixes #11899.
535
+ Fixes #14734.
2032
536
 
2033
- *Yves Senn*
537
+ *Lauro Caetano*
2034
538
 
2035
- * Stop interpreting SQL 'string' columns as :string type because there is no
2036
- common STRING datatype in SQL.
539
+ * Change belongs_to touch to be consistent with timestamp updates
2037
540
 
2038
- *Ben Woosley*
541
+ If a model is set up with a belongs_to: touch relationship the parent
542
+ record will only be touched if the record was modified. This makes it
543
+ consistent with timestamp updating on the record itself.
2039
544
 
2040
- * `ActiveRecord::FinderMethods#exists?` returns `true`/`false` in all cases.
545
+ *Brock Trappitt*
2041
546
 
2042
- *Xavier Noria*
547
+ * Fixed the inferred table name of a has_and_belongs_to_many auxiliar
548
+ table inside a schema.
2043
549
 
2044
- * Assign inet/cidr attribute with `nil` value for invalid address.
550
+ Fixes #14824.
2045
551
 
2046
- Example:
552
+ *Eric Chahin*
2047
553
 
2048
- record = User.new
2049
- record.logged_in_from_ip # is type of an inet or a cidr
554
+ * Remove unused `:timestamp` type. Transparently alias it to `:datetime`
555
+ in all cases. Fixes inconsistencies when column types are sent outside of
556
+ `ActiveRecord`, such as for XML Serialization.
2050
557
 
2051
- # Before:
2052
- record.logged_in_from_ip = 'bad ip address' # raise exception
558
+ *Sean Griffin*
2053
559
 
2054
- # After:
2055
- record.logged_in_from_ip = 'bad ip address' # do not raise exception
2056
- record.logged_in_from_ip # => nil
2057
- record.logged_in_from_ip_before_type_cast # => 'bad ip address'
560
+ * Fix bug that added `table_name_prefix` and `table_name_suffix` to
561
+ extension names in PostgreSQL when migrating.
2058
562
 
2059
- *Paul Nikitochkin*
563
+ *Joao Carlos*
2060
564
 
2061
- * `add_to_target` now accepts a second optional `skip_callbacks` argument
565
+ * The `:index` option in migrations, which previously was only available for
566
+ `references`, now works with any column types.
2062
567
 
2063
- If truthy, it will skip the :before_add and :after_add callbacks.
568
+ *Marc Schütz*
2064
569
 
2065
- *Ben Woosley*
570
+ * Add support for counter name to be passed as parameter on `CounterCache::ClassMethods#reset_counters`.
2066
571
 
2067
- * Fix interactions between `:before_add` callbacks and nested attributes
2068
- assignment of `has_many` associations, when the association was not
2069
- yet loaded:
572
+ *jnormore*
2070
573
 
2071
- - A `:before_add` callback was being called when a nested attributes
2072
- assignment assigned to an existing record.
574
+ * Restrict deletion of record when using `delete_all` with `uniq`, `group`, `having`
575
+ or `offset`.
2073
576
 
2074
- - Nested Attributes assignment did not affect the record in the
2075
- association target when a `:before_add` callback triggered the
2076
- loading of the association
577
+ In these cases the generated query ignored them and that caused unintended
578
+ records to be deleted.
2077
579
 
2078
- *Jörg Schray*
580
+ Fixes #11985.
2079
581
 
2080
- * Allow enable_extension migration method to be revertible.
582
+ *Leandro Facchinetti*
2081
583
 
2082
- *Eric Tipton*
584
+ * Floats with limit >= 25 that get turned into doubles in MySQL no longer have
585
+ their limit dropped from the schema.
2083
586
 
2084
- * Type cast hstore values on write, so that the value is consistent
2085
- with reading from the database.
587
+ Fixes #14135.
2086
588
 
2087
- Example:
589
+ *Aaron Nelson*
2088
590
 
2089
- x = Hstore.new tags: {"bool" => true, "number" => 5}
591
+ * Fix how to calculate associated class name when using namespaced has_and_belongs_to_many
592
+ association.
2090
593
 
2091
- # Before:
2092
- x.tags # => {"bool" => true, "number" => 5}
594
+ Fixes #14709.
2093
595
 
2094
- # After:
2095
- x.tags # => {"bool" => "true", "number" => "5"}
596
+ *Kassio Borges*
2096
597
 
2097
- *Yves Senn* , *Severin Schoepke*
598
+ * `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and
599
+ strings in column names as equal.
2098
600
 
2099
- * Fix multidimensional PostgreSQL arrays containing non-string items.
601
+ This fixes a rare case in which more bind values are passed than there are
602
+ placeholders for them in the generated SQL statement, which can make PostgreSQL
603
+ throw a `StatementInvalid` exception.
2100
604
 
2101
- *Yves Senn*
605
+ *Nat Budin*
2102
606
 
2103
- * Fixes bug when using includes combined with select, the select statement was overwritten.
607
+ * Fix `stored_attributes` to correctly merge the details of stored
608
+ attributes defined in parent classes.
2104
609
 
2105
- Fixes #11773.
610
+ Fixes #14672.
2106
611
 
2107
- *Edo Balvers*
612
+ *Brad Bennett*, *Jessica Yao*, *Lakshmi Parthasarathy*
2108
613
 
2109
- * Load fixtures from linked folders.
614
+ * `change_column_default` allows `[]` as argument to `change_column_default`.
2110
615
 
2111
- *Kassio Borges*
616
+ Fixes #11586.
2112
617
 
2113
- * Create a directory for sqlite3 file if not present on the system.
618
+ *Yves Senn*
2114
619
 
2115
- *Richard Schneeman*
620
+ * Handle `name` and `"char"` column types in the PostgreSQL adapter.
2116
621
 
2117
- * Removed redundant override of `xml` column definition for PostgreSQL,
2118
- in order to use `xml` column type instead of `text`.
622
+ `name` and `"char"` are special character types used internally by
623
+ PostgreSQL and are used by internal system catalogs. These field types
624
+ can sometimes show up in structure-sniffing queries that feature internal system
625
+ structures or with certain PostgreSQL extensions.
2119
626
 
2120
- *Paul Nikitochkin*, *Michael Nikitochkin*
627
+ *J Smith*, *Yves Senn*
2121
628
 
2122
- * Revert `ActiveRecord::Relation#order` change that make new order
2123
- prepend the old one.
629
+ * Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and
630
+ NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
2124
631
 
2125
632
  Before:
2126
633
 
2127
- User.order("name asc").order("created_at desc")
2128
- # SELECT * FROM users ORDER BY created_at desc, name asc
634
+ Point.create(value: 1.0/0)
635
+ Point.last.value # => 0.0
2129
636
 
2130
637
  After:
2131
638
 
2132
- User.order("name asc").order("created_at desc")
2133
- # SELECT * FROM users ORDER BY name asc, created_at desc
639
+ Point.create(value: 1.0/0)
640
+ Point.last.value # => Infinity
2134
641
 
2135
- This also affects order defined in `default_scope` or any kind of associations.
642
+ *Innokenty Mikhailov*
2136
643
 
2137
- * Add ability to define how a class is converted to Arel predicates.
2138
- For example, adding a very vendor specific regex implementation:
644
+ * Allow the PostgreSQL adapter to handle bigserial primary key types again.
2139
645
 
2140
- regex_handler = proc do |column, value|
2141
- Arel::Nodes::InfixOperation.new('~', column, value.source)
2142
- end
2143
- ActiveRecord::PredicateBuilder.register_handler(Regexp, regex_handler)
646
+ Fixes #10410.
2144
647
 
2145
- *Sean Griffin & @joannecheng*
648
+ *Patrick Robertson*
2146
649
 
2147
- * Don't allow `quote_value` to be called without a column.
650
+ * Deprecate joining, eager loading and preloading of instance dependent
651
+ associations without replacement. These operations happen before instances
652
+ are created. The current behavior is unexpected and can result in broken
653
+ behavior.
2148
654
 
2149
- Some adapters require column information to do their job properly.
2150
- By enforcing the provision of the column for this internal method
2151
- we ensure that those using adapters that require column information
2152
- will always get the proper behavior.
655
+ Fixes #15024.
2153
656
 
2154
- *Ben Woosley*
657
+ *Yves Senn*
2155
658
 
2156
- * When using optimistic locking, `update` was not passing the column to `quote_value`
2157
- to allow the connection adapter to properly determine how to quote the value. This was
2158
- affecting certain databases that use specific column types.
659
+ * Fixed has_and_belongs_to_many's CollectionAssociation size calculation.
2159
660
 
2160
- Fixes #6763.
661
+ has_and_belongs_to_many should fall back to using the normal CollectionAssociation's
662
+ size calculation if the collection is not cached or loaded.
2161
663
 
2162
- *Alfred Wong*
664
+ Fixes #14913, #14914.
2163
665
 
2164
- * rescue from all exceptions in `ConnectionManagement#call`
666
+ *Fred Wu*
2165
667
 
2166
- Fixes #11497.
668
+ * Return a non zero status when running `rake db:migrate:status` and migration table does
669
+ not exist.
2167
670
 
2168
- As `ActiveRecord::ConnectionAdapters::ConnectionManagement` middleware does
2169
- not rescue from Exception (but only from StandardError), the Connection
2170
- Pool quickly runs out of connections when multiple erroneous Requests come
2171
- in right after each other.
671
+ *Paul B.*
2172
672
 
2173
- Rescuing from all exceptions and not just StandardError, fixes this
2174
- behaviour.
673
+ * Add support for module-level `table_name_suffix` in models.
2175
674
 
2176
- *Vipul A M*
675
+ This makes `table_name_suffix` work the same way as `table_name_prefix` when
676
+ using namespaced models.
2177
677
 
2178
- * `change_column` for PostgreSQL adapter respects the `:array` option.
678
+ *Jenner LaFave*
2179
679
 
2180
- *Yves Senn*
680
+ * Revert the behaviour of `ActiveRecord::Relation#join` changed through 4.0 => 4.1 to 4.0.
2181
681
 
2182
- * Remove deprecation warning from `attribute_missing` for attributes that are columns.
682
+ In 4.1.0 `Relation#join` is delegated to `Arel#SelectManager`.
683
+ In 4.0 series it is delegated to `Array#join`.
2183
684
 
2184
- *Arun Agrawal*
685
+ *Bogdan Gusiev*
2185
686
 
2186
- * Remove extra decrement of transaction deep level.
687
+ * Log nil binary column values correctly.
2187
688
 
2188
- Fixes #4566.
689
+ When an object with a binary column is updated with a nil value
690
+ in that column, the SQL logger would throw an exception when trying
691
+ to log that nil value. This only occurs when updating a record
692
+ that already has a non-nil value in that column since an initial nil
693
+ value isn't included in the SQL anyway (at least, when dirty checking
694
+ is enabled.) The column's new value will now be logged as `<NULL binary data>`
695
+ to parallel the existing `<N bytes of binary data>` for non-nil values.
2189
696
 
2190
- *Paul Nikitochkin*
697
+ *James Coleman*
2191
698
 
2192
- * Reset @column_defaults when assigning `locking_column`.
2193
- We had a potential problem. For example:
699
+ * Rails will now pass a custom validation context through to autosave associations
700
+ in order to validate child associations with the same context.
2194
701
 
2195
- class Post < ActiveRecord::Base
2196
- self.column_defaults # if we call this unintentionally before setting locking_column ...
2197
- self.locking_column = 'my_locking_column'
2198
- end
702
+ Fixes #13854.
2199
703
 
2200
- Post.column_defaults["my_locking_column"]
2201
- => nil # expected value is 0 !
704
+ *Eric Chahin*, *Aaron Nelson*, *Kevin Casey*
2202
705
 
2203
- *kennyj*
706
+ * Stringify all variables keys of MySQL connection configuration.
2204
707
 
2205
- * Remove extra select and update queries on save/touch/destroy ActiveRecord model
2206
- with belongs to reflection with option `touch: true`.
708
+ When `sql_mode` variable for MySQL adapters set in configuration as `String`
709
+ was ignored and overwritten by strict mode option.
2207
710
 
2208
- Fixes #11288.
711
+ Fixes #14895.
2209
712
 
2210
713
  *Paul Nikitochkin*
2211
714
 
2212
- * Remove deprecated nil-passing to the following `SchemaCache` methods:
2213
- `primary_keys`, `tables`, `columns` and `columns_hash`.
715
+ * Ensure SQLite3 statements are closed on errors.
2214
716
 
2215
- *Yves Senn*
717
+ Fixes #13631.
2216
718
 
2217
- * Remove deprecated block filter from `ActiveRecord::Migrator#migrate`.
719
+ *Timur Alperovich*
2218
720
 
2219
- *Yves Senn*
721
+ * Give ActiveRecord::PredicateBuilder private methods the privacy they deserve.
2220
722
 
2221
- * Remove deprecated String constructor from `ActiveRecord::Migrator`.
723
+ *Hector Satre*
2222
724
 
2223
- *Yves Senn*
725
+ * When using a custom `join_table` name on a `habtm`, rails was not saving it
726
+ on Reflections. This causes a problem when rails loads fixtures, because it
727
+ uses the reflections to set database with fixtures.
2224
728
 
2225
- * Remove deprecated `scope` use without passing a callable object.
729
+ Fixes #14845.
2226
730
 
2227
- *Arun Agrawal*
731
+ *Kassio Borges*
2228
732
 
2229
- * Remove deprecated `transaction_joinable=` in favor of `begin_transaction`
2230
- with `:joinable` option.
733
+ * Reset the cache when modifying a Relation with cached Arel.
734
+ Additionally display a warning message to make the user aware.
2231
735
 
2232
- *Arun Agrawal*
736
+ *Yves Senn*
2233
737
 
2234
- * Remove deprecated `decrement_open_transactions`.
738
+ * PostgreSQL should internally use `:datetime` consistently for TimeStamp. Assures
739
+ different spellings of timestamps are treated the same.
2235
740
 
2236
- *Arun Agrawal*
741
+ Example:
2237
742
 
2238
- * Remove deprecated `increment_open_transactions`.
743
+ mytimestamp.simplified_type('timestamp without time zone')
744
+ # => :datetime
745
+ mytimestamp.simplified_type('timestamp(6) without time zone')
746
+ # => also :datetime (previously would be :timestamp)
2239
747
 
2240
- *Arun Agrawal*
748
+ See #14513.
2241
749
 
2242
- * Remove deprecated `PostgreSQLAdapter#outside_transaction?`
2243
- method. You can use `#transaction_open?` instead.
750
+ *Jefferson Lai*
2244
751
 
2245
- *Yves Senn*
752
+ * `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.
2246
753
 
2247
- * Remove deprecated `ActiveRecord::Fixtures.find_table_name` in favor of
2248
- `ActiveRecord::Fixtures.default_fixture_model_name`.
754
+ Fixes #14841.
755
+
756
+ *Lucas Mazza*
2249
757
 
2250
- *Vipul A M*
758
+ * Fix name collision with `Array#select!` with `Relation#select!`.
2251
759
 
2252
- * Removed deprecated `columns_for_remove` from `SchemaStatements`.
760
+ Fixes #14752.
2253
761
 
2254
- *Neeraj Singh*
762
+ *Earl St Sauver*
2255
763
 
2256
- * Remove deprecated `SchemaStatements#distinct`.
764
+ * Fixed unexpected behavior for `has_many :through` associations going through a scoped `has_many`.
2257
765
 
2258
- *Francesco Rodriguez*
766
+ If a `has_many` association is adjusted using a scope, and another `has_many :through`
767
+ uses this association, then the scope adjustment is unexpectedly neglected.
2259
768
 
2260
- * Move deprecated `ActiveRecord::TestCase` into the rails test
2261
- suite. The class is no longer public and is only used for internal
2262
- Rails tests.
769
+ Fixes #14537.
2263
770
 
2264
- *Yves Senn*
771
+ *Jan Habermann*
2265
772
 
2266
- * Removed support for deprecated option `:restrict` for `:dependent`
2267
- in associations.
773
+ * `@destroyed` should always be set to `false` when an object is duped.
2268
774
 
2269
- *Neeraj Singh*
775
+ *Kuldeep Aggarwal*
2270
776
 
2271
- * Removed support for deprecated `delete_sql` in associations.
777
+ * Fixed has_many association to make it support irregular inflections.
2272
778
 
2273
- *Neeraj Singh*
779
+ Fixes #8928.
2274
780
 
2275
- * Removed support for deprecated `insert_sql` in associations.
781
+ *arthurnn*, *Javier Goizueta*
2276
782
 
2277
- *Neeraj Singh*
783
+ * Fixed a problem where count used with a grouping was not returning a Hash.
2278
784
 
2279
- * Removed support for deprecated `finder_sql` in associations.
785
+ Fixes #14721.
2280
786
 
2281
- *Neeraj Singh*
787
+ *Eric Chahin*
2282
788
 
2283
- * Support array as root element in JSON fields.
789
+ * `sanitize_sql_like` helper method to escape a string for safe use in an SQL
790
+ LIKE statement.
2284
791
 
2285
- *Alexey Noskov & Francesco Rodriguez*
792
+ Example:
2286
793
 
2287
- * Removed support for deprecated `counter_sql` in associations.
794
+ class Article
795
+ def self.search(term)
796
+ where("title LIKE ?", sanitize_sql_like(term))
797
+ end
798
+ end
2288
799
 
2289
- *Neeraj Singh*
800
+ Article.search("20% _reduction_")
801
+ # => Query looks like "... title LIKE '20\% \_reduction\_' ..."
2290
802
 
2291
- * Do not invoke callbacks when `delete_all` is called on collection.
803
+ *Rob Gilson*, *Yves Senn*
2292
804
 
2293
- Method `delete_all` should not be invoking callbacks and this
2294
- feature was deprecated in Rails 4.0. This is being removed.
2295
- `delete_all` will continue to honor the `:dependent` option. However
2296
- if `:dependent` value is `:destroy` then the `:delete_all` deletion
2297
- strategy for that collection will be applied.
805
+ * Do not quote uuid default value on `change_column`.
2298
806
 
2299
- User can also force a deletion strategy by passing parameter to
2300
- `delete_all`. For example you can do `@post.comments.delete_all(:nullify)`.
807
+ Fixes #14604.
2301
808
 
2302
- *Neeraj Singh*
809
+ *Eric Chahin*
2303
810
 
2304
- * Calling default_scope without a proc will now raise `ArgumentError`.
811
+ * The comparison between `Relation` and `CollectionProxy` should be consistent.
2305
812
 
2306
- *Neeraj Singh*
813
+ Example:
2307
814
 
2308
- * Removed deprecated method `type_cast_code` from Column.
815
+ author.posts == Post.where(author_id: author.id)
816
+ # => true
817
+ Post.where(author_id: author.id) == author.posts
818
+ # => true
2309
819
 
2310
- *Neeraj Singh*
820
+ Fixes #13506.
2311
821
 
2312
- * Removed deprecated options `delete_sql` and `insert_sql` from HABTM
2313
- association.
822
+ *Lauro Caetano*
2314
823
 
2315
- Removed deprecated options `finder_sql` and `counter_sql` from
2316
- collection association.
824
+ * Calling `delete_all` on an unloaded `CollectionProxy` no longer
825
+ generates an SQL statement containing each id of the collection:
2317
826
 
2318
- *Neeraj Singh*
827
+ Before:
2319
828
 
2320
- * Remove deprecated `ActiveRecord::Base#connection` method.
2321
- Make sure to access it via the class.
829
+ DELETE FROM `model` WHERE `model`.`parent_id` = 1
830
+ AND `model`.`id` IN (1, 2, 3...)
2322
831
 
2323
- *Yves Senn*
832
+ After:
2324
833
 
2325
- * Remove deprecation warning for `auto_explain_threshold_in_seconds`.
834
+ DELETE FROM `model` WHERE `model`.`parent_id` = 1
2326
835
 
2327
- *Yves Senn*
836
+ *Eileen M. Uchitelle*, *Aaron Patterson*
2328
837
 
2329
- * Remove deprecated `:distinct` option from `Relation#count`.
838
+ * Fixed error for aggregate methods (`empty?`, `any?`, `count`) with `select`
839
+ which created invalid SQL.
2330
840
 
2331
- *Yves Senn*
841
+ Fixes #13648.
2332
842
 
2333
- * Removed deprecated methods `partial_updates`, `partial_updates?` and
2334
- `partial_updates=`.
843
+ *Simon Woker*
2335
844
 
2336
- *Neeraj Singh*
845
+ * PostgreSQL adapter only warns once for every missing OID per connection.
2337
846
 
2338
- * Removed deprecated method `scoped`.
847
+ Fixes #14275.
2339
848
 
2340
- *Neeraj Singh*
849
+ *Matthew Draper*, *Yves Senn*
2341
850
 
2342
- * Removed deprecated method `default_scopes?`.
851
+ * PostgreSQL adapter automatically reloads it's type map when encountering
852
+ unknown OIDs.
2343
853
 
2344
- *Neeraj Singh*
854
+ Fixes #14678.
2345
855
 
2346
- * Remove implicit join references that were deprecated in 4.0.
856
+ *Matthew Draper*, *Yves Senn*
2347
857
 
2348
- Example:
858
+ * Fix insertion of records via `has_many :through` association with scope.
2349
859
 
2350
- # before with implicit joins
2351
- Comment.where('posts.author_id' => 7)
860
+ Fixes #3548.
2352
861
 
2353
- # after
2354
- Comment.references(:posts).where('posts.author_id' => 7)
862
+ *Ivan Antropov*
2355
863
 
2356
- *Yves Senn*
864
+ * Auto-generate stable fixture UUIDs on PostgreSQL.
2357
865
 
2358
- * Apply default scope when joining associations. For example:
866
+ Fixes #11524.
2359
867
 
2360
- class Post < ActiveRecord::Base
2361
- default_scope -> { where published: true }
2362
- end
868
+ *Roderick van Domburg*
2363
869
 
2364
- class Comment
2365
- belongs_to :post
2366
- end
870
+ * Fixed a problem where an enum would overwrite values of another enum
871
+ with the same name in an unrelated class.
2367
872
 
2368
- When calling `Comment.joins(:post)`, we expect to receive only
2369
- comments on published posts, since that is the default scope for
2370
- posts.
873
+ Fixes #14607.
2371
874
 
2372
- Before this change, the default scope from `Post` was not applied,
2373
- so we'd get comments on unpublished posts.
875
+ *Evan Whalen*
2374
876
 
2375
- *Jon Leighton*
877
+ * PostgreSQL and SQLite string columns no longer have a default limit of 255.
2376
878
 
2377
- * Remove `activerecord-deprecated_finders` as a dependency.
879
+ Fixes #13435, #9153.
2378
880
 
2379
- *Łukasz Strzałkowski*
881
+ *Vladimir Sazhin*, *Toms Mikoss*, *Yves Senn*
2380
882
 
2381
- * Remove Oracle / Sqlserver / Firebird database tasks that were deprecated in 4.0.
883
+ * Make possible to have an association called `records`.
2382
884
 
2383
- *kennyj*
885
+ Fixes #11645.
2384
886
 
2385
- * `find_each` now returns an `Enumerator` when called without a block, so that it
2386
- can be chained with other `Enumerable` methods.
887
+ *prathamesh-sonpatki*
2387
888
 
2388
- *Ben Woosley*
889
+ * `to_sql` on an association now matches the query that is actually executed, where it
890
+ could previously have incorrectly accrued additional conditions (e.g. as a result of
891
+ a previous query). CollectionProxy now always defers to the association scope's
892
+ `arel` method so the (incorrect) inherited one should be entirely concealed.
2389
893
 
2390
- * `ActiveRecord::Result.each` now returns an `Enumerator` when called without
2391
- a block, so that it can be chained with other `Enumerable` methods.
894
+ Fixes #14003.
2392
895
 
2393
- *Ben Woosley*
896
+ *Jefferson Lai*
2394
897
 
2395
- * Flatten merged join_values before building the joins.
898
+ * Block a few default Class methods as scope name.
2396
899
 
2397
- While joining_values special treatment is given to string values.
2398
- By flattening the array it ensures that string values are detected
2399
- as strings and not arrays.
900
+ For instance, this will raise:
2400
901
 
2401
- Fixes #10669.
902
+ scope :public, -> { where(status: 1) }
2402
903
 
2403
- *Neeraj Singh and iwiznia*
904
+ *arthurnn*
2404
905
 
2405
- * Do not load all child records for inverse case.
906
+ * Fixed error when using `with_options` with lambda.
2406
907
 
2407
- currently `post.comments.find(Comment.first.id)` would load all
2408
- comments for the given post to set the inverse association.
908
+ Fixes #9805.
2409
909
 
2410
- This has a huge performance penalty. Because if post has 100k
2411
- records and all these 100k records would be loaded in memory
2412
- even though the comment id was supplied.
910
+ *Lauro Caetano*
2413
911
 
2414
- Fix is to use in-memory records only if loaded? is true. Otherwise
2415
- load the records using full sql.
912
+ * Switch `sqlite3:///` URLs (which were temporarily
913
+ deprecated in 4.1) from relative to absolute.
2416
914
 
2417
- Fixes #10509.
915
+ If you still want the previous interpretation, you should replace
916
+ `sqlite3:///my/path` with `sqlite3:my/path`.
2418
917
 
2419
- *Neeraj Singh*
918
+ *Matthew Draper*
2420
919
 
2421
- * `inspect` on Active Record model classes does not initiate a
2422
- new connection. This means that calling `inspect`, when the
2423
- database is missing, will no longer raise an exception.
2424
- Fixes #10936.
920
+ * Treat blank UUID values as `nil`.
2425
921
 
2426
922
  Example:
2427
923
 
2428
- Author.inspect # => "Author(no database connection)"
2429
-
2430
- *Yves Senn*
924
+ Sample.new(uuid_field: '') #=> <Sample id: nil, uuid_field: nil>
2431
925
 
2432
- * Handle single quotes in PostgreSQL default column values.
2433
- Fixes #10881.
926
+ *Dmitry Lavrov*
2434
927
 
2435
- *Dylan Markow*
928
+ * Enable support for materialized views on PostgreSQL >= 9.3.
2436
929
 
2437
- * Log the sql that is actually sent to the database.
930
+ *Dave Lee*
2438
931
 
2439
- If I have a query that produces sql
2440
- `WHERE "users"."name" = 'a b'` then in the log all the
2441
- whitespace is being squeezed. So the sql that is printed in the
2442
- log is `WHERE "users"."name" = 'a b'`.
932
+ * The PostgreSQL adapter supports custom domains. Fixes #14305.
2443
933
 
2444
- Do not squeeze whitespace out of sql queries. Fixes #10982.
934
+ *Yves Senn*
2445
935
 
2446
- *Neeraj Singh*
936
+ * PostgreSQL `Column#type` is now determined through the corresponding OID.
937
+ The column types stay the same except for enum columns. They no longer have
938
+ `nil` as type but `enum`.
2447
939
 
2448
- * Fixture setup no longer depends on `ActiveRecord::Base.configurations`.
2449
- This is relevant when `ENV["DATABASE_URL"]` is used in place of a `database.yml`.
940
+ See #7814.
2450
941
 
2451
942
  *Yves Senn*
2452
943
 
2453
- * Fix mysql2 adapter raises the correct exception when executing a query on a
2454
- closed connection.
944
+ * Fixed error when specifying a non-empty default value on a PostgreSQL array column.
2455
945
 
2456
- *Yves Senn*
946
+ Fixes #10613.
2457
947
 
2458
- * Ambiguous reflections are on :through relationships are no longer supported.
2459
- For example, you need to change this:
948
+ *Luke Steensen*
2460
949
 
2461
- class Author < ActiveRecord::Base
2462
- has_many :posts
2463
- has_many :taggings, through: :posts
2464
- end
950
+ * Fixed error where .persisted? throws SystemStackError for an unsaved model with a
951
+ custom primary key that didn't save due to validation error.
2465
952
 
2466
- class Post < ActiveRecord::Base
2467
- has_one :tagging
2468
- has_many :taggings
2469
- end
953
+ Fixes #14393.
2470
954
 
2471
- class Tagging < ActiveRecord::Base
2472
- end
955
+ *Chris Finne*
2473
956
 
2474
- To this:
957
+ * Introduce `validate` as an alias for `valid?`.
2475
958
 
2476
- class Author < ActiveRecord::Base
2477
- has_many :posts
2478
- has_many :taggings, through: :posts, source: :tagging
2479
- end
959
+ This is more intuitive when you want to run validations but don't care about the return value.
2480
960
 
2481
- class Post < ActiveRecord::Base
2482
- has_one :tagging
2483
- has_many :taggings
2484
- end
961
+ *Henrik Nyh*
2485
962
 
2486
- class Tagging < ActiveRecord::Base
2487
- end
963
+ * Create indexes inline in CREATE TABLE for MySQL.
2488
964
 
2489
- *Aaron Patterson*
965
+ This is important, because adding an index on a temporary table after it has been created
966
+ would commit the transaction.
2490
967
 
2491
- * Remove column restrictions for `count`, let the database raise if the SQL is
2492
- invalid. The previous behavior was untested and surprising for the user.
2493
- Fixes #5554.
968
+ It also allows creating and dropping indexed tables with fewer queries and fewer permissions
969
+ required.
2494
970
 
2495
971
  Example:
2496
972
 
2497
- User.select("name, username").count
2498
- # Before => SELECT count(*) FROM users
2499
- # After => ActiveRecord::StatementInvalid
2500
-
2501
- # you can still use `count(:all)` to perform a query unrelated to the
2502
- # selected columns
2503
- User.select("name, username").count(:all) # => SELECT count(*) FROM users
2504
-
2505
- *Yves Senn*
2506
-
2507
- * Rails now automatically detects inverse associations. If you do not set the
2508
- `:inverse_of` option on the association, then Active Record will guess the
2509
- inverse association based on heuristics.
2510
-
2511
- Note that automatic inverse detection only works on `has_many`, `has_one`,
2512
- and `belongs_to` associations. Extra options on the associations will
2513
- also prevent the association's inverse from being found automatically.
2514
-
2515
- The automatic guessing of the inverse association uses a heuristic based
2516
- on the name of the class, so it may not work for all associations,
2517
- especially the ones with non-standard names.
2518
-
2519
- You can turn off the automatic detection of inverse associations by setting
2520
- the `:inverse_of` option to `false` like so:
2521
-
2522
- class Taggable < ActiveRecord::Base
2523
- belongs_to :tag, inverse_of: false
973
+ create_table :temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query" do |t|
974
+ t.index :zip
2524
975
  end
976
+ # => CREATE TEMPORARY TABLE temp (INDEX (zip)) AS SELECT id, name, zip FROM a_really_complicated_query
2525
977
 
2526
- *John Wang*
978
+ *Cody Cutrer*, *Steve Rice*, *Rafael Mendonça Franca*
2527
979
 
2528
- * Fix `add_column` with `array` option when using PostgreSQL. Fixes #10432.
980
+ * Use singular table name in generated migrations when
981
+ `ActiveRecord::Base.pluralize_table_names` is `false`.
2529
982
 
2530
- *Adam Anderson*
983
+ Fixes #13426.
984
+
985
+ *Kuldeep Aggarwal*
2531
986
 
2532
- * Usage of `implicit_readonly` is being removed`. Please use `readonly` method
2533
- explicitly to mark records as `readonly.
2534
- Fixes #10615.
987
+ * `touch` accepts many attributes to be touched at once.
2535
988
 
2536
989
  Example:
2537
990
 
2538
- user = User.joins(:todos).select("users.*, todos.title as todos_title").readonly(true).first
2539
- user.todos_title = 'clean pet'
2540
- user.save! # will raise error
991
+ # touches :signed_at, :sealed_at, and :updated_at/on attributes.
992
+ Photo.last.touch(:signed_at, :sealed_at)
2541
993
 
2542
- *Yves Senn*
994
+ *James Pinto*
2543
995
 
2544
- * Fix the `:primary_key` option for `has_many` associations.
996
+ * `rake db:structure:dump` only dumps schema information if the schema
997
+ migration table exists.
2545
998
 
2546
- Fixes #10693.
999
+ Fixes #14217.
2547
1000
 
2548
1001
  *Yves Senn*
2549
1002
 
2550
- * Fix bug where tiny types are incorrectly coerced as boolean when the length is more than 1.
1003
+ * Reap connections that were checked out by now-dead threads, instead
1004
+ of waiting until they disconnect by themselves. Before this change,
1005
+ a suitably constructed series of short-lived threads could starve
1006
+ the connection pool, without ever having more than a couple alive at
1007
+ the same time.
2551
1008
 
2552
- Fixes #10620.
2553
-
2554
- *Aaron Patterson*
1009
+ *Matthew Draper*
2555
1010
 
2556
- * Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1.
1011
+ * `pk_and_sequence_for` now ensures that only the pg_depend entries
1012
+ pointing to pg_class, and thus only sequence objects, are considered.
2557
1013
 
2558
- *kennyj*
1014
+ *Josh Williams*
2559
1015
 
2560
- * Deprecate `ConnectionAdapters::SchemaStatements#distinct`,
2561
- as it is no longer used by internals.
1016
+ * `where.not` adds `references` for `includes` like normal `where` calls do.
2562
1017
 
2563
- *Ben Woosley*
1018
+ Fixes #14406.
2564
1019
 
2565
- * Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix`
2566
- is not blank.
1020
+ *Yves Senn*
2567
1021
 
2568
- Call `assume_migrated_upto_version` on connection to prevent it from first
2569
- being picked up in `method_missing`.
1022
+ * Extend fixture `$LABEL` replacement to allow string interpolation.
2570
1023
 
2571
- In the base class, `Migration`, `method_missing` expects the argument to be a
2572
- table name, and calls `proper_table_name` on the arguments before sending to
2573
- `connection`. If `table_name_prefix` or `table_name_suffix` is used, the schema
2574
- version changes to `prefix_version_suffix`, breaking `rake test:prepare`.
1024
+ Example:
2575
1025
 
2576
- Fixes #10411.
1026
+ martin:
1027
+ email: $LABEL@email.com
2577
1028
 
2578
- *Kyle Stevens*
1029
+ users(:martin).email # => martin@email.com
2579
1030
 
2580
- * Method `read_attribute_before_type_cast` should accept input as symbol.
1031
+ *Eric Steele*
2581
1032
 
2582
- *Neeraj Singh*
1033
+ * Add support for `Relation` be passed as parameter on `QueryCache#select_all`.
2583
1034
 
2584
- * Confirm a record has not already been destroyed before decrementing counter cache.
1035
+ Fixes #14361.
2585
1036
 
2586
- *Ben Tucker*
1037
+ *arthurnn*
2587
1038
 
2588
- * Fixed a bug in `ActiveRecord#sanitize_sql_hash_for_conditions` in which
2589
- `self.class` is an argument to `PredicateBuilder#build_from_hash`
2590
- causing `PredicateBuilder` to call non-existent method
2591
- `Class#reflect_on_association`.
1039
+ * Passing an Active Record object to `find` or `exists?` is now deprecated.
1040
+ Call `.id` on the object first.
2592
1041
 
2593
- *Zach Ohlgren*
1042
+ *Aaron Patterson*
2594
1043
 
2595
- * While removing index if column option is missing then raise IrreversibleMigration exception.
1044
+ * Only use BINARY for MySQL case sensitive uniqueness check when column has a case insensitive collation.
2596
1045
 
2597
- Following code should raise `IrreversibleMigration`. But the code was
2598
- failing since options is an array and not a hash.
1046
+ *Ryuta Kamizono*
2599
1047
 
2600
- def change
2601
- change_table :users do |t|
2602
- t.remove_index [:name, :email]
2603
- end
2604
- end
1048
+ * Support for MySQL 5.6 fractional seconds.
2605
1049
 
2606
- Fix was to check if the options is a Hash before operating on it.
1050
+ *arthurnn*, *Tatsuhiko Miyagawa*
2607
1051
 
2608
- Fixes #10419.
1052
+ * Support for Postgres `citext` data type enabling case-insensitive where
1053
+ values without needing to wrap in UPPER/LOWER sql functions.
2609
1054
 
2610
- *Neeraj Singh*
1055
+ *Troy Kruthoff*, *Lachlan Sylvester*
2611
1056
 
2612
- * Do not overwrite manually built records during one-to-one nested attribute assignment
1057
+ * Only save has_one associations if record has changes.
1058
+ Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
1059
+ object did not get saved to the db.
2613
1060
 
2614
- For one-to-one nested associations, if you build the new (in-memory)
2615
- child object yourself before assignment, then the NestedAttributes
2616
- module will not overwrite it, e.g.:
1061
+ *Alan Kennedy*
2617
1062
 
2618
- class Member < ActiveRecord::Base
2619
- has_one :avatar
2620
- accepts_nested_attributes_for :avatar
1063
+ * Allow strings to specify the `#order` value.
2621
1064
 
2622
- def avatar
2623
- super || build_avatar(width: 200)
2624
- end
2625
- end
1065
+ Example:
2626
1066
 
2627
- member = Member.new
2628
- member.avatar_attributes = {icon: 'sad'}
2629
- member.avatar.width # => 200
1067
+ Model.order(id: 'asc').to_sql == Model.order(id: :asc).to_sql
2630
1068
 
2631
- *Olek Janiszewski*
1069
+ *Marcelo Casiraghi*, *Robin Dupret*
2632
1070
 
2633
- * fixes bug introduced by #3329. Now, when autosaving associations,
2634
- deletions happen before inserts and saves. This prevents a 'duplicate
2635
- unique value' database error that would occur if a record being created had
2636
- the same value on a unique indexed field as that of a record being destroyed.
1071
+ * Dynamically register PostgreSQL enum OIDs. This prevents "unknown OID"
1072
+ warnings on enum columns.
2637
1073
 
2638
- *Johnny Holton*
1074
+ *Dieter Komendera*
2639
1075
 
2640
- * Handle aliased attributes in ActiveRecord::Relation.
1076
+ * `includes` is able to detect the right preloading strategy when string
1077
+ joins are involved.
2641
1078
 
2642
- When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database:
1079
+ Fixes #14109.
2643
1080
 
2644
- With the model
1081
+ *Aaron Patterson*, *Yves Senn*
2645
1082
 
2646
- class Topic
2647
- alias_attribute :heading, :title
2648
- end
1083
+ * Fixed error with validation with enum fields for records where the
1084
+ value for any enum attribute is always evaluated as 0 during
1085
+ uniqueness validation.
2649
1086
 
2650
- The call
1087
+ Fixes #14172.
2651
1088
 
2652
- Topic.where(heading: 'The First Topic')
1089
+ *Vilius Luneckas* *Ahmed AbouElhamayed*
2653
1090
 
2654
- should yield the same result as
1091
+ * `before_add` callbacks are fired before the record is saved on
1092
+ `has_and_belongs_to_many` associations *and* on `has_many :through`
1093
+ associations. Before this change, `before_add` callbacks would be fired
1094
+ before the record was saved on `has_and_belongs_to_many` associations, but
1095
+ *not* on `has_many :through` associations.
2655
1096
 
2656
- Topic.where(title: 'The First Topic')
1097
+ Fixes #14144.
2657
1098
 
2658
- This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`.
1099
+ * Fixed STI classes not defining an attribute method if there is a
1100
+ conflicting private method defined on its ancestors.
2659
1101
 
2660
- This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`.
1102
+ Fixes #11569.
2661
1103
 
2662
1104
  *Godfrey Chan*
2663
1105
 
2664
- * Mute `psql` output when running rake db:schema:load.
1106
+ * Coerce strings when reading attributes. Fixes #10485.
2665
1107
 
2666
- *Godfrey Chan*
1108
+ Example:
2667
1109
 
2668
- * Trigger a save on `has_one association=(associate)` when the associate contents have changed.
1110
+ book = Book.new(title: 12345)
1111
+ book.save!
1112
+ book.title # => "12345"
2669
1113
 
2670
- Fixes #8856.
1114
+ *Yves Senn*
2671
1115
 
2672
- *Chris Thompson*
1116
+ * Deprecate half-baked support for PostgreSQL range values with excluding beginnings.
1117
+ We currently map PostgreSQL ranges to Ruby ranges. This conversion is not fully
1118
+ possible because the Ruby range does not support excluded beginnings.
2673
1119
 
2674
- * Abort a rake task when missing db/structure.sql like `db:schema:load` task.
1120
+ The current solution of incrementing the beginning is not correct and is now
1121
+ deprecated. For subtypes where we don't know how to increment (e.g. `#succ`
1122
+ is not defined) it will raise an ArgumentException for ranges with excluding
1123
+ beginnings.
2675
1124
 
2676
- *kennyj*
1125
+ *Yves Senn*
2677
1126
 
2678
- * rake:db:test:prepare falls back to original environment after execution.
1127
+ * Support for user created range types in PostgreSQL.
2679
1128
 
2680
- *Slava Markevich*
1129
+ *Yves Senn*
2681
1130
 
2682
- Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/activerecord/CHANGELOG.md) for previous changes.
1131
+ Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/activerecord/CHANGELOG.md) for previous changes.