activerecord 4.0.4 → 4.1.16

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 (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1632 -1797
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +2 -2
  5. data/examples/performance.rb +30 -18
  6. data/examples/simple.rb +4 -4
  7. data/lib/active_record/aggregations.rb +2 -1
  8. data/lib/active_record/association_relation.rb +4 -0
  9. data/lib/active_record/associations/alias_tracker.rb +49 -29
  10. data/lib/active_record/associations/association.rb +9 -17
  11. data/lib/active_record/associations/association_scope.rb +59 -49
  12. data/lib/active_record/associations/belongs_to_association.rb +34 -25
  13. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +6 -1
  14. data/lib/active_record/associations/builder/association.rb +84 -54
  15. data/lib/active_record/associations/builder/belongs_to.rb +90 -58
  16. data/lib/active_record/associations/builder/collection_association.rb +47 -45
  17. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +119 -25
  18. data/lib/active_record/associations/builder/has_many.rb +3 -3
  19. data/lib/active_record/associations/builder/has_one.rb +5 -7
  20. data/lib/active_record/associations/builder/singular_association.rb +6 -7
  21. data/lib/active_record/associations/collection_association.rb +121 -111
  22. data/lib/active_record/associations/collection_proxy.rb +73 -18
  23. data/lib/active_record/associations/has_many_association.rb +14 -11
  24. data/lib/active_record/associations/has_many_through_association.rb +33 -6
  25. data/lib/active_record/associations/has_one_association.rb +1 -1
  26. data/lib/active_record/associations/join_dependency/join_association.rb +46 -104
  27. data/lib/active_record/associations/join_dependency/join_base.rb +6 -8
  28. data/lib/active_record/associations/join_dependency/join_part.rb +18 -37
  29. data/lib/active_record/associations/join_dependency.rb +208 -168
  30. data/lib/active_record/associations/preloader/association.rb +69 -27
  31. data/lib/active_record/associations/preloader/collection_association.rb +2 -2
  32. data/lib/active_record/associations/preloader/has_many_through.rb +1 -1
  33. data/lib/active_record/associations/preloader/singular_association.rb +3 -3
  34. data/lib/active_record/associations/preloader/through_association.rb +58 -26
  35. data/lib/active_record/associations/preloader.rb +63 -49
  36. data/lib/active_record/associations/singular_association.rb +6 -5
  37. data/lib/active_record/associations/through_association.rb +30 -9
  38. data/lib/active_record/associations.rb +116 -42
  39. data/lib/active_record/attribute_assignment.rb +6 -3
  40. data/lib/active_record/attribute_methods/before_type_cast.rb +2 -1
  41. data/lib/active_record/attribute_methods/dirty.rb +35 -26
  42. data/lib/active_record/attribute_methods/primary_key.rb +8 -1
  43. data/lib/active_record/attribute_methods/read.rb +56 -29
  44. data/lib/active_record/attribute_methods/serialization.rb +44 -12
  45. data/lib/active_record/attribute_methods/time_zone_conversion.rb +13 -1
  46. data/lib/active_record/attribute_methods/write.rb +59 -26
  47. data/lib/active_record/attribute_methods.rb +82 -43
  48. data/lib/active_record/autosave_association.rb +209 -194
  49. data/lib/active_record/base.rb +6 -2
  50. data/lib/active_record/callbacks.rb +2 -2
  51. data/lib/active_record/coders/json.rb +13 -0
  52. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +5 -10
  53. data/lib/active_record/connection_adapters/abstract/database_statements.rb +14 -24
  54. data/lib/active_record/connection_adapters/abstract/query_cache.rb +13 -13
  55. data/lib/active_record/connection_adapters/abstract/quoting.rb +6 -3
  56. data/lib/active_record/connection_adapters/abstract/savepoints.rb +21 -0
  57. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +90 -0
  58. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +9 -8
  59. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +45 -70
  60. data/lib/active_record/connection_adapters/abstract/transaction.rb +1 -0
  61. data/lib/active_record/connection_adapters/abstract_adapter.rb +28 -96
  62. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +74 -66
  63. data/lib/active_record/connection_adapters/column.rb +1 -35
  64. data/lib/active_record/connection_adapters/connection_specification.rb +231 -43
  65. data/lib/active_record/connection_adapters/mysql2_adapter.rb +10 -5
  66. data/lib/active_record/connection_adapters/mysql_adapter.rb +24 -17
  67. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +22 -15
  68. data/lib/active_record/connection_adapters/postgresql/cast.rb +12 -4
  69. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +18 -44
  70. data/lib/active_record/connection_adapters/postgresql/oid.rb +38 -14
  71. data/lib/active_record/connection_adapters/postgresql/quoting.rb +37 -12
  72. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +20 -11
  73. data/lib/active_record/connection_adapters/postgresql_adapter.rb +98 -52
  74. data/lib/active_record/connection_adapters/schema_cache.rb +8 -29
  75. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +55 -60
  76. data/lib/active_record/connection_handling.rb +39 -5
  77. data/lib/active_record/core.rb +38 -54
  78. data/lib/active_record/counter_cache.rb +9 -10
  79. data/lib/active_record/dynamic_matchers.rb +6 -2
  80. data/lib/active_record/enum.rb +199 -0
  81. data/lib/active_record/errors.rb +22 -5
  82. data/lib/active_record/fixture_set/file.rb +2 -1
  83. data/lib/active_record/fixtures.rb +173 -76
  84. data/lib/active_record/gem_version.rb +15 -0
  85. data/lib/active_record/inheritance.rb +23 -9
  86. data/lib/active_record/integration.rb +54 -1
  87. data/lib/active_record/locking/optimistic.rb +7 -2
  88. data/lib/active_record/locking/pessimistic.rb +1 -1
  89. data/lib/active_record/log_subscriber.rb +6 -13
  90. data/lib/active_record/migration/command_recorder.rb +8 -2
  91. data/lib/active_record/migration.rb +91 -56
  92. data/lib/active_record/model_schema.rb +7 -14
  93. data/lib/active_record/nested_attributes.rb +25 -13
  94. data/lib/active_record/no_touching.rb +52 -0
  95. data/lib/active_record/null_relation.rb +26 -6
  96. data/lib/active_record/persistence.rb +23 -29
  97. data/lib/active_record/querying.rb +15 -12
  98. data/lib/active_record/railtie.rb +12 -61
  99. data/lib/active_record/railties/databases.rake +37 -56
  100. data/lib/active_record/readonly_attributes.rb +0 -6
  101. data/lib/active_record/reflection.rb +230 -79
  102. data/lib/active_record/relation/batches.rb +74 -24
  103. data/lib/active_record/relation/calculations.rb +52 -48
  104. data/lib/active_record/relation/delegation.rb +54 -39
  105. data/lib/active_record/relation/finder_methods.rb +210 -67
  106. data/lib/active_record/relation/merger.rb +15 -12
  107. data/lib/active_record/relation/predicate_builder/array_handler.rb +29 -0
  108. data/lib/active_record/relation/predicate_builder/relation_handler.rb +17 -0
  109. data/lib/active_record/relation/predicate_builder.rb +81 -40
  110. data/lib/active_record/relation/query_methods.rb +185 -108
  111. data/lib/active_record/relation/spawn_methods.rb +8 -5
  112. data/lib/active_record/relation.rb +79 -84
  113. data/lib/active_record/result.rb +45 -6
  114. data/lib/active_record/runtime_registry.rb +5 -0
  115. data/lib/active_record/sanitization.rb +4 -4
  116. data/lib/active_record/schema_dumper.rb +18 -6
  117. data/lib/active_record/schema_migration.rb +31 -18
  118. data/lib/active_record/scoping/default.rb +5 -18
  119. data/lib/active_record/scoping/named.rb +14 -29
  120. data/lib/active_record/scoping.rb +5 -0
  121. data/lib/active_record/store.rb +67 -18
  122. data/lib/active_record/tasks/database_tasks.rb +66 -26
  123. data/lib/active_record/tasks/mysql_database_tasks.rb +16 -10
  124. data/lib/active_record/tasks/postgresql_database_tasks.rb +1 -1
  125. data/lib/active_record/tasks/sqlite_database_tasks.rb +5 -1
  126. data/lib/active_record/timestamp.rb +6 -6
  127. data/lib/active_record/transactions.rb +10 -12
  128. data/lib/active_record/validations/presence.rb +1 -1
  129. data/lib/active_record/validations/uniqueness.rb +19 -9
  130. data/lib/active_record/version.rb +4 -7
  131. data/lib/active_record.rb +5 -7
  132. data/lib/rails/generators/active_record/migration/migration_generator.rb +4 -0
  133. data/lib/rails/generators/active_record/migration.rb +18 -0
  134. data/lib/rails/generators/active_record/model/model_generator.rb +4 -0
  135. data/lib/rails/generators/active_record.rb +2 -8
  136. metadata +18 -30
  137. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +0 -65
  138. data/lib/active_record/associations/join_helper.rb +0 -45
  139. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +0 -60
  140. data/lib/active_record/tasks/firebird_database_tasks.rb +0 -56
  141. data/lib/active_record/tasks/oracle_database_tasks.rb +0 -45
  142. data/lib/active_record/tasks/sqlserver_database_tasks.rb +0 -48
  143. data/lib/active_record/test_case.rb +0 -96
data/CHANGELOG.md CHANGED
@@ -1,2847 +1,2682 @@
1
- ## Rails 4.0.4 (March 14, 2014) ##
1
+ ## Rails 4.1.16 (July 12, 2016) ##
2
2
 
3
- * Only save has_one associations if record has changes.
4
- Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
5
- object did not get saved to the db.
3
+ * Correctly pass MySQL options when using structure_dump or structure_load
6
4
 
7
- *Alan Kennedy*
5
+ Specifically, it fixes an issue when using SSL authentication.
8
6
 
9
- * Fixed STI classes not defining an attribute method if there is a
10
- conflicting private method defined on its ancestors.
7
+ *Alex Coomans*
11
8
 
12
- Fixes #11569.
13
9
 
14
- *Godfrey Chan*
10
+ ## Rails 4.1.15 (March 07, 2016) ##
15
11
 
16
- * Fix validation on uniqueness of empty association.
12
+ * Fixes custom primary keys for associations when calling `Relation#where`
17
13
 
18
- *Evgeny Li*
14
+ Fixes #23327.
19
15
 
20
- * Perform necessary deeper encoding when hstore is inside an array.
16
+ *Rick Song*
21
17
 
22
- Fixes #11135.
18
+ * No longer pass deprecated option `-i` to `pg_dump`.
23
19
 
24
- *Josh Goodall*, *Genadi Samokovarov*
20
+ *Paul Sadauskas*
25
21
 
26
- * Properly detect if a connection is still active before using it
27
- in multi-threaded environments.
28
22
 
29
- Fixes #12867.
23
+ ## Rails 4.1.14.2 (February 26, 2016) ##
30
24
 
31
- *Kevin Casey*, *Matthew Draper*, *William (B.J.) Snow Orvis*
25
+ * No changes.
32
26
 
33
- * When inverting add_index use the index name if present instead of
34
- the columns.
35
27
 
36
- If there are two indices with matching columns and one of them is
37
- explicitly named then reverting the migration adding the named one
38
- would instead drop the unnamed one.
28
+ ## Rails 4.1.14.1 (January 25, 2015) ##
39
29
 
40
- The inversion of add_index will now drop the index by its name if
41
- it is present.
30
+ * No changes.
42
31
 
43
- *Hubert Dąbrowski*
44
32
 
45
- * Make sure transaction state gets reset after a commit operation on the record.
33
+ ## Rails 4.1.14 (November 12, 2015) ##
46
34
 
47
- If a new transaction was open inside a callback, the record was loosing track
48
- of the transaction level state, and it was leaking that state.
35
+ * No longer pass deprecated option `-i` to `pg_dump`.
49
36
 
50
- Fixes #12566.
37
+ *Paul Sadauskas*
51
38
 
52
- *arthurnn*
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.
53
41
 
54
- * PostgreSQL implementation of `SchemaStatements#index_name_exists?`.
42
+ Fixes #16032.
55
43
 
56
- The database agnostic implementation does not detect with indexes that are
57
- not supported by the ActiveRecord schema dumper. For example, expressions
58
- indexes would not be detected.
44
+ Examples:
59
45
 
60
- Fixes #11018.
46
+ before:
61
47
 
62
- *Jonathan Baudanza*
48
+ Project.first.salaried_developers.size # => 3
49
+ Project.includes(:salaried_developers).first.salaried_developers.size # => 1
63
50
 
64
- * Parsing PostgreSQL arrays with empty strings now works correctly.
51
+ after:
65
52
 
66
- Previously, if you tried to parse `{"1","","2","","3"}` the result
67
- would be `["1","2","3"]`, removing the empty strings from the array,
68
- which would be incorrect. Now it will correctly produce `["1","","2","","3"]`
69
- as the result of parsing the above PostgreSQL array.
53
+ Project.first.salaried_developers.size # => 3
54
+ Project.includes(:salaried_developers).first.salaried_developers.size # => 3
70
55
 
71
- Fixes #13907.
56
+ *Bigxiang*
72
57
 
73
- *Maurício Linhares*
74
58
 
75
- * Fix regressions on `select_*` methods.
76
- When `select_*` methods receive a `Relation` object, they should be able to get the arel/binds from it.
77
- Also fix regressions on select_rows that was ignoring the binds.
59
+ ## Rails 4.1.13 (August 24, 2015) ##
78
60
 
79
- Fixes #7538, #12017, #13731, #12056.
61
+ * Don't define autosave association callbacks twice from
62
+ `accepts_nested_attributes_for`.
80
63
 
81
- *arthurnn*
64
+ Fixes #18704.
82
65
 
83
- * Correctly send an user provided statement to a `lock!()` call.
66
+ *Sean Griffin*
84
67
 
85
- person.lock! 'FOR SHARE NOWAIT'
86
- # Before: SELECT * ... LIMIT 1 FOR UPDATE
87
- # After: SELECT * ... LIMIT 1 FOR SHARE NOWAIT
88
68
 
89
- Fixes #13788.
69
+ ## Rails 4.1.12 (June 25, 2015) ##
90
70
 
91
- *Maurício Linhares*
71
+ * Raises the right exception when declares a has many through
72
+ association with missing source.
92
73
 
93
- * Active Record objects can now be correctly dumped, loaded and dumped again without issues.
74
+ *Mauro George*
94
75
 
95
- Previously, if you did `YAML.dump`, `YAML.load` and then `YAML.dump` again
96
- in an ActiveRecord model that used serialization it would fail at the last
97
- dump due to the fields not being correctly serialized before being dumped
98
- to YAML. Now it is possible to dump and load the same object as many times
99
- as needed without any issues.
76
+ * Revert behavior of `db:schema:load` back to loading the full
77
+ environment. This ensures that initializers are run.
100
78
 
101
- Fixes #13861.
79
+ Fixes #19545.
102
80
 
103
- *Maurício Linhares*
81
+ *Yves Senn*
104
82
 
105
- * `has_one` and `belongs_to` accessors don't add ORDER BY to the queries anymore.
83
+ * Rename `:class` to `:anonymous_class` in association options.
106
84
 
107
- Since Rails 4.0, we add an ORDER BY in the `first` method to ensure consistent results
108
- among different database engines. But for singular associations this behavior is not needed
109
- since we will have one record to return. As this ORDER BY option can lead some performance
110
- issues we are removing it for singular associations accessors.
85
+ Fixes #19659.
111
86
 
112
- Fixes #12623.
87
+ *Andrew White*
113
88
 
114
- *Rafael Mendonça França*
89
+ * Fix referencing wrong table aliases while joining tables of has many through
90
+ association (only when calling calculation methods).
115
91
 
116
- * Fail early with "Primary key not included in the custom select clause"
117
- in `find_in_batches`.
92
+ Fixes #19276.
118
93
 
119
- Before this patch, the exception was raised after the first batch was
120
- yielded to the block. This means that you only get it, when you hit the
121
- `batch_size` treshold. This could shadow the issue in development.
94
+ *pinglamb*
122
95
 
123
- *Alexander Balashov*
124
96
 
125
- * ActiveRecord states are now correctly restored after a rollback for
126
- models that did not define any transactional callbacks (i.e.
127
- `after_commit`, `after_rollback` or `after_create`).
97
+ ## Rails 4.1.11 (June 16, 2015) ##
128
98
 
129
- Fixes #13744.
99
+ * No changes.
130
100
 
131
- *Godfrey Chan*
132
101
 
133
- * Add back `#yaml_initialize` method for Syck deserialization
102
+ ## Rails 4.1.10 (March 19, 2015) ##
134
103
 
135
- `ActiveRecord::Core#yaml_initialize` has been added back to support deserialization using
136
- the Syck engine. This is to facilitate migration from Syck to Psych. Serialization support
137
- will not been restored for Syck, Psych should be used to serialize YAML once its been
138
- parsed with Syck.
104
+ * Fixed ActiveRecord::Relation#becomes! and changed_attributes issues for type column
139
105
 
140
- *Blake Mesdag*, *arthurnn*
106
+ Fixes #17139.
141
107
 
142
- * Make `touch` fire the `after_commit` and `after_rollback` callbacks.
108
+ *Miklos Fazekas*
143
109
 
144
- *Harry Brundage*
110
+ * A `NullRelation` should represent nothing. This fixes a bug where
111
+ `Comment.where(post_id: Post.none)` returned a non-empty result.
145
112
 
146
- * Don't try to get the subclass if the inheritance column doesn't exist
113
+ Closes #15176.
147
114
 
148
- The `subclass_from_attrs` method is called even if the column specified by
149
- the `inheritance_column` setting doesn't exist. This prevents setting associations
150
- via the attributes hash if the association name clashes with the value of the setting,
151
- typically `:type`. This worked previously in Rails 3.2.
115
+ *Matthew Draper*, *Yves Senn*
152
116
 
153
- *Ujjwal Thaakar*
117
+ * Respect custom primary keys for associations when calling `Relation#where`
154
118
 
155
- * Fix bug in `becomes!` when changing from the base model to a STI sub-class.
119
+ Fixes #18813.
156
120
 
157
- Fixes #13272.
121
+ *Sean Griffin*
158
122
 
159
- *the-web-dev*, *Yves Senn*
123
+ * Fixed ActiveRecord::Relation#group method when argument is SQL reserved key word:
160
124
 
161
- * Initialize version on Migration objects so that it can be used in a migration,
162
- and it will be included in the announce message.
125
+ SplitTest.group(:key).count
126
+ Property.group(:value).count
163
127
 
164
- *Dylan Thacker-Smith*
128
+ *Bogdan Gusiev*
165
129
 
166
- * `change_table` now uses the current adapter's `update_table_definition`
167
- method to retrieve a specific table definition.
168
- This ensures that `change_table` and `create_table` will use
169
- similar objects.
130
+ * Fixed setting of foreign_key for through associations while building of new record.
170
131
 
171
- Fixes #13577 and #13503.
132
+ Fixes #12698.
172
133
 
173
- *Nishant Modak*, *Prathamesh Sonpatki*, *Rafael Mendonça França*
134
+ *Ivan Antropov*
174
135
 
175
- * Fixed ActiveRecord::Store nil conversion TypeError when using YAML coder.
176
- In case the YAML passed as paramter is nil, uses an empty string.
136
+ * Fixed automatic inverse_of for models nested in module.
177
137
 
178
- Fixes #13570.
138
+ *Andrew McCloud*
179
139
 
180
- *Thales Oliveira*
140
+ * Fix `reaping_frequency` option when the value is a string.
181
141
 
182
- * Fix presence validator for association when the associated record responds to `to_a`.
142
+ This usually happens when it is configured using `DATABASE_URL`.
183
143
 
184
- *gmarik*
144
+ *korbin*
185
145
 
186
- * Fix bug in `belongs_to` association with `touch: true`.
187
- Associated records are no longer touched, when they are already destroyed.
188
146
 
189
- Fixes #13445.
147
+ ## Rails 4.1.9 (January 6, 2015) ##
190
148
 
191
- Example:
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.
192
152
 
193
- # Given Comment has belongs_to :post, touch: true
194
- comment.post.destroy
195
- comment.destroy # no longer touches post
153
+ Closes #17945.
196
154
 
197
- *Paul Nikitochkin*
155
+ *Yves Senn*
198
156
 
199
- * Fixed `update_column`, `update_columns`, and `update_all` to correctly serialize
200
- values for `array`, `hstore` and `json` column types in PostgreSQL.
157
+ * Bring back `db:test:prepare` to synchronize the test database schema.
201
158
 
202
- Fixes #12261.
159
+ Manual synchronization using `bin/rake db:test:prepare` is required
160
+ when a migration is rolled-back, edited and reapplied.
203
161
 
204
- *Tadas Tamosauskas*, *Carlos Antonio da Silva*
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.
205
165
 
206
- * Do not consider PostgreSQL array columns as number or text columns.
166
+ NOTE: `test:prepare` runs before the schema was synchronized.
207
167
 
208
- The code uses these checks in several places to know what to do with a
209
- particular column, for instance AR attribute query methods has a branch
210
- like this:
168
+ Fixes #17171, #15787.
211
169
 
212
- if column.number?
213
- !value.zero?
214
- end
170
+ *Yves Senn*
215
171
 
216
- This should never be true for array columns, since it would be the same
217
- as running [].zero?, which results in a NoMethodError exception.
172
+ * Renaming a table in pg also renames the primary key index.
218
173
 
219
- Fixing this by ensuring that array columns in PostgreSQL never return
220
- true for number?/text? checks.
174
+ Fixes #12856
221
175
 
222
- *Carlos Antonio da Silva*
176
+ *Sean Griffin*
223
177
 
224
- * Fix a bug when assigning an array containing string numbers to a
225
- PostgreSQL integer array column.
178
+ * Make it possible to access fixtures excluded by a `default_scope`.
226
179
 
227
- Fixes #13444.
180
+ *Yves Senn*
228
181
 
229
- Example:
182
+ * `timestamps` and `add_timestamps` passes additional options along.
183
+ (like `null: false`)
230
184
 
231
- # Given Book#ratings is of type :integer, array: true
232
- Book.new(ratings: [1, 2]) # worked before
233
- Book.new(ratings: ['1', '2']) # now works as well
185
+ Closes #17624.
234
186
 
235
- *Damien Mathieu*
187
+ *Yves Senn*
236
188
 
237
- * `db:test:clone` and `db:test:prepare` must load Rails environment.
238
189
 
239
- `db:test:clone` and `db:test:prepare` use `ActiveRecord::Base`. configurations,
240
- so we need to load the Rails environment, otherwise the config wont be in place.
190
+ ## Rails 4.1.8 (November 16, 2014) ##
241
191
 
242
- *arthurnn*
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.
243
195
 
244
- * Use the right column to type cast grouped calculations with custom expressions.
196
+ *Ben Woosley*
245
197
 
246
- Fixes #13230.
198
+ * Fix preloading of associations which unscope a default scope.
247
199
 
248
- Example:
200
+ Fixes #11036.
249
201
 
250
- # Before
251
- Account.group(:firm_name).sum('0.01 * credit_limit')
252
- # => { '37signals' => '0.5' }
202
+ *Byron Bischoff*
253
203
 
254
- # After
255
- Account.group(:firm_name).sum('0.01 * credit_limit')
256
- # => { '37signals' => 0.5 }
204
+ * Do not use `RENAME INDEX` syntax for MariaDB 10.0.
257
205
 
258
- *Paul Nikitochkin*
206
+ Fixes #15931.
259
207
 
260
- * Support deprecated finder options when performing calculations
261
- on an association.
208
+ *Jeff Browning*
262
209
 
263
- Fixes #13165.
210
+ * Allow included modules to override association methods.
264
211
 
265
- *Garth Smedley*, *Yves Senn*
212
+ Fixes #16684.
266
213
 
267
- * `ActiveRecord::ConnectionAdapters.string_to_time` respects
268
- string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
214
+ *Yves Senn*
269
215
 
270
- Fixes #12278, #12459.
216
+ * Schema loading rake tasks (like `db:schema:load` and `db:setup`) maintain
217
+ the database connection to the current environment.
271
218
 
272
- *kennyj*, *George Guimarães*
219
+ Fixes #16757.
273
220
 
274
- * Polymorphic `belongs_to` associations with the `touch: true` option set update the timestamps of
275
- the old and new owner correctly when moved between owners of different types.
221
+ *Joshua Cody*, *Yves Senn*
276
222
 
277
- Example:
223
+ * `db:purge` with MySQL respects `Rails.env`.
278
224
 
279
- class Rating < ActiveRecord::Base
280
- belongs_to :rateable, polymorphic: true, touch: true
281
- end
225
+ *Yves Senn*
282
226
 
283
- rating = Rating.create rateable: Song.find(1)
284
- rating.update_attributes rateable: Book.find(2) # => timestamps of Song(1) and Book(2) are updated
227
+ * Fixed automatic maintaining test schema to properly handle sql structure
228
+ schema format.
285
229
 
286
- *Severin Schoepke*
230
+ Fixes #15394.
287
231
 
288
- * `type_to_sql` returns a `String` for unmapped columns. This fixes an error
289
- when using unmapped array types in combination with PostgreSQL's `array: true`.
232
+ *Wojciech Wnętrzak*
290
233
 
291
- Fixes #13146.
234
+ * Fix has_many :through relation merging failing when dynamic conditions are
235
+ passed as a lambda with an arity of one.
292
236
 
293
- Example:
237
+ Fixes #16128.
294
238
 
295
- change_colum :table, :column, :bigint, array: true
239
+ *Agis Anastasopoulos*
296
240
 
297
- *Jens Fahnenbruck*, *Yves Senn*
298
241
 
299
- * Previously, the `has_one` macro incorrectly accepts the `counter_cache`
300
- option due to a bug, although that options was never supported nor
301
- functional on `has_one` and `has_one ... through` relationships. It now
302
- correctly raises an `ArgumentError` when passed that option.
242
+ ## Rails 4.1.7.1 (November 19, 2014) ##
303
243
 
304
- *Godfrey Chan*
244
+ * No changes.
305
245
 
306
- * Update counter cache on a has_many relationship regardless of default scope
307
246
 
308
- Fix #12952.
247
+ ## Rails 4.1.7 (October 29, 2014) ##
309
248
 
310
- *Uku Taht*
249
+ * No changes.
311
250
 
312
- * Fix bug when validating the uniqueness of an aliased attribute.
313
251
 
314
- Fixes #12402.
252
+ ## Rails 4.1.6 (September 11, 2014) ##
315
253
 
316
- *Lauro Caetano*
254
+ * Fixed a regression where whitespaces were stripped from DISTINCT queries in
255
+ PostgreSQL.
317
256
 
318
- * Checks to see if the record contains the foreign key to set the inverse automatically.
257
+ *Agis Anastasopoulos*
319
258
 
320
- *Edo Balvers*
259
+ Fixes #16623.
321
260
 
322
- * Prevent the counter cache from being decremented twice when destroying
323
- a record on a has_many :through association.
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.
324
264
 
325
- Fixes #11079.
265
+ Fixes #16288.
326
266
 
327
- *Dmitry Dedov*
267
+ * Baseclass becomes! subclass.
328
268
 
329
- * Fix bug where has_one associaton record update result in crash, when replaced with itself.
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.
330
271
 
331
- Fixes #12834.
272
+ Fixes #14785.
332
273
 
333
- *Denis Redozubov*, *Sergio Cambra*
274
+ *Matthew Draper*, *Earl St Sauver*, *Edo Balvers*
334
275
 
335
- * Fix uninitialized constant TransactionState error when Marshall.load is used on an Active Record result.
276
+ * Fix regression on after_commit that didnt fire when having nested transactions.
336
277
 
337
- Fixes #12790.
278
+ Fixes #16425.
338
279
 
339
- *Jason Ayre*
280
+ *arthurnn*
340
281
 
341
- * Do not add to scope includes values from through associations.
342
- Fixed bug when providing `includes` in through association scope, and fetching targets.
282
+ * Define `id_was` to get the previous value of the primary key.
343
283
 
344
- Example:
345
- class Vendor < ActiveRecord::Base
346
- has_many :relationships, -> { includes(:user) }
347
- has_many :users, through: :relationships
348
- end
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.
349
288
 
350
- vendor = Vendor.first
289
+ Fixes #16413.
351
290
 
352
- # Before
291
+ *Rafael Mendonça França*
353
292
 
354
- vendor.users.to_a # => Raises exception: not found `:user` for `User`
293
+ * Fix the schema dump generated for tables without constraints and with
294
+ primary key with default value of custom PostgreSQL function result.
355
295
 
356
- # After
296
+ Fixes #16111.
357
297
 
358
- vendor.users.to_a # => No exception is raised
298
+ *Andrey Novikov*
359
299
 
300
+ * Restore 4.0 behavior for using serialize attributes with `JSON` as coder.
360
301
 
361
- Fixes #12242, #9517, #10240.
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.
362
304
 
363
- *Paul Nikitochkin*
305
+ Example:
364
306
 
365
- * Save `has_one` association when primary key is manually set.
307
+ class Post < ActiveRecord::Base
308
+ serialize :comment, JSON
309
+ end
366
310
 
367
- Fixes #12302.
311
+ class Comment
312
+ include ActiveModel::Model
313
+ attr_accessor :category, :text
314
+ end
368
315
 
369
- *Lauro Caetano*
316
+ post = Post.create!
317
+ post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
318
+ post.save!
370
319
 
371
- * Allow any version of BCrypt when using `has_secury_password`.
320
+ # 4.0
321
+ post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
372
322
 
373
- *Mike Perham*
323
+ # 4.1 before
324
+ post.comment # => "#<Comment:0x007f80ab48ff98>"
374
325
 
375
- * Assign inet/cidr attribute with `nil` value for invalid address.
326
+ # 4.1 after
327
+ post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
376
328
 
377
- Example:
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.
378
333
 
379
- record = User.new
334
+ To keep the previous behaviour, supply a custom coder instead
335
+ ([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
380
336
 
381
- record.logged_in_from_ip # is type of an inet or a cidr
337
+ Fixes #15594.
382
338
 
383
- # Before:
384
- record.logged_in_from_ip = 'bad ip address' # raise exception
339
+ *Jenn Cooper*
385
340
 
386
- # After:
387
- record.logged_in_from_ip = 'bad ip address' # do not raise exception
388
- record.logged_in_from_ip # => nil
389
- record.logged_in_from_ip_before_type_cast # => 'bad ip address'
341
+ * Fixed error in `reset_counters` when associations have `select` scope.
342
+ (Call to `count` generates invalid SQL.)
390
343
 
391
- *Paul Nikitochkin*
344
+ *Cade Truitt*
392
345
 
393
- * `rake db:structure:dump` no longer crashes when the port was specified as `Fixnum`.
346
+ * After a successful `reload`, `new_record?` is always false.
394
347
 
395
- *Kenta Okamoto*
348
+ Fixes #12101.
396
349
 
397
- * Fix a bug where rake db:structure:load crashed when the path contained
398
- spaces.
350
+ *Matthew Draper*
399
351
 
400
- *Kevin Mook*
352
+ * Correctly extract IPv6 addresses from `DATABASE_URI`: the square brackets
353
+ are part of the URI structure, not the actual host.
401
354
 
402
- * `ActiveRecord::QueryMethods#unscope` unscopes negative equality
355
+ Fixes #15705.
403
356
 
404
- Allows you to call `#unscope` on a relation with negative equality
405
- operators, i.e. `Arel::Nodes::NotIn` and `Arel::Nodes::NotEqual` that have
406
- been generated through the use of `where.not`.
357
+ *Andy Bakun*, *Aaron Stone*
407
358
 
408
- *Eric Hankins*
359
+ * Don't error when quoting user defined types in PostgreSQL.
409
360
 
361
+ Fixes #15697.
410
362
 
411
- ## Rails 4.0.3 (February 18, 2014) ##
363
+ *Sean Griffin*
412
364
 
413
- * Correctly escape PostgreSQL arrays.
365
+ * Ensure both parent IDs are set on join records when both sides of a
366
+ through association are new.
414
367
 
415
- Fixes: CVE-2014-0080
368
+ *Sean Griffin*
416
369
 
370
+ * Pluck now works when selecting columns from different tables with the same
371
+ name.
417
372
 
418
- ## Rails 4.0.2 (December 02, 2013) ##
373
+ Fixes #15649.
419
374
 
420
- *No changes*
375
+ *Sean Griffin*
421
376
 
377
+ * `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
378
+ `Enumerable#find` does.
422
379
 
423
- ## Rails 4.0.1 (November 01, 2013) ##
380
+ Fixes #15382.
424
381
 
425
- * `NullRelation#pluck` takes a list of columns
382
+ *James Yang*
426
383
 
427
- The method signature in `NullRelation` was updated to mimic that in
428
- `Calculations`.
384
+ * `ActiveRecord::SchemaMigration` has no primary key regardless of the
385
+ `primary_key_prefix_type` configuration.
429
386
 
430
- *Derek Prior*
387
+ Fixes #15051.
431
388
 
432
- * `scope_chain` should not be mutated for other reflections.
389
+ *JoseLuis Torres*, *Yves Senn*
433
390
 
434
- Currently `scope_chain` uses same array for building different
435
- `scope_chain` for different associations. During processing
436
- these arrays are sometimes mutated and because of in-place
437
- mutation the changed `scope_chain` impacts other reflections.
391
+ * `rake db:migrate:status` works with legacy migration numbers like `00018_xyz.rb`.
438
392
 
439
- Fix is to dup the value before adding to the `scope_chain`.
393
+ Fixes #15538.
440
394
 
441
- Fixes #3882.
395
+ *Yves Senn*
442
396
 
443
- *Neeraj Singh*
397
+ * Fixed `columns_for_distinct` of postgresql adapter to work correctly
398
+ with orders without sort direction modifiers.
444
399
 
445
- * Prevent the inversed association from being reloaded on save.
400
+ *Nikolay Kondratyev*
446
401
 
447
- Fixes #9499.
402
+ * Keep PostgreSQL `hstore` and `json` attributes as `Hash` in `@attributes`.
403
+ Fixes duplication in combination with `store_accessor`.
448
404
 
449
- *Dmitry Polushkin*
405
+ Fixes #15369.
450
406
 
451
- * `Relation#order` quotes the column name if you pass a `Symbol`.
452
- Fixes #11870.
407
+ *Yves Senn*
453
408
 
454
- Example:
409
+ * `rake railties:install:migrations` respects the order of railties.
455
410
 
456
- # Before
457
- Post.order(:id).to_sql == '... ORDER BY "posts".id ASC'
411
+ *Arun Agrawal*
458
412
 
459
- # After
460
- Post.order(:id).to_sql == '... ORDER BY "posts"."id" ASC'
461
413
 
462
- *Yves Senn*
414
+ ## Rails 4.1.5 (August 18, 2014) ##
463
415
 
464
- * Generate subquery for `Relation` if it passed as array condition for `where`
465
- method.
416
+ * No changes.
466
417
 
467
- Example:
468
418
 
469
- # Before
470
- Blog.where('id in (?)', Blog.where(id: 1))
471
- # => SELECT "blogs".* FROM "blogs" WHERE "blogs"."id" = 1
472
- # => SELECT "blogs".* FROM "blogs" WHERE (id IN (1))
419
+ ## Rails 4.1.4 (July 2, 2014) ##
473
420
 
474
- # After
475
- Blog.where('id in (?)', Blog.where(id: 1).select(:id))
476
- # => SELECT "blogs".* FROM "blogs"
477
- # WHERE "blogs"."id" IN (SELECT "blogs"."id" FROM "blogs" WHERE "blogs"."id" = 1)
421
+ * Fix regression added from the latest security fix.
478
422
 
479
- Fixes #12415.
423
+ *Sean Griffin*, *Matthew Draper*
480
424
 
481
- *Paul Nikitochkin*
482
425
 
483
- * For missed association exception message
484
- which is raised in `ActiveRecord::Associations::Preloader` class
485
- added owner record class name in order to simplify to find problem code.
426
+ ## Rails 4.1.3 (July 2, 2014) ##
486
427
 
487
- *Paul Nikitochkin*
428
+ * Fix SQL Injection Vulnerability in 'range' quoting.
488
429
 
489
- * Fixes bug when using includes combined with select, the select statement was overwritten.
430
+ Fixes CVE-2014-3483
490
431
 
491
- Fixes #11773.
432
+ *Rafael Mendonça França*
492
433
 
493
- *Edo Balvers*
494
434
 
495
- * Objects instantiated using a null relationship will now retain the
496
- attributes of the where clause.
435
+ ## Rails 4.1.2 (June 26, 2014) ##
497
436
 
498
- Fixes #11676, #11675, #11376.
437
+ * Fix regression on eager loading association based on SQL query rather than
438
+ existing column.
499
439
 
500
- *Paul Nikitochkin*, *Peter Brown*, *Nthalk*
440
+ Fixes #15480.
501
441
 
502
- * Fixed `ActiveRecord::Associations::CollectionAssociation#find`
503
- when using `has_many` association with `:inverse_of` and finding an array of one element,
504
- it should return an array of one element too.
442
+ *Lauro Caetano*, *Carlos Antonio da Silva*
443
+
444
+ * Fix redefine a has_and_belongs_to_many inside inherited class
445
+ Fixing regression case, where redefining the same has_an_belongs_to_many
446
+ definition into a subclass would raise.
447
+
448
+ Fixes #14983.
505
449
 
506
450
  *arthurnn*
507
451
 
508
- * Callbacks on has_many should access the in memory parent if a inverse_of is set.
452
+ * Fix has_and_belongs_to_many public reflection.
453
+ When defining a has_and_belongs_to_many, internally we convert that to two has_many.
454
+ But as `reflections` is a public API, people expect to see the right macro.
455
+
456
+ Fixes #14682.
509
457
 
510
458
  *arthurnn*
511
459
 
512
- * Migration dump UUID default functions to schema.rb.
460
+ * Fixed serialization for records with an attribute named `format`.
513
461
 
514
- Fixes #10751.
462
+ Fixes #15188.
515
463
 
516
- *kennyj*
464
+ *Godfrey Chan*
517
465
 
518
- * Fixed a bug in `ActiveRecord::Associations::CollectionAssociation#find_by_scan`
519
- when using `has_many` association with `:inverse_of` option and UUID primary key.
466
+ * Fixed serialized fields returning serialized data after being updated with
467
+ `update_column`.
520
468
 
521
- Fixes #10450.
469
+ *Simon Hørup Eskildsen*
522
470
 
523
- *kennyj*
471
+ * When a `group` is set, `sum`, `size`, `average`, `minimum` and `maximum`
472
+ on a NullRelation should return a Hash.
524
473
 
525
- * Fix: joins association, with defined in the scope block constraints by using several
526
- where constraints and at least of them is not `Arel::Nodes::Equality`,
527
- generates invalid SQL expression.
474
+ *Kuldeep Aggarwal*
528
475
 
529
- Fixes: #11963
476
+ * Fixed polymorphic eager loading when using a String as foreign key.
530
477
 
531
- *Paul Nikitochkin*
478
+ Fixes #14734.
532
479
 
533
- * Make possible to run SQLite rake tasks without the `Rails` constant defined.
480
+ *Lauro Caetano*
534
481
 
535
- *Damien Mathieu*
482
+ * Fixed the inferred table name of a has_and_belongs_to_many auxiliar
483
+ table inside a schema.
536
484
 
537
- * Allow Relation#from to accept other relations with bind values.
485
+ Fixes #14824
538
486
 
539
- *Ryan Wallace*
487
+ *Eric Chahin*
540
488
 
541
- * Make `find_in_batches` and `find_each` work without a logger.
489
+ * Fix bug that added `table_name_prefix` and `table_name_suffix` to
490
+ extension names in PostgreSQL when migrating.
542
491
 
543
- *Dmitry Polushkin*
492
+ *Joao Carlos*
544
493
 
545
- * Fix inserts with prepared statements disabled.
494
+ * Floats with limit >= 25 that get turned into doubles in MySQL no longer have
495
+ their limit dropped from the schema.
546
496
 
547
- Fixes #12023.
497
+ Fixes #14135.
548
498
 
549
- *Rafael Mendonça França*
499
+ *Aaron Nelson*
550
500
 
551
- * Setting a has_one association on a new record no longer causes an empty
552
- transaction.
501
+ * Fix how to calculate associated class name when using namespaced has_and_belongs_to_many
502
+ association.
553
503
 
554
- *Dylan Thacker-Smith*
504
+ Fixes #14709.
555
505
 
556
- * Fix `AR::Relation#merge` sometimes failing to preserve `readonly(false)` flag.
506
+ *Kassio Borges*
557
507
 
558
- *thedarkone*
508
+ * `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and
509
+ strings in column names as equal.
559
510
 
560
- * PostgreSQL adapter recognizes negative money values formatted with
561
- parentheses (eg. `($1.25) # => -1.25`)).
562
- Fixes #11899.
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.
563
514
 
564
- * Yves Senn*
515
+ *Nat Budin*
565
516
 
566
- * Do not load all child records for inverse case.
517
+ * Fix `stored_attributes` to correctly merge the details of stored
518
+ attributes defined in parent classes.
567
519
 
568
- currently `post.comments.find(Comment.first.id)` would load all
569
- comments for the given post to set the inverse association.
520
+ Fixes #14672.
570
521
 
571
- This has a huge performance penalty. Because if post has 100k
572
- records and all these 100k records would be loaded in memory
573
- even though the comment id was supplied.
522
+ *Brad Bennett*, *Jessica Yao*, *Lakshmi Parthasarathy*
574
523
 
575
- Fix is to use in-memory records only if loaded? is true. Otherwise
576
- load the records using full sql.
524
+ * `change_column_default` allows `[]` as argument to `change_column_default`.
577
525
 
578
- Fixes #10509.
526
+ Fixes #11586.
579
527
 
580
- *Neeraj Singh*
528
+ *Yves Senn*
581
529
 
582
- * `ActiveRecord::FinderMethods#exists?` returns `true`/`false` in all cases.
530
+ * Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and
531
+ NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
583
532
 
584
- *Xavier Noria*
533
+ Example:
585
534
 
586
- * Load fixtures from linked folders.
535
+ # Before
536
+ Point.create(value: 1.0/0)
537
+ Point.last.value # => 0.0
587
538
 
588
- *Kassio Borges*
539
+ # After
540
+ Point.create(value: 1.0/0)
541
+ Point.last.value # => Infinity
589
542
 
590
- * Create a directory for sqlite3 file if not present on the system.
543
+ *Innokenty Mikhailov*
591
544
 
592
- *Richard Schneeman*
545
+ * Allow the PostgreSQL adapter to handle bigserial primary key types again.
593
546
 
594
- * Removed redundant override of `xml` column definition for PG,
595
- in order to use `xml` column type instead of `text`.
547
+ Fixes #10410.
596
548
 
597
- *Paul Nikitochkin*, *Michael Nikitochkin*
549
+ *Patrick Robertson*
598
550
 
599
- * Revert `ActiveRecord::Relation#order` change that make new order
600
- prepend the old one.
551
+ * Fixed has_and_belongs_to_many's CollectionAssociation size calculation.
601
552
 
602
- Before:
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.
603
555
 
604
- User.order("name asc").order("created_at desc")
605
- # SELECT * FROM users ORDER BY created_at desc, name asc
556
+ Fixes #14913 and #14914.
606
557
 
607
- After:
558
+ *Fred Wu*
608
559
 
609
- User.order("name asc").order("created_at desc")
610
- # SELECT * FROM users ORDER BY name asc, created_at desc
560
+ * Revert the behaviour of `ActiveRecord::Relation#join` changed through 4.0 => 4.1 to 4.0.
611
561
 
612
- This also affects order defined in `default_scope` or any kind of associations.
562
+ In 4.1.0 `Relation#join` is delegated to `Arel#SelectManager`.
563
+ In 4.0 series it is delegated to `Array#join`.
613
564
 
614
- *Rafael Mendonça França*
565
+ *Bogdan Gusiev*
615
566
 
616
- * When using optimistic locking, `update` was not passing the column to `quote_value`
617
- to allow the connection adapter to properly determine how to quote the value. This was
618
- affecting certain databases that use specific column types.
567
+ * Log nil binary column values correctly.
619
568
 
620
- Fixes #6763.
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.
621
576
 
622
- *Alfred Wong*
577
+ *James Coleman*
623
578
 
624
- * `change_column` for PostgreSQL adapter respects the `:array` option.
579
+ * Stringify all variables keys of MySQL connection configuration.
625
580
 
626
- *Yves Senn*
581
+ When `sql_mode` variable for MySQL adapters set in configuration as `String`
582
+ was ignored and overwritten by strict mode option.
627
583
 
628
- * Fixes bug introduced by #3329. Now, when autosaving associations,
629
- deletions happen before inserts and saves. This prevents a
630
- 'duplicate unique value' database error that would occur if a record being created had
631
- the same value on a unique indexed field as that of a record being destroyed.
584
+ Fixes #14895.
632
585
 
633
- *Johnny Holton*
586
+ *Paul Nikitochkin*
634
587
 
635
- * Flatten merged join values before building the joins.
588
+ * Ensure SQLite3 statements are closed on errors.
636
589
 
637
- While joining values special treatment is given to string values.
638
- By flattening the array it ensures that string values are detected
639
- as strings and not arrays.
590
+ Fixes #13631.
640
591
 
641
- Fixes #10669.
592
+ *Timur Alperovich*
642
593
 
643
- *Neeraj Singh and iwiznia*
594
+ * Fix excluding lower bounds of PostgreSQL date and int ranges.
644
595
 
645
- * Remove extra select and update queries on `save`/`touch`/`destroy` Active Record model
646
- with belongs to reflection with option `touch: true`.
596
+ *River MacLeod*, *Yves Senn*
647
597
 
648
- Fixes #11288.
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.
649
601
 
650
- *Paul Nikitochkin*
602
+ Fixes #14845.
651
603
 
652
- * Support array as root element in JSON fields.
604
+ *Kassio Borges*
653
605
 
654
- *Alexey Noskov & Francesco Rodriguez*
606
+ * `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.
655
607
 
656
- * Apply default scope when joining associations. For example:
608
+ Fixes #14841.
657
609
 
658
- class Post < ActiveRecord::Base
659
- default_scope -> { where published: true }
660
- end
610
+ *Lucas Mazza*
661
611
 
662
- class Comment
663
- belongs_to :post
664
- end
612
+ * Fix name collision with `Array#select!` with `Relation#select!`.
665
613
 
666
- When calling `Comment.joins(:post)`, we expect to receive only
667
- comments on published posts, since that is the default scope for
668
- posts.
614
+ Fixes #14752.
669
615
 
670
- Before this change, the default scope from `Post` was not applied,
671
- so we'd get comments on unpublished posts.
616
+ *Earl St Sauver*
672
617
 
673
- *Jon Leighton*
618
+ * Fixed unexpected behavior for `has_many :through` associations going through a scoped `has_many`.
674
619
 
675
- * `inspect` on Active Record model classes does not initiate a
676
- new connection. This means that calling `inspect`, when the
677
- database is missing, will no longer raise an exception.
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.
678
622
 
679
- Fixes #10936.
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.
680
664
 
681
665
  Example:
682
666
 
683
- Author.inspect # => "Author(no database connection)"
667
+ author.posts == Post.where(author_id: author.id)
668
+ # => true
669
+ Post.where(author_id: author.id) == author.posts
670
+ # => true
684
671
 
685
- *Yves Senn*
672
+ Fixes #13506.
686
673
 
687
- * Fix mysql2 adapter raises the correct exception when executing a query on a
688
- closed connection.
674
+ *Lauro Caetano*
689
675
 
690
- *Yves Senn*
676
+ * PostgreSQL adapter only warns once for every missing OID per connection.
691
677
 
692
- * Fix the `:primary_key` option for `has_many` associations.
678
+ Fixes #14275.
693
679
 
694
- Fixes #10693.
680
+ *Matthew Draper*, *Yves Senn*
695
681
 
696
- *Yves Senn*
682
+ * Fixed error for aggregate methods (`empty?`, `any?`, `count`) with `select`
683
+ which created invalid SQL.
697
684
 
698
- * Fix bug where tiny types are incorectly coerced as booleand when the length is more than 1.
685
+ Fixes #13648.
699
686
 
700
- Fixes #10620.
687
+ *Simon Woker*
701
688
 
702
- *Aaron Patterson*
689
+ * Fix insertion of records via `has_many :through` association with scope.
703
690
 
704
- * Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1.
691
+ Fixes #3548.
705
692
 
706
- *kennyj*
693
+ *Ivan Antropov*
707
694
 
708
- * Deprecate `ConnectionAdapters::SchemaStatements#distinct`,
709
- as it is no longer used by internals.
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*
710
715
 
711
- *Ben Woosley#
716
+ * Fixed error when specifying a non-empty default value on a PostgreSQL array column.
712
717
 
713
- * Remove not needed bind variables. Port of commit #5082345.
718
+ Fixes #10613.
714
719
 
715
- Fixes #10958.
720
+ *Luke Steensen*
716
721
 
717
- *Neeraj Singh*
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.
718
724
 
719
- * Confirm a record has not already been destroyed before decrementing counter cache.
725
+ Fixes #14393.
720
726
 
721
- *Ben Tucker*
727
+ *Chris Finne*
722
728
 
723
- * Fixed a bug in `ActiveRecord#sanitize_sql_hash_for_conditions` in which
724
- `self.class` is an argument to `PredicateBuilder#build_from_hash`
725
- causing `PredicateBuilder` to call non-existent method
726
- `Class#reflect_on_association`.
729
+ * `rake db:structure:dump` only dumps schema information if the schema
730
+ migration table exists.
727
731
 
728
- *Zach Ohlgren*
732
+ Fixes #14217.
729
733
 
730
- * While removing index if column option is missing then raise IrreversibleMigration exception.
734
+ *Yves Senn*
731
735
 
732
- Following code should raise `IrreversibleMigration`. But the code was
733
- failing since options is an array and not a hash.
736
+ * Add support for `Relation` be passed as parameter on `QueryCache#select_all`.
734
737
 
735
- def change
736
- change_table :users do |t|
737
- t.remove_index [:name, :email]
738
- end
739
- end
738
+ Fixes #14361.
740
739
 
741
- Fix was to check if the options is a Hash before operating on it.
740
+ *arthurnn*
742
741
 
743
- Fixes #10419.
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.
744
745
 
745
- *Neeraj Singh*
746
+ *Alan Kennedy*
746
747
 
747
748
 
748
- ## Rails 4.0.0 (June 25, 2013) ##
749
+ ## Rails 4.1.1 (May 6, 2014) ##
749
750
 
750
- * Fix `add_column` with `array` option when using PostgreSQL. Fixes #10432
751
+ * No changes.
751
752
 
752
- * Do not overwrite manually built records during one-to-one nested attribute assignment
753
753
 
754
- For one-to-one nested associations, if you build the new (in-memory)
755
- child object yourself before assignment, then the NestedAttributes
756
- module will not overwrite it, e.g.:
754
+ ## Rails 4.1.0 (April 8, 2014) ##
757
755
 
758
- class Member < ActiveRecord::Base
759
- has_one :avatar
760
- accepts_nested_attributes_for :avatar
756
+ * Fixed a problem where an enum would overwrite values of another enum
757
+ with the same name in an unrelated class.
761
758
 
762
- def avatar
763
- super || build_avatar(width: 200)
764
- end
765
- end
759
+ Fixes #14607.
766
760
 
767
- member = Member.new
768
- member.avatar_attributes = {icon: 'sad'}
769
- member.avatar.width # => 200
761
+ *Evan Whalen*
770
762
 
771
- *Olek Janiszewski*
772
763
 
773
- * fixes bug introduced by #3329. Now, when autosaving associations,
774
- deletions happen before inserts and saves. This prevents a 'duplicate
775
- unique value' database error that would occur if a record being created had
776
- the same value on a unique indexed field as that of a record being destroyed.
764
+ * Block a few default Class methods as scope name.
777
765
 
778
- *Adam Anderson*
766
+ For instance, this will raise:
779
767
 
780
- * Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix`
781
- is not blank.
768
+ scope :public, -> { where(status: 1) }
782
769
 
783
- Call `assume_migrated_upto_version` on connection to prevent it from first
784
- being picked up in `method_missing`.
770
+ *arthurnn*
785
771
 
786
- In the base class, `Migration`, `method_missing` expects the argument to be a
787
- table name, and calls `proper_table_name` on the arguments before sending to
788
- `connection`. If `table_name_prefix` or `table_name_suffix` is used, the schema
789
- version changes to `prefix_version_suffix`, breaking `rake test:prepare`.
772
+ * Deprecate SQLite database URLs containing an
773
+ authority.
790
774
 
791
- Fixes #10411.
775
+ The current "correct" spellings for in-memory, relative, and
776
+ absolute URLs, respectively, are:
792
777
 
793
- *Kyle Stevens*
778
+ sqlite3::memory:
779
+ sqlite3:relative/path
780
+ sqlite3:/full/path
794
781
 
795
- * Mute `psql` output when running rake db:schema:load.
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.
796
786
 
797
- *Godfrey Chan*
787
+ *Matthew Draper*
798
788
 
799
- * Trigger a save on `has_one association=(associate)` when the associate contents have changed.
789
+ * `where.not` adds `references` for `includes` like normal `where` calls do.
800
790
 
801
- Fix #8856.
791
+ Fixes #14406.
802
792
 
803
- *Chris Thompson*
793
+ *Yves Senn*
804
794
 
805
- * Allow to use databases.rake tasks without having `Rails.application`.
795
+ * `includes` is able to detect the right preloading strategy when string
796
+ joins are involved.
806
797
 
807
- *Piotr Sarnacki*
798
+ Fixes #14109.
808
799
 
809
- * Fix a `SystemStackError` problem when using time zone aware or serialized attributes.
810
- In current implementation, we reuse `column_types` argument when initiating an instance.
811
- If an instance has serialized or time zone aware attributes, `column_types` is
812
- wrapped multiple times in `decorate_columns` method. Thus the above error occurs.
800
+ *Aaron Patterson*, *Yves Senn*
813
801
 
814
- *Dan Erikson & kennyj*
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.
815
805
 
816
- * Fix for a regression bug in which counter cache columns were not being updated
817
- when record was pushed into a has_many association. For example:
806
+ Fixes #14172.
818
807
 
819
- Post.first.comments << Comment.create
808
+ *Vilius Luneckas* *Ahmed AbouElhamayed*
820
809
 
821
- Fixes #3891.
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.
822
815
 
823
- *Matthew Robertson*
816
+ Fixes #14144.
824
817
 
825
- * If a model was instantiated from the database using `select`, `respond_to?`
826
- returns false for non-selected attributes. For example:
818
+ * Fixed STI classes not defining an attribute method if there is a
819
+ conflicting private method defined on its ancestors.
827
820
 
828
- post = Post.select(:title).first
829
- post.respond_to?(:body) # => false
821
+ Fixes #11569.
830
822
 
831
- post = Post.select('title as post_title').first
832
- post.respond_to?(:title) # => false
823
+ *Godfrey Chan*
833
824
 
834
- Fixes #4208.
825
+ * Default scopes are no longer overriden by chained conditions.
835
826
 
836
- *Neeraj Singh*
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.
837
830
 
838
- * Run `rake migrate:down` & `rake migrate:up` in transaction if database supports.
831
+ Before:
839
832
 
840
- *Alexander Bondarev*
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
841
838
 
842
- * `0x` prefix must be added when assigning hexadecimal string into `bit` column in PostgreSQL.
839
+ User.all
840
+ # SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
843
841
 
844
- *kennyj*
842
+ User.active
843
+ # SELECT "users".* FROM "users" WHERE "users"."state" = 'active'
845
844
 
846
- * Added Statement Cache to allow the caching of a single statement. The cache works by
847
- duping the relation returned from yielding a statement, which allows skipping the AST
848
- building phase for following executes. The cache returns results in array format.
845
+ User.where(state: 'inactive')
846
+ # SELECT "users".* FROM "users" WHERE "users"."state" = 'inactive'
849
847
 
850
- Example:
848
+ After:
851
849
 
852
- cache = ActiveRecord::StatementCache.new do
853
- Book.where(name: "my book").limit(100)
850
+ class User < ActiveRecord::Base
851
+ default_scope { where state: 'pending' }
852
+ scope :active, -> { where state: 'active' }
853
+ scope :inactive, -> { where state: 'inactive' }
854
854
  end
855
855
 
856
- books = cache.execute
856
+ User.all
857
+ # SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
857
858
 
858
- The solution attempts to get closer to the speed of `find_by_sql` but still maintaining
859
- the expressiveness of the Active Record queries.
859
+ User.active
860
+ # SELECT "users".* FROM "users" WHERE "users"."state" = 'pending' AND "users"."state" = 'active'
860
861
 
861
- *Olli Rissanen*
862
+ User.where(state: 'inactive')
863
+ # SELECT "users".* FROM "users" WHERE "users"."state" = 'pending' AND "users"."state" = 'inactive'
862
864
 
863
- * Preserve context while merging relations with join information.
865
+ To get the previous behavior it is needed to explicitly remove the
866
+ `default_scope` condition using `unscoped`, `unscope`, `rewhere` or
867
+ `except`.
864
868
 
865
- class Comment < ActiveRecord::Base
866
- belongs_to :post
867
- end
869
+ Example:
868
870
 
869
- class Author < ActiveRecord::Base
870
- has_many :posts
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' }
871
875
  end
872
876
 
873
- class Post < ActiveRecord::Base
874
- belongs_to :author
875
- has_many :comments
876
- end
877
+ User.all
878
+ # SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
877
879
 
878
- `Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all`
879
- would fail with
880
- `ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`.
880
+ User.active
881
+ # SELECT "users".* FROM "users" WHERE "users"."state" = 'active'
881
882
 
882
- It is failing because `all` is being called on relation which looks like this after all
883
- the merging: `{:joins=>[:post, :author], :where=>[#<Arel::Nodes::Equality: ....}`. In this
884
- relation all the context that `Post` was joined with `Author` is lost and hence the error
885
- that `author` was not found on `Comment`.
883
+ User.inactive
884
+ # SELECT "users".* FROM "users" WHERE "users"."state" = 'inactive'
886
885
 
887
- The solution is to build `JoinAssociation` when two relations with join information are being
888
- merged. And later while building the Arel use the previously built `JoinAssociation` record
889
- in `JoinDependency#graft` to build the right from clause.
890
- Fixes #3002.
886
+ * Perform necessary deeper encoding when hstore is inside an array.
891
887
 
892
- *Jared Armstrong and Neeraj Singh*
888
+ Fixes #11135.
893
889
 
894
- * `default_scopes?` is deprecated. Check for `default_scopes.empty?` instead.
890
+ *Josh Goodall*, *Genadi Samokovarov*
895
891
 
896
- *Agis Anastasopoulos*
892
+ * Properly detect if a connection is still active before using it
893
+ in multi-threaded environments.
897
894
 
898
- * Default values for PostgreSQL bigint types now get parsed and dumped to the
899
- schema correctly.
895
+ Fixes #12867.
900
896
 
901
- *Erik Peterson*
897
+ *Kevin Casey*, *Matthew Draper*, *William (B.J.) Snow Orvis*
902
898
 
903
- * Fix associations with `:inverse_of` option when building association
904
- with a block. Inside the block the parent object was different then
905
- after the block.
899
+ * When inverting add_index use the index name if present instead of
900
+ the columns.
906
901
 
907
- Example:
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.
908
905
 
909
- parent.association.build do |child|
910
- child.parent.equal?(parent) # false
911
- end
906
+ The inversion of add_index will now drop the index by its name if
907
+ it is present.
912
908
 
913
- # vs
909
+ *Hubert Dąbrowski*
914
910
 
915
- child = parent.association.build
916
- child.parent.equal?(parent) # true
911
+ * Add flag to disable schema dump after migration.
917
912
 
918
- *Michal Cichra*
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.
919
916
 
920
- * `has_many` using `:through` now obeys the order clause mentioned in
921
- through association.
922
- Fixes #10016.
917
+ *Emil Soman*
923
918
 
924
- *Neeraj Singh*
919
+ * `find_in_batches`, `find_each`, `Result#each` and `Enumerable#index_by` now
920
+ return an `Enumerator` that can calculate its size.
925
921
 
926
- * `belongs_to :touch` behavior now touches old association when
927
- transitioning to new association.
922
+ See also #13938.
928
923
 
929
- class Passenger < ActiveRecord::Base
930
- belongs_to :car, touch: true
931
- end
924
+ *Marc-André Lafortune*
932
925
 
933
- car_1 = Car.create
934
- car_2 = Car.create
926
+ * Make sure transaction state gets reset after a commit operation on the record.
935
927
 
936
- passenger = Passenger.create car: car_1
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.
937
930
 
938
- passenger.car = car_2
939
- passenger.save
931
+ Fixes #12566.
940
932
 
941
- Previously only car_2 would be touched. Now both car_1 and car_2
942
- will be touched.
933
+ *arthurnn*
943
934
 
944
- *Adam Gamble*
935
+ * Pass `has_and_belongs_to_many` `:autosave` option to
936
+ the underlying `has_many :through` association.
945
937
 
946
- * Extract and deprecate Firebird / Sqlserver / Oracle database tasks, because
947
- These tasks should be supported by 3rd-party adapter.
938
+ Fixes #13923.
948
939
 
949
- *kennyj*
940
+ *Yves Senn*
950
941
 
951
- * Allow `ActiveRecord::Base.connection_handler` to have thread affinity and be
952
- settable, this effectively allows Active Record to be used in a multithreaded
953
- setup with multiple connections to multiple databases.
942
+ * PostgreSQL implementation of `SchemaStatements#index_name_exists?`.
954
943
 
955
- *Sam Saffron*
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.
956
947
 
957
- * `rename_column` preserves `auto_increment` in MySQL migrations.
958
- Fixes #3493.
948
+ Fixes #11018.
959
949
 
960
- *Vipul A M*
950
+ *Jonathan Baudanza*
961
951
 
962
- * PostgreSQL geometric type point is now supported by Active Record. Fixes #7324.
952
+ * Parsing PostgreSQL arrays with empty strings now works correctly.
963
953
 
964
- *Martin Schuerrer*
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.
965
958
 
966
- * Add support for concurrent indexing in PostgreSQL adapter via the
967
- `algorithm: :concurrently` option.
959
+ Fixes #13907.
968
960
 
969
- add_index(:people, :last_name, algorithm: :concurrently)
961
+ *Maurício Linhares*
970
962
 
971
- Also add support for MySQL index algorithms (`COPY`, `INPLACE`,
972
- `DEFAULT`) via the `:algorithm` option.
963
+ * Associations now raise `ArgumentError` on name conflicts.
973
964
 
974
- add_index(:people, :last_name, algorithm: :copy) # or :inplace/:default
965
+ Dangerous association names conflicts include instance or class methods already
966
+ defined by `ActiveRecord::Base`.
975
967
 
976
- *Dan McClain*
968
+ Example:
977
969
 
978
- * Add support for fulltext and spatial indexes on MySQL tables with MyISAM database
979
- engine via the `type: 'FULLTEXT'` / `type: 'SPATIAL'` option.
970
+ class Car < ActiveRecord::Base
971
+ has_many :errors
972
+ end
973
+ # Will raise ArgumentError.
980
974
 
981
- add_index(:people, :last_name, type: 'FULLTEXT')
982
- add_index(:people, :last_name, type: 'SPATIAL')
975
+ Fixes #13217.
983
976
 
984
- *Ken Mazaika*
977
+ *Lauro Caetano*
985
978
 
986
- * Add an `add_index` override in PostgreSQL adapter and MySQL adapter
987
- to allow custom index type support.
988
- Fixes #6101.
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.
989
983
 
990
- add_index(:wikis, :body, :using => 'gin')
984
+ Fixes #7538, #12017, #13731, #12056.
991
985
 
992
- *Stefan Huber* and *Doabit*
986
+ *arthurnn*
993
987
 
994
- * After extraction of mass-assignment attributes (which protects [id, type]
995
- by default) we can pass id to `update_attributes` and it will update
996
- another record because id will be used in where statement. We never have
997
- to change id in where statement because we try to set/replace fields for
998
- already loaded record but we have to try to set new id for that record.
988
+ * Active Record objects can now be correctly dumped, loaded and dumped again
989
+ without issues.
999
990
 
1000
- *Dmitry Vorotilin*
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.
1001
996
 
1002
- * Models with multiple counter cache associations now update correctly on destroy.
1003
- See #7706.
997
+ Fixes #13861.
1004
998
 
1005
- *Ian Young*
999
+ *Maurício Linhares*
1006
1000
 
1007
- * If `:inverse_of` is true on an association, then when one calls `find()` on
1008
- the association, Active Record will first look through the in-memory objects
1009
- in the association for a particular id. Then, it will go to the DB if it
1010
- is not found. This is accomplished by calling `find_by_scan` in
1011
- collection associations whenever `options[:inverse_of]` is not nil.
1012
- Fixes #9470.
1001
+ * `find_in_batches` now returns an `Enumerator` when called without a block, so that it
1002
+ can be chained with other `Enumerable` methods.
1013
1003
 
1014
- *John Wang*
1004
+ *Marc-André Lafortune*
1015
1005
 
1016
- * `rake db:create` does not change permissions of the MySQL root user.
1017
- Fixes #8079.
1006
+ * `enum` now raises on "dangerous" name conflicts.
1018
1007
 
1019
- *Yves Senn*
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.
1020
1012
 
1021
- * The length of the `version` column in the `schema_migrations` table
1022
- created by the `mysql2` adapter is 191 if the encoding is "utf8mb4".
1013
+ Fixes #13389.
1023
1014
 
1024
- The "utf8" encoding in MySQL has support for a maximum of 3 bytes per character,
1025
- and only contains characters from the BMP. The recently added
1026
- [utf8mb4](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html)
1027
- encoding extends the support to four bytes. As of this writing, said encoding
1028
- is supported in the betas of the `mysql2` gem.
1015
+ *Godfrey Chan*
1029
1016
 
1030
- Setting the encoding to "utf8mb4" has
1031
- [a few implications](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-upgrading.html).
1032
- This change addresses the max length for indexes, which is 191 instead of 255.
1017
+ * `scope` now raises on "dangerous" name conflicts.
1033
1018
 
1034
- *Xavier Noria*
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.
1035
1022
 
1036
- * Counter caches on associations will now stay valid when attributes are
1037
- updated (not just when records are created or destroyed), for example,
1038
- when calling `update_attributes`. The following code now works:
1023
+ See also #13389.
1039
1024
 
1040
- class Comment < ActiveRecord::Base
1041
- belongs_to :post, counter_cache: true
1042
- end
1025
+ *Godfrey Chan*, *Philippe Creux*
1043
1026
 
1044
- class Post < ActiveRecord::Base
1045
- has_many :comments
1046
- end
1027
+ * Correctly send an user provided statement to a `lock!()` call.
1047
1028
 
1048
- post = Post.create
1049
- comment = Comment.create
1029
+ person.lock! 'FOR SHARE NOWAIT'
1030
+ # Before: SELECT * ... LIMIT 1 FOR UPDATE
1031
+ # After: SELECT * ... LIMIT 1 FOR SHARE NOWAIT
1050
1032
 
1051
- post.comments << comment
1052
- post.save.reload.comments_count # => 1
1053
- comment.update_attributes(post_id: nil)
1033
+ Fixes #13788.
1054
1034
 
1055
- post.save.reload.comments_count # => 0
1035
+ *Maurício Linhares*
1056
1036
 
1057
- Updating the id of a `belongs_to` object with the id of a new object will
1058
- also keep the count accurate.
1037
+ * Handle aliased attributes `select()`, `order()` and `reorder()`.
1059
1038
 
1060
- *John Wang*
1039
+ *Tsutomu Kuroda*
1061
1040
 
1062
- * Referencing join tables implicitly was deprecated. There is a
1063
- possibility that these deprecation warnings are shown even if you
1064
- don't make use of that feature. You can now disable the feature entirely.
1065
- Fixes #9712.
1041
+ * Reset the collection association when calling `reset` on it.
1066
1042
 
1067
- Example:
1043
+ Before:
1068
1044
 
1069
- # in your configuration
1070
- config.active_record.disable_implicit_join_references = true
1045
+ post.comments.loaded? # => true
1046
+ post.comments.reset
1047
+ post.comments.loaded? # => true
1071
1048
 
1072
- # or directly
1073
- ActiveRecord::Base.disable_implicit_join_references = true
1049
+ After:
1074
1050
 
1075
- *Yves Senn*
1051
+ post.comments.loaded? # => true
1052
+ post.comments.reset
1053
+ post.comments.loaded? # => false
1076
1054
 
1077
- * The `:distinct` option for `Relation#count` is deprecated. You
1078
- should use `Relation#distinct` instead.
1055
+ Fixes #13777.
1079
1056
 
1080
- Example:
1057
+ *Kelsey Schlarman*
1081
1058
 
1082
- # Before
1083
- Post.select(:author_name).count(distinct: true)
1059
+ * Make enum fields work as expected with the `ActiveModel::Dirty` API.
1084
1060
 
1085
- # After
1086
- Post.select(:author_name).distinct.count
1061
+ Before this change, using the dirty API would have surprising results:
1087
1062
 
1088
- *Yves Senn*
1063
+ conversation = Conversation.new
1064
+ conversation.status = :active
1065
+ conversation.status = :archived
1066
+ conversation.status_was # => 0
1089
1067
 
1090
- * Rename `Relation#uniq` to `Relation#distinct`. `#uniq` is still
1091
- available as an alias but we encourage to use `#distinct` instead.
1092
- Also `Relation#uniq_value` is aliased to `Relation#distinct_value`,
1093
- this is a temporary solution and you should migrate to `distinct_value`.
1068
+ After this change, the same code would result in:
1094
1069
 
1095
- *Yves Senn*
1070
+ conversation = Conversation.new
1071
+ conversation.status = :active
1072
+ conversation.status = :archived
1073
+ conversation.status_was # => "active"
1096
1074
 
1097
- * Fix quoting for sqlite migrations using `copy_table_contents` with binary
1098
- columns.
1075
+ *Rafael Mendonça França*
1099
1076
 
1100
- These would fail with "SQLite3::SQLException: unrecognized token" because
1101
- the column was not being passed to `quote` so the data was not quoted
1102
- correctly.
1077
+ * `has_one` and `belongs_to` accessors don't add ORDER BY to the queries
1078
+ anymore.
1103
1079
 
1104
- *Matthew M. Boedicker*
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.
1105
1085
 
1106
- * Promotes `change_column_null` to the migrations API. This macro sets/removes
1107
- `NOT NULL` constraints, and accepts an optional argument to replace existing
1108
- `NULL`s if needed. The adapters for SQLite, MySQL, PostgreSQL, and (at least)
1109
- Oracle, already implement this method.
1086
+ Fixes #12623.
1110
1087
 
1111
- *Xavier Noria*
1088
+ *Rafael Mendonça França*
1112
1089
 
1113
- * Uniqueness validation allows you to pass `:conditions` to limit
1114
- the constraint lookup.
1090
+ * Prepend table name for column names passed to `Relation#select`.
1115
1091
 
1116
1092
  Example:
1117
1093
 
1118
- validates_uniqueness_of :title, conditions: -> { where('approved = ?', true) }
1094
+ Post.select(:id)
1095
+ # Before: => SELECT id FROM "posts"
1096
+ # After: => SELECT "posts"."id" FROM "posts"
1119
1097
 
1120
- *Mattias Pfeiffer + Yves Senn*
1098
+ *Yves Senn*
1121
1099
 
1122
- * `connection` is deprecated as an instance method.
1123
- This allows end-users to have a `connection` method on their models
1124
- without clashing with Active Record internals.
1100
+ * Fail early with "Primary key not included in the custom select clause"
1101
+ in `find_in_batches`.
1125
1102
 
1126
- *Ben Moss*
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.
1127
1106
 
1128
- * When copying migrations, preserve their magic comments and content encoding.
1107
+ *Alexander Balashov*
1129
1108
 
1130
- *OZAWA Sakuro*
1109
+ * Ensure `second` through `fifth` methods act like the `first` finder.
1131
1110
 
1132
- * Fix `subclass_from_attrs` when `eager_load` is false. It cannot find
1133
- subclass because all classes are loaded automatically when it needs.
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.
1134
1115
 
1135
- *Dmitry Vorotilin*
1116
+ Fixes #13743.
1136
1117
 
1137
- * When `:name` option is provided to `remove_index`, use it if there is no
1138
- index by the conventional name.
1118
+ Example:
1139
1119
 
1140
- For example, previously if an index was removed like so
1141
- `remove_index :values, column: :value, name: 'a_different_name'`
1142
- the generated SQL would not contain the specified index name,
1143
- and hence the migration would fail.
1144
- Fixes #8858.
1120
+ User.all.second
1145
1121
 
1146
- *Ezekiel Smithburg*
1122
+ # Before
1123
+ # => 'SELECT "users".* FROM "users"'
1147
1124
 
1148
- * Created block to by-pass the prepared statement bindings.
1149
- This will allow to compose fragments of large SQL statements to
1150
- avoid multiple round-trips between Ruby and the DB.
1125
+ # After
1126
+ # => SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 OFFSET 1'
1151
1127
 
1152
- Example:
1128
+ User.offset(3).second
1153
1129
 
1154
- sql = Post.connection.unprepared_statement do
1155
- Post.first.comments.to_sql
1156
- end
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
1157
1134
 
1158
- *Cédric Fabianski*
1135
+ # After
1136
+ # => SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 OFFSET 4'
1159
1137
 
1160
- * Change the semantics of combining scopes to be the same as combining
1161
- class methods which return scopes. For example:
1138
+ *Jason Meller*
1162
1139
 
1163
- class User < ActiveRecord::Base
1164
- scope :active, -> { where state: 'active' }
1165
- scope :inactive, -> { where state: 'inactive' }
1166
- end
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`).
1167
1143
 
1168
- class Post < ActiveRecord::Base
1169
- def self.active
1170
- where state: 'active'
1171
- end
1144
+ Fixes #13744.
1172
1145
 
1173
- def self.inactive
1174
- where state: 'inactive'
1175
- end
1176
- end
1146
+ *Godfrey Chan*
1147
+
1148
+ * Make `touch` fire the `after_commit` and `after_rollback` callbacks.
1177
1149
 
1178
- ### BEFORE ###
1150
+ *Harry Brundage*
1179
1151
 
1180
- User.where(state: 'active').where(state: 'inactive')
1181
- # => SELECT * FROM users WHERE state = 'active' AND state = 'inactive'
1152
+ * Enable partial indexes for `sqlite >= 3.8.0`.
1182
1153
 
1183
- User.active.inactive
1184
- # => SELECT * FROM users WHERE state = 'inactive'
1154
+ See http://www.sqlite.org/partialindex.html
1185
1155
 
1186
- Post.active.inactive
1187
- # => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
1156
+ *Cody Cutrer*
1188
1157
 
1189
- ### AFTER ###
1158
+ * Don't try to get the subclass if the inheritance column doesn't exist
1190
1159
 
1191
- User.active.inactive
1192
- # => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
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.
1193
1164
 
1194
- Before this change, invoking a scope would merge it into the current
1195
- scope and return the result. `Relation#merge` applies "last where
1196
- wins" logic to de-duplicate the conditions, but this lead to
1197
- confusing and inconsistent behaviour. This fixes that.
1165
+ *Ujjwal Thaakar*
1198
1166
 
1199
- If you really do want the "last where wins" logic, you can opt-in to
1200
- it like so:
1167
+ * Enum mappings are now exposed via class methods instead of constants.
1201
1168
 
1202
- User.active.merge(User.inactive)
1169
+ Example:
1203
1170
 
1204
- Fixes #7365.
1171
+ class Conversation < ActiveRecord::Base
1172
+ enum status: [ :active, :archived ]
1173
+ end
1205
1174
 
1206
- *Neeraj Singh* and *Jon Leighton*
1175
+ Before:
1207
1176
 
1208
- * Expand `#cache_key` to consult all relevant updated timestamps.
1177
+ Conversation::STATUS # => { "active" => 0, "archived" => 1 }
1209
1178
 
1210
- Previously only `updated_at` column was checked, now it will
1211
- consult other columns that received updated timestamps on save,
1212
- such as `updated_on`. When multiple columns are present it will
1213
- use the most recent timestamp.
1214
- Fixes #9033.
1179
+ After:
1215
1180
 
1216
- *Brendon Murphy*
1181
+ Conversation.statuses # => { "active" => 0, "archived" => 1 }
1217
1182
 
1218
- * Throw `NotImplementedError` when trying to instantiate `ActiveRecord::Base` or an abstract class.
1183
+ *Godfrey Chan*
1219
1184
 
1220
- *Aaron Weiner*
1185
+ * Set `NameError#name` when STI-class-lookup fails.
1221
1186
 
1222
- * Warn when `rake db:structure:dump` with a MySQL database and
1223
- `mysqldump` is not in the PATH or fails.
1224
- Fixes #9518.
1187
+ *Chulki Lee*
1225
1188
 
1226
- *Yves Senn*
1189
+ * Fix bug in `becomes!` when changing from the base model to a STI sub-class.
1227
1190
 
1228
- * Remove `connection#structure_dump`, which is no longer used. *Yves Senn*
1191
+ Fixes #13272.
1229
1192
 
1230
- * Make it possible to execute migrations without a transaction even
1231
- if the database adapter supports DDL transactions.
1232
- Fixes #9483.
1193
+ *the-web-dev*, *Yves Senn*
1233
1194
 
1234
- Example:
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`.
1235
1253
 
1236
- class ChangeEnum < ActiveRecord::Migration
1237
- disable_ddl_transaction!
1254
+ *Richard Schneeman*
1238
1255
 
1239
- def up
1240
- execute "ALTER TYPE model_size ADD VALUE 'new_value'"
1241
- end
1242
- end
1256
+ * Make `change_column_null` revertable. Fixes #13576.
1243
1257
 
1244
- *Yves Senn*
1258
+ *Yves Senn*, *Nishant Modak*, *Prathamesh Sonpatki*
1245
1259
 
1246
- * Assigning "0.0" to a nullable numeric column does not make it dirty.
1247
- Fixes #9034.
1260
+ * Don't create/drop the test database if RAILS_ENV is specified explicitly.
1248
1261
 
1249
- Example:
1262
+ Previously, when the environment was development, we would always
1263
+ create or drop both the test and development databases.
1250
1264
 
1251
- product = Product.create price: 0.0
1252
- product.price = '0.0'
1253
- product.changed? # => false (this used to return true)
1254
- product.changes # => {} (this used to return { price: [0.0, 0.0] })
1265
+ Now, if RAILS_ENV is explicitly defined as development, we don't create
1266
+ the test database.
1255
1267
 
1256
- *Yves Senn*
1268
+ *Damien Mathieu*
1257
1269
 
1258
- * Added functionality to unscope relations in a relations chain. For
1259
- instance, if you are passed in a chain of relations as follows:
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.
1260
1272
 
1261
- User.where(name: "John").order('id DESC')
1273
+ *Dylan Thacker-Smith*
1262
1274
 
1263
- but you want to get rid of order, then this feature allows you to do:
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.
1264
1279
 
1265
- User.where(name: "John").order('id DESC').unscope(:order)
1266
- == User.where(name: "John")
1280
+ Fixes #13577, #13503.
1267
1281
 
1268
- The .unscope() function is more general than the .except() method because
1269
- .except() only works on the relation it is acting on. However, .unscope()
1270
- works for any relation in the entire relation chain.
1282
+ *Nishant Modak*, *Prathamesh Sonpatki*, *Rafael Mendonça França*
1271
1283
 
1272
- *John Wang*
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.
1273
1286
 
1274
- * PostgreSQL timestamp with time zone (timestamptz) datatype now returns a
1275
- ActiveSupport::TimeWithZone instance instead of a string
1287
+ Fixes #13570.
1276
1288
 
1277
- *Troy Kruthoff*
1289
+ *Thales Oliveira*
1278
1290
 
1279
- * The `#append` method for collection associations behaves like`<<`.
1280
- `#prepend` is not defined and `<<` or `#append` should be used.
1281
- Fixes #7364.
1291
+ * Deprecate unused `ActiveRecord::Base.symbolized_base_class`
1292
+ and `ActiveRecord::Base.symbolized_sti_name` without replacement.
1282
1293
 
1283
1294
  *Yves Senn*
1284
1295
 
1285
- * Added support for creating a table via Rails migration generator.
1286
- For example,
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:
1287
1300
 
1288
- rails g migration create_books title:string content:text
1301
+ rake db:schema:load RAILS_ENV=test
1289
1302
 
1290
- will generate a migration that creates a table called books with
1291
- the listed attributes, without creating a model.
1292
-
1293
- *Sammy Larbi*
1303
+ *Jon Leighton*
1294
1304
 
1295
- * Fix bug that raises the wrong exception when the exception handled by PostgreSQL adapter
1296
- doesn't respond to `#result`.
1297
- Fixes #8617.
1305
+ * Fix presence validator for association when the associated record responds to `to_a`.
1298
1306
 
1299
- *kennyj*
1307
+ *gmarik*
1300
1308
 
1301
- * Support PostgreSQL specific column types when using `change_table`.
1302
- Fixes #9480.
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`.
1303
1311
 
1304
- Example:
1312
+ Fixes #13437.
1305
1313
 
1306
- change_table :authors do |t|
1307
- t.hstore :books
1308
- t.json :metadata
1309
- end
1314
+ *Vipul A M*, *khustochka*
1310
1315
 
1311
- *Yves Senn*
1316
+ * Add the ability to nullify the `enum` column.
1312
1317
 
1313
- * Revert 408227d9c5ed7d, 'quote numeric'. This introduced some regressions.
1318
+ Example:
1314
1319
 
1315
- *Steve Klabnik*
1320
+ class Conversation < ActiveRecord::Base
1321
+ enum gender: [:female, :male]
1322
+ end
1316
1323
 
1317
- * Fix calculation of `db_runtime` property in
1318
- `ActiveRecord::Railties::ControllerRuntime#cleanup_view_runtime`.
1319
- Previously, after raising `ActionView::MissingTemplate`, `db_runtime` was
1320
- not populated.
1321
- Fixes #9215.
1324
+ Conversation::GENDER # => { female: 0, male: 1 }
1322
1325
 
1323
- *Igor Fedoronchuk*
1326
+ # conversation.update! gender: 0
1327
+ conversation.female!
1328
+ conversation.female? # => true
1329
+ conversation.gender # => "female"
1324
1330
 
1325
- * Do not try to touch invalid (and thus not persisted) parent record
1326
- for a `belongs_to :parent, touch: true` association
1331
+ # conversation.update! gender: nil
1332
+ conversation.gender = nil
1333
+ conversation.gender.nil? # => true
1334
+ conversation.gender # => nil
1327
1335
 
1328
- *Olek Janiszewski*
1336
+ *Amr Tamimi*
1329
1337
 
1330
- * Fix when performing an ordered join query. The bug only
1331
- affected queries where the order was given with a symbol.
1332
- Fixes #9275.
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.
1333
1341
 
1334
- Example:
1342
+ *Richard Schneeman*
1335
1343
 
1336
- # This will expand the order :name to "authors".name.
1337
- Author.joins(:books).where('books.published = 1').order(:name)
1344
+ * An `ArgumentError` is now raised on a call to `Relation#where.not(nil)`.
1338
1345
 
1339
- * Fix overriding of attributes by `default_scope` on `ActiveRecord::Base#dup`.
1346
+ Example:
1340
1347
 
1341
- *Hiroshige UMINO*
1348
+ User.where.not(nil)
1342
1349
 
1343
- * Update queries now use prepared statements.
1350
+ # Before
1351
+ # => 'SELECT `users`.* FROM `users` WHERE (NOT (NULL))'
1344
1352
 
1345
- *Olli Rissanen*
1353
+ # After
1354
+ # => ArgumentError, 'Invalid argument for .where.not(), got nil.'
1346
1355
 
1347
- * Fixing issue #8345. Now throwing an error when one attempts to touch a
1348
- new object that has not yet been persisted. For instance:
1356
+ *Kuldeep Aggarwal*
1349
1357
 
1350
- Example:
1358
+ * Deprecated use of string argument as a configuration lookup in
1359
+ `ActiveRecord::Base.establish_connection`. Instead, a symbol must be given.
1351
1360
 
1352
- ball = Ball.new
1353
- ball.touch :updated_at # => raises error
1361
+ *José Valim*
1354
1362
 
1355
- It is not until the ball object has been persisted that it can be touched.
1356
- This follows the behavior of update_column.
1363
+ * Fixed `update_column`, `update_columns`, and `update_all` to correctly serialize
1364
+ values for `array`, `hstore` and `json` column types in PostgreSQL.
1357
1365
 
1358
- *John Wang*
1366
+ Fixes #12261.
1359
1367
 
1360
- * Preloading ordered `has_many :through` associations no longer applies
1361
- invalid ordering to the `:through` association.
1362
- Fixes #8663.
1368
+ *Tadas Tamosauskas*, *Carlos Antonio da Silva*
1363
1369
 
1364
- *Yves Senn*
1370
+ * Do not consider PostgreSQL array columns as number or text columns.
1365
1371
 
1366
- * The auto explain feature has been removed. This feature was
1367
- activated by configuring `config.active_record.auto_explain_threshold_in_seconds`.
1368
- The configuration option was deprecated and has no more effect.
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:
1369
1375
 
1370
- You can still use `ActiveRecord::Relation#explain` to see the EXPLAIN output for
1371
- any given relation.
1376
+ if column.number?
1377
+ !value.zero?
1378
+ end
1372
1379
 
1373
- *Yves Senn*
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.
1374
1382
 
1375
- * The `:on` option for `after_commit` and `after_rollback` now
1376
- accepts an Array of actions.
1377
- Fixes #988.
1383
+ Fixing this by ensuring that array columns in PostgreSQL never return
1384
+ true for number?/text? checks.
1378
1385
 
1379
- Example:
1386
+ *Carlos Antonio da Silva*
1380
1387
 
1381
- after_commit :update_cache on: [:create, :update]
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
1382
1392
 
1383
- *Yves Senn*
1393
+ *Richard Schneeman*
1384
1394
 
1385
- * Rename related indexes on `rename_table` and `rename_column`. This
1386
- does not affect indexes with custom names.
1395
+ * Do not raise `'cannot touch on a new record object'` exception on destroying
1396
+ already destroyed `belongs_to` association with `touch: true` option.
1387
1397
 
1388
- *Yves Senn*
1398
+ Fixes #13445.
1389
1399
 
1390
- * Prevent the creation of indices with too long names, which cause
1391
- internal operations to fail (sqlite3 adapter only). The method
1392
- `allowed_index_name_length` defines the length limit enforced by
1393
- rails. It's value defaults to `index_name_length` but can vary per adapter.
1394
- Fixes #8264.
1400
+ Example:
1395
1401
 
1396
- *Yves Senn*
1402
+ # Given Comment has belongs_to :post, touch: true
1403
+ comment.post.destroy
1404
+ comment.destroy # no longer raises an error
1397
1405
 
1398
- * Fixing issue #776.
1406
+ *Paul Nikitochkin*
1399
1407
 
1400
- Memory bloat in transactions is handled by having the transaction hold only
1401
- the AR objects which it absolutely needs to know about. These are the AR
1402
- objects with callbacks (they need to be updated as soon as something in the
1403
- transaction occurs).
1408
+ * Fix a bug when assigning an array containing string numbers to a
1409
+ PostgreSQL integer array column.
1404
1410
 
1405
- All other AR objects can be updated lazily by keeping a reference to a
1406
- TransactionState object. If an AR object gets inside a transaction, then
1407
- the transaction will add its TransactionState to the AR object. When the
1408
- user makes a call to some attribute on an AR object (which has no
1409
- callbacks) associated with a transaction, the AR object will call the
1410
- sync_with_transaction_state method and make sure it is up to date with the
1411
- transaction. After it has synced with the transaction state, the AR object
1412
- will return the attribute that was requested.
1411
+ Fixes #13444.
1413
1412
 
1414
- Most of the logic in the changes are used to handle multiple transactions,
1415
- in which case the AR object has to recursively follow parent pointers of
1416
- TransactionState objects.
1413
+ Example:
1417
1414
 
1418
- *John Wang*
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
1419
1418
 
1420
- * Descriptive error message when the necessary AR adapter gem was not found.
1421
- Fixes #7313.
1419
+ *Damien Mathieu*
1422
1420
 
1423
- *Yves Senn*
1421
+ * Fix `PostgreSQL` insert to properly extract table name from multiline string SQL.
1424
1422
 
1425
- * Active Record now raises an error when blank arguments are passed to query
1426
- methods for which blank arguments do not make sense.
1423
+ Previously, executing an insert SQL in `PostgreSQL` with a command like this:
1427
1424
 
1428
- Example:
1425
+ insert into articles(
1426
+ number)
1427
+ values(
1428
+ 5152
1429
+ )
1429
1430
 
1430
- Post.includes() # => raises error
1431
+ would not work because the adapter was unable to extract the correct `articles`
1432
+ table name.
1431
1433
 
1432
- *John Wang*
1434
+ *Kuldeep Aggarwal*
1433
1435
 
1434
- * Simplified type casting code for timezone aware attributes to use the
1435
- `in_time_zone` method if it is available. This introduces a subtle change
1436
- of behavior when using `Date` instances as they are directly converted to
1437
- `ActiveSupport::TimeWithZone` instances without first being converted to
1438
- `Time` instances. For example:
1436
+ * Correctly escape PostgreSQL arrays.
1439
1437
 
1440
- # Rails 3.2 behavior
1441
- >> Date.today.to_time.in_time_zone
1442
- => Wed, 13 Feb 2013 07:00:00 UTC +00:00
1438
+ Fixes: CVE-2014-0080
1443
1439
 
1444
- # Rails 4.0 behavior
1445
- >> Date.today.in_time_zone
1446
- => Wed, 13 Feb 2013 00:00:00 UTC +00:00
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.
1447
1442
 
1448
- On the plus side it now behaves the same whether you pass a `String` date
1449
- or an actual `Date` instance. For example:
1443
+ It intends to prevent odd bugs and confusion in code that call mutator
1444
+ methods directly on the `Relation`.
1450
1445
 
1451
- # Rails 3.2 behavior
1452
- >> Date.civil(2013, 2, 13).to_time.in_time_zone
1453
- => Wed, 13 Feb 2013 07:00:00 UTC +00:00
1454
- >> Time.zone.parse("2013-02-13")
1455
- => Wed, 13 Feb 2013 00:00:00 UTC +00:00
1446
+ Example:
1456
1447
 
1457
- # Rails 4.0 behavior
1458
- >> Date.civil(2013, 2, 13).in_time_zone
1459
- => Wed, 13 Feb 2013 00:00:00 UTC +00:00
1460
- >> "2013-02-13".in_time_zone
1461
- => Wed, 13 Feb 2013 00:00:00 UTC +00:00
1448
+ # Instead of this
1449
+ Author.where(name: 'Hank Moody').compact!
1462
1450
 
1463
- If you need the old behavior you can convert the dates to times manually.
1464
- For example:
1451
+ # Now you have to do this
1452
+ authors = Author.where(name: 'Hank Moody').to_a
1453
+ authors.compact!
1465
1454
 
1466
- >> Post.new(created_at: Date.today).created_at
1467
- => Wed, 13 Feb 2013 00:00:00 UTC +00:00
1455
+ *Lauro Caetano*
1468
1456
 
1469
- >> Post.new(created_at: Date.today.to_time).created_at
1470
- => Wed, 13 Feb 2013 07:00:00 UTC +00:00
1457
+ * Better support for `where()` conditions that use a `belongs_to`
1458
+ association name.
1471
1459
 
1472
- *Andrew White*
1460
+ Using the name of an association in `where` previously worked only
1461
+ if the value was a single `ActiveRecord::Base` object. e.g.
1473
1462
 
1474
- * Preloading `has_many :through` associations with conditions won't
1475
- cache the `:through` association. This will prevent invalid
1476
- subsets to be cached.
1477
- Fixes #8423.
1463
+ Post.where(author: Author.first)
1478
1464
 
1479
- Example:
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.
1480
1470
 
1481
- class User
1482
- has_many :posts
1483
- has_many :recent_comments, -> { where('created_at > ?', 1.week.ago) }, :through => :posts
1471
+ class Post < ActiveRecord::Base
1472
+ belongs_to :author
1484
1473
  end
1485
1474
 
1486
- a_user = User.includes(:recent_comments).first
1487
-
1488
- # This is preloaded.
1489
- a_user.recent_comments
1475
+ `nil` value finds records where the association is not set:
1490
1476
 
1491
- # This is not preloaded, fetched now.
1492
- a_user.posts
1477
+ Post.where(author: nil)
1478
+ # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL
1493
1479
 
1494
- *Yves Senn*
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])`:
1495
1483
 
1496
- * Don't run `after_commit` callbacks when creating through an association
1497
- if saving the record fails.
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)
1498
1487
 
1499
- *James Miller*
1488
+ `ActiveRecord::Relation` values find records using the same
1489
+ query as `Post.where(author_id: Author.where(last_name: "Emde"))`
1500
1490
 
1501
- * Allow store accessors to be overridden like other attribute methods, e.g.:
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')
1502
1496
 
1503
- class User < ActiveRecord::Base
1504
- store :settings, accessors: [ :color, :homepage ], coder: JSON
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`.
1505
1501
 
1506
- def color
1507
- super || 'red'
1508
- end
1502
+ class Post < ActiveRecord::Base
1503
+ belongs_to :author, polymorphic: true
1509
1504
  end
1510
1505
 
1511
- *Sergey Nartimov*
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")
1512
1509
 
1513
- * Quote numeric values being compared to non-numeric columns. Otherwise,
1514
- in some database, the string column values will be coerced to a numeric
1515
- allowing 0, 0.0 or false to match any string starting with a non-digit.
1510
+ *Martin Emde*
1516
1511
 
1517
- Example:
1518
-
1519
- App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
1520
-
1521
- *Dylan Smith*
1522
-
1523
- * Schema dumper supports dumping the enabled database extensions to `schema.rb`
1524
- (currently only supported by PostgreSQL).
1512
+ * Respect temporary option when dropping tables with MySQL.
1525
1513
 
1526
- *Justin George*
1514
+ Normal DROP TABLE also works, but commits the transaction.
1527
1515
 
1528
- * The database adapters now converts the options passed thought `DATABASE_URL`
1529
- environment variable to the proper Ruby types before using. For example, SQLite requires
1530
- that the timeout value is an integer, and PostgreSQL requires that the
1531
- prepared_statements option is a boolean. These now work as expected:
1516
+ drop_table :temporary_table, temporary: true
1532
1517
 
1533
- Example:
1518
+ *Cody Cutrer*
1534
1519
 
1535
- DATABASE_URL=sqlite3://localhost/test_db?timeout=500
1536
- DATABASE_URL=postgresql://localhost/test_db?prepared_statements=false
1520
+ * Add option to create tables from a query.
1537
1521
 
1538
- *Aaron Stone + Rafael Mendonça França*
1522
+ create_table(:long_query, temporary: true,
1523
+ as: "SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id")
1539
1524
 
1540
- * `Relation#merge` now only overwrites where values on the LHS of the
1541
- merge. Consider:
1525
+ Generates:
1542
1526
 
1543
- left = Person.where(age: [13, 14, 15])
1544
- right = Person.where(age: [13, 14]).where(age: [14, 15])
1527
+ CREATE TEMPORARY TABLE long_query AS
1528
+ SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id
1545
1529
 
1546
- `left` results in the following SQL:
1530
+ *Cody Cutrer*
1547
1531
 
1548
- WHERE age IN (13, 14, 15)
1532
+ * `db:test:clone` and `db:test:prepare` must load Rails environment.
1549
1533
 
1550
- `right` results in the following SQL:
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.
1551
1536
 
1552
- WHERE age IN (13, 14) AND age IN (14, 15)
1537
+ *arthurnn*
1553
1538
 
1554
- Previously, `left.merge(right)` would result in all but the last
1555
- condition being removed:
1539
+ * Use the right column to type cast grouped calculations with custom expressions.
1556
1540
 
1557
- WHERE age IN (14, 15)
1541
+ Fixes #13230.
1558
1542
 
1559
- Now it results in the LHS condition(s) for `age` being removed, but
1560
- the RHS remains as it is:
1543
+ Example:
1561
1544
 
1562
- WHERE age IN (13, 14) AND age IN (14, 15)
1545
+ # Before
1546
+ Account.group(:firm_name).sum('0.01 * credit_limit')
1547
+ # => { '37signals' => '0.5' }
1563
1548
 
1564
- *Jon Leighton*
1549
+ # After
1550
+ Account.group(:firm_name).sum('0.01 * credit_limit')
1551
+ # => { '37signals' => 0.5 }
1565
1552
 
1566
- * Fix handling of dirty time zone aware attributes
1553
+ *Paul Nikitochkin*
1567
1554
 
1568
- Previously, when `time_zone_aware_attributes` were enabled, after
1569
- changing a datetime or timestamp attribute and then changing it back
1570
- to the original value, `changed_attributes` still tracked the
1571
- attribute as changed. This caused `[attribute]_changed?` and
1572
- `changed?` methods to return true incorrectly.
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.
1573
1557
 
1574
1558
  Example:
1575
1559
 
1576
- in_time_zone 'Paris' do
1577
- order = Order.new
1578
- original_time = Time.local(2012, 10, 10)
1579
- order.shipped_at = original_time
1580
- order.save
1581
- order.changed? # => false
1560
+ class Rating < ActiveRecord::Base
1561
+ belongs_to :rateable, polymorphic: true, touch: true
1562
+ end
1582
1563
 
1583
- # changing value
1584
- order.shipped_at = Time.local(2013, 1, 1)
1585
- order.changed? # => true
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
1586
1566
 
1587
- # reverting to original value
1588
- order.shipped_at = original_time
1589
- order.changed? # => false, used to return true
1590
- end
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.
1591
1571
 
1592
- *Lilibeth De La Cruz*
1572
+ *John Bachir*
1593
1573
 
1594
- * When `#count` is used in conjunction with `#uniq` we perform `count(:distinct => true)`.
1595
- Fixes #6865.
1574
+ * Fix `last` with `offset` to return the proper record instead of always the last one.
1596
1575
 
1597
1576
  Example:
1598
1577
 
1599
- relation.uniq.count # => SELECT COUNT(DISTINCT *)
1578
+ Model.offset(4).last
1579
+ # => returns the 4th record from the end.
1600
1580
 
1601
- *Yves Senn + Kaspar Schiess*
1581
+ Fixes #7441.
1602
1582
 
1603
- * PostgreSQL ranges type support. Includes: int4range, int8range,
1604
- numrange, tsrange, tstzrange, daterange
1583
+ *kostya*, *Lauro Caetano*
1605
1584
 
1606
- Ranges can be created with inclusive and exclusive bounds.
1585
+ * `type_to_sql` returns a `String` for unmapped columns. This fixes an error
1586
+ when using unmapped PostgreSQL array types.
1607
1587
 
1608
1588
  Example:
1609
1589
 
1610
- create_table :Room do |t|
1611
- t.daterange :availability
1612
- end
1590
+ change_colum :table, :column, :bigint, array: true
1591
+
1592
+ Fixes #13146.
1613
1593
 
1614
- Room.create(availability: (Date.today..Float::INFINITY))
1615
- Room.first.availability # => Wed, 19 Sep 2012..Infinity
1594
+ *Jens Fahnenbruck*, *Yves Senn*
1616
1595
 
1617
- One thing to note: Range class does not support exclusive lower
1618
- bound.
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.
1619
1598
 
1620
- *Alexander Grebennik*
1599
+ *Vipul A M*
1621
1600
 
1622
- * Added a state instance variable to each transaction. Will allow other objects
1623
- to know whether a transaction has been committed or rolled back.
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`.
1624
1604
 
1625
- *John Wang*
1605
+ *Victor Costan*
1626
1606
 
1627
- * Collection associations `#empty?` always respects built records.
1628
- Fixes #8879.
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`.
1629
1610
 
1630
- Example:
1611
+ *Godfrey Chan*
1631
1612
 
1632
- widget = Widget.new
1633
- widget.things.build
1634
- widget.things.empty? # => false
1613
+ * Implement `rename_index` natively for MySQL >= 5.7.
1635
1614
 
1636
- *Yves Senn*
1615
+ *Cody Cutrer*
1637
1616
 
1638
- * Support for PostgreSQL's `ltree` data type.
1617
+ * Fix bug when validating the uniqueness of an aliased attribute.
1639
1618
 
1640
- *Rob Worley*
1619
+ Fixes #12402.
1641
1620
 
1642
- * Fix undefined method `to_i` when calling `new` on a scope that uses an
1643
- Array; Fix FloatDomainError when setting integer column to NaN.
1644
- Fixes #8718, #8734, #8757.
1621
+ *Lauro Caetano*
1645
1622
 
1646
- *Jason Stirk + Tristan Harward*
1623
+ * Update counter cache on a `has_many` relationship regardless of default scope.
1647
1624
 
1648
- * Rename `update_attributes` to `update`, keep `update_attributes` as an alias for `update` method.
1649
- This is a soft-deprecation for `update_attributes`, although it will still work without any
1650
- deprecation message in 4.0 is recommended to start using `update` since `update_attributes` will be
1651
- deprecated and removed in future versions of Rails.
1625
+ Fixes #12952.
1652
1626
 
1653
- *Amparo Luna + Guillermo Iguaran*
1627
+ *Uku Taht*
1654
1628
 
1655
- * `after_commit` and `after_rollback` now validate the `:on` option and raise an `ArgumentError`
1656
- if it is not one of `:create`, `:destroy` or `:update`
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:
1657
1631
 
1658
- *Pascal Friederich*
1632
+ Cannot drop index 'index_engines_on_car_id': needed in a foreign key constraint
1659
1633
 
1660
- * Improve ways to write `change` migrations, making the old `up` & `down` methods no longer necessary.
1634
+ *Cody Cutrer*, *Yves Senn*
1661
1635
 
1662
- * The methods `drop_table` and `remove_column` are now reversible, as long as the necessary information is given.
1663
- The method `remove_column` used to accept multiple column names; instead use `remove_columns` (which is not reversible).
1664
- The method `change_table` is also reversible, as long as its block doesn't call `remove`, `change` or `change_default`
1636
+ * Raise `ActiveRecord::RecordNotDestroyed` when a replaced child
1637
+ marked with `dependent: destroy` fails to be destroyed.
1665
1638
 
1666
- * New method `reversible` makes it possible to specify code to be run when migrating up or down.
1667
- See the [Guide on Migration](https://github.com/rails/rails/blob/master/guides/source/migrations.md#using-the-reversible-method)
1639
+ Fixes #12812.
1668
1640
 
1669
- * New method `revert` will revert a whole migration or the given block.
1670
- If migrating down, the given migration / block is run normally.
1671
- See the [Guide on Migration](https://github.com/rails/rails/blob/master/guides/source/migrations.md#reverting-previous-migrations)
1641
+ *Brian Thomas Storti*
1672
1642
 
1673
- Attempting to revert the methods `execute`, `remove_columns` and `change_column` will now
1674
- raise an `IrreversibleMigration` instead of actually executing them without any output.
1643
+ * Fix validation on uniqueness of empty association.
1675
1644
 
1676
- *Marc-André Lafortune*
1645
+ *Evgeny Li*
1677
1646
 
1678
- * Serialized attributes can be serialized in integer columns.
1679
- Fixes #8575.
1647
+ * Make `ActiveRecord::Relation#unscope` affect relations it is merged in to.
1680
1648
 
1681
- *Rafael Mendonça França*
1649
+ *Jon Leighton*
1682
1650
 
1683
- * Keep index names when using `alter_table` with sqlite3.
1684
- Fixes #3489.
1651
+ * Use strings to represent non-string `order_values`.
1685
1652
 
1686
1653
  *Yves Senn*
1687
1654
 
1688
- * Add ability for PostgreSQL adapter to disable user triggers in `disable_referential_integrity`.
1689
- Fixes #5523.
1690
-
1691
- *Gary S. Weaver*
1655
+ * Checks to see if the record contains the foreign key to set the inverse automatically.
1692
1656
 
1693
- * Added support for `validates_uniqueness_of` in PostgreSQL array columns.
1694
- Fixes #8075.
1657
+ *Edo Balvers*
1695
1658
 
1696
- *Pedro Padron*
1659
+ * Added `ActiveRecord::Base.to_param` for convenient "pretty" URLs derived from a model's attribute or method.
1697
1660
 
1698
- * Allow int4range and int8range columns to be created in PostgreSQL and properly convert to/from database.
1661
+ Example:
1699
1662
 
1700
- *Alexey Vasiliev aka leopard*
1663
+ class User < ActiveRecord::Base
1664
+ to_param :name
1665
+ end
1701
1666
 
1702
- * Do not log the binding values for binary columns.
1667
+ user = User.find_by(name: 'Fancy Pants')
1668
+ user.id # => 123
1669
+ user.to_param # => "123-fancy-pants"
1703
1670
 
1704
- *Matthew M. Boedicker*
1671
+ *Javan Makhmali*
1705
1672
 
1706
- * Fix counter cache columns not updated when replacing `has_many :through`
1707
- associations.
1673
+ * Added `ActiveRecord::Base.no_touching`, which allows ignoring touch on models.
1708
1674
 
1709
- *Matthew Robertson*
1675
+ Example:
1710
1676
 
1711
- * Recognize migrations placed in directories containing numbers and 'rb'.
1712
- Fixes #8492.
1677
+ Post.no_touching do
1678
+ Post.first.touch
1679
+ end
1713
1680
 
1714
- *Yves Senn*
1681
+ *Sam Stephenson*, *Damien Mathieu*
1715
1682
 
1716
- * Add `ActiveRecord::Base.cache_timestamp_format` class attribute to control
1717
- the format of the timestamp value in the cache key. Defaults to `:nsec`.
1718
- Fixes #8195.
1683
+ * Prevent the counter cache from being decremented twice when destroying
1684
+ a record on a `has_many :through` association.
1719
1685
 
1720
- *Rafael Mendonça França*
1686
+ Fixes #11079.
1721
1687
 
1722
- * Session variables can be set for the `mysql`, `mysql2`, and `postgresql` adapters
1723
- in the `variables: <hash>` parameter in `config/database.yml`. The key-value pairs of this
1724
- hash will be sent in a `SET key = value` query on new database connections. See also:
1725
- http://dev.mysql.com/doc/refman/5.0/en/set-statement.html
1726
- http://www.postgresql.org/docs/8.3/static/sql-set.html
1688
+ *Dmitry Dedov*
1727
1689
 
1728
- *Aaron Stone*
1690
+ * Unify boolean type casting for `MysqlAdapter` and `Mysql2Adapter`.
1691
+ `type_cast` will return `1` for `true` and `0` for `false`.
1729
1692
 
1730
- * Allow setting of all libpq connection parameters through the PostgreSQL adapter. See also:
1731
- http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS
1693
+ Fixes #11119.
1732
1694
 
1733
- *Lars Kanis*
1695
+ *Adam Williams*, *Yves Senn*
1734
1696
 
1735
- * Allow `Relation#where` with no arguments to be chained with new `not` query method.
1697
+ * Fix bug where `has_one` association record update result in crash, when replaced with itself.
1736
1698
 
1737
- Example:
1699
+ Fixes #12834.
1738
1700
 
1739
- Developer.where.not(name: 'Aaron')
1701
+ *Denis Redozubov*, *Sergio Cambra*
1740
1702
 
1741
- *Akira Matsuda*
1703
+ * Log bind variables after they are type casted. This makes it more
1704
+ transparent what values are actually sent to the database.
1742
1705
 
1743
- * Unscope `update_column(s)` query to ignore default scope.
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]]
1744
1709
 
1745
- When applying `default_scope` to a class with a where clause, using
1746
- `update_column(s)` could generate a query that would not properly update
1747
- the record due to the where clause from the `default_scope` being applied
1748
- to the update query.
1710
+ *Yves Senn*
1749
1711
 
1750
- class User < ActiveRecord::Base
1751
- default_scope -> { where(active: true) }
1752
- end
1712
+ * Fix uninitialized constant `TransactionState` error when `Marshall.load` is used on an Active Record result.
1753
1713
 
1754
- user = User.first
1755
- user.active = false
1756
- user.save!
1714
+ Fixes #12790.
1757
1715
 
1758
- user.update_column(:active, true) # => false
1716
+ *Jason Ayre*
1759
1717
 
1760
- In this situation we want to skip the default_scope clause and just
1761
- update the record based on the primary key. With this change:
1718
+ * `.unscope` now removes conditions specified in `default_scope`.
1762
1719
 
1763
- user.update_column(:active, true) # => true
1720
+ *Jon Leighton*
1764
1721
 
1765
- Fixes #8436.
1722
+ * Added `ActiveRecord::QueryMethods#rewhere` which will overwrite an existing, named where condition.
1766
1723
 
1767
- *Carlos Antonio da Silva*
1724
+ Examples:
1768
1725
 
1769
- * SQLite adapter no longer corrupts binary data if the data contains `%00`.
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
1770
1729
 
1771
- *Chris Feist*
1730
+ *DHH*
1772
1731
 
1773
- * Fix performance problem with `primary_key` method in PostgreSQL adapter when having many schemas.
1774
- Uses `pg_constraint` table instead of `pg_depend` table which has many records in general.
1775
- Fixes #8414.
1732
+ * Extend `ActiveRecord::Base#cache_key` to take an optional list of timestamp attributes of which the highest will be used.
1776
1733
 
1777
- *kennyj*
1734
+ Example:
1778
1735
 
1779
- * Do not instantiate intermediate Active Record objects when eager loading.
1780
- These records caused `after_find` to run more than expected.
1781
- Fixes #3313.
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)
1782
1738
 
1783
- *Yves Senn*
1739
+ *DHH*
1784
1740
 
1785
- * Add STI support to init and building associations.
1786
- Allows you to do `BaseClass.new(type: "SubClass")` as well as
1787
- `parent.children.build(type: "SubClass")` or `parent.build_child`
1788
- to initialize an STI subclass. Ensures that the class name is a
1789
- valid class and that it is in the ancestors of the super class
1790
- that the association is expecting.
1741
+ * Added `ActiveRecord::Base#enum` for declaring enum attributes where the values map to integers in the database, but can be queried by name.
1791
1742
 
1792
- *Jason Rush*
1743
+ Example:
1793
1744
 
1794
- * Observers was extracted from Active Record as `rails-observers` gem.
1745
+ class Conversation < ActiveRecord::Base
1746
+ enum status: [:active, :archived]
1747
+ end
1795
1748
 
1796
- *Rafael Mendonça França*
1749
+ Conversation::STATUS # => { active: 0, archived: 1 }
1797
1750
 
1798
- * Ensure that associations take a symbol argument. *Steve Klabnik*
1751
+ # conversation.update! status: 0
1752
+ conversation.active!
1753
+ conversation.active? # => true
1754
+ conversation.status # => "active"
1799
1755
 
1800
- * Fix dirty attribute checks for `TimeZoneConversion` with nil and blank
1801
- datetime attributes. Setting a nil datetime to a blank string should not
1802
- result in a change being flagged.
1803
- Fixes #8310.
1756
+ # conversation.update! status: 1
1757
+ conversation.archived!
1758
+ conversation.archived? # => true
1759
+ conversation.status # => "archived"
1804
1760
 
1805
- *Alisdair McDiarmid*
1761
+ # conversation.update! status: 1
1762
+ conversation.status = :archived
1806
1763
 
1807
- * Prevent mass assignment to the type column of polymorphic associations when using `build`
1808
- Fixes #8265.
1764
+ *DHH*
1809
1765
 
1810
- *Yves Senn*
1766
+ * `ActiveRecord::Base#attribute_for_inspect` now truncates long arrays (more than 10 elements).
1811
1767
 
1812
- * Deprecate calling `Relation#sum` with a block. To perform a calculation over
1813
- the array result of the relation, use `to_a.sum(&block)`.
1768
+ *Jan Bernacki*
1814
1769
 
1815
- *Carlos Antonio da Silva*
1770
+ * Allow for the name of the `schema_migrations` table to be configured.
1816
1771
 
1817
- * Fix PostgreSQL adapter to handle BC timestamps correctly
1772
+ *Jerad Phelps*
1818
1773
 
1819
- HistoryEvent.create!(name: "something", occured_at: Date.new(0) - 5.years)
1774
+ * Do not add to scope includes values from through associations.
1775
+ Fixed bug when providing `includes` in through association scope, and fetching targets.
1820
1776
 
1821
- *Bogdan Gusiev*
1777
+ Example:
1822
1778
 
1823
- * When running migrations on PostgreSQL, the `:limit` option for `binary` and `text` columns is silently dropped.
1824
- Previously, these migrations caused sql exceptions, because PostgreSQL doesn't support limits on these types.
1779
+ class Vendor < ActiveRecord::Base
1780
+ has_many :relationships, -> { includes(:user) }
1781
+ has_many :users, through: :relationships
1782
+ end
1825
1783
 
1826
- *Victor Costan*
1784
+ vendor = Vendor.first
1827
1785
 
1828
- * Don't change STI type when calling `ActiveRecord::Base#becomes`.
1829
- Add `ActiveRecord::Base#becomes!` with the previous behavior.
1786
+ # Before
1830
1787
 
1831
- See #3023 for more information.
1788
+ vendor.users.to_a # => Raises exception: not found `:user` for `User`
1832
1789
 
1833
- *Thomas Hollstegge*
1790
+ # After
1834
1791
 
1835
- * `rename_index` can be used inside a `change_table` block.
1792
+ vendor.users.to_a # => No exception is raised
1836
1793
 
1837
- change_table :accounts do |t|
1838
- t.rename_index :user_id, :account_id
1839
- end
1794
+ Fixes #12242, #9517, #10240.
1840
1795
 
1841
- *Jarek Radosz*
1796
+ *Paul Nikitochkin*
1842
1797
 
1843
- * `#pluck` can be used on a relation with `select` clause. Fix #7551
1798
+ * Type cast json values on write, so that the value is consistent
1799
+ with reading from the database.
1844
1800
 
1845
1801
  Example:
1846
1802
 
1847
- Topic.select([:approved, :id]).order(:id).pluck(:id)
1848
-
1849
- *Yves Senn*
1803
+ x = JsonDataType.new tags: {"string" => "foo", :symbol => :bar}
1850
1804
 
1851
- * Do not create useless database transaction when building `has_one` association.
1805
+ # Before:
1806
+ x.tags # => {"string" => "foo", :symbol => :bar}
1852
1807
 
1853
- Example:
1808
+ # After:
1809
+ x.tags # => {"string" => "foo", "symbol" => "bar"}
1854
1810
 
1855
- User.has_one :profile
1856
- User.new.build_profile
1811
+ *Severin Schoepke*
1857
1812
 
1858
- *Bogdan Gusiev*
1813
+ * `ActiveRecord::Store` works together with PostgreSQL `hstore` columns.
1859
1814
 
1860
- * `:counter_cache` option for `has_many` associations to support custom named counter caches.
1861
- Fixes #7993.
1815
+ Fixes #12452.
1862
1816
 
1863
1817
  *Yves Senn*
1864
1818
 
1865
- * Deprecate the possibility to pass a string as third argument of `add_index`.
1866
- Pass `unique: true` instead.
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`.
1867
1822
 
1868
- add_index(:users, :organization_id, unique: true)
1869
-
1870
- *Rafael Mendonça França*
1823
+ *Yves Senn*
1871
1824
 
1872
- * Raise an `ArgumentError` when passing an invalid option to `add_index`.
1825
+ * Save `has_one` association when primary key is manually set.
1873
1826
 
1874
- *Rafael Mendonça França*
1827
+ Fixes #12302.
1875
1828
 
1876
- * Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
1829
+ *Lauro Caetano*
1877
1830
 
1878
- *Alexis Bernard*
1831
+ * Allow any version of BCrypt when using `has_secure_password`.
1879
1832
 
1880
- * `AR::Base#attributes_before_type_cast` now returns unserialized values for serialized attributes.
1833
+ *Mike Perham*
1881
1834
 
1882
- *Nikita Afanasenko*
1835
+ * Sub-query generated for `Relation` passed as array condition did not take in account
1836
+ bind values and have invalid syntax.
1883
1837
 
1884
- * Use query cache/uncache when using `DATABASE_URL`.
1885
- Fixes #6951.
1838
+ Generate sub-query with inline bind values.
1886
1839
 
1887
- *kennyj*
1840
+ Fixes #12586.
1888
1841
 
1889
- * Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
1842
+ *Paul Nikitochkin*
1890
1843
 
1891
- *Henrik Nyh*
1844
+ * Fix a bug where rake db:structure:load crashed when the path contained
1845
+ spaces.
1892
1846
 
1893
- * The `create_table` method raises an `ArgumentError` when the primary key column is redefined.
1894
- Fixes #6378.
1847
+ *Kevin Mook*
1895
1848
 
1896
- *Yves Senn*
1849
+ * `ActiveRecord::QueryMethods#unscope` unscopes negative equality
1897
1850
 
1898
- * `ActiveRecord::AttributeMethods#[]` raises `ActiveModel::MissingAttributeError`
1899
- error if the given attribute is missing. Fixes #5433.
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`.
1900
1854
 
1901
- class Person < ActiveRecord::Base
1902
- belongs_to :company
1903
- end
1855
+ *Eric Hankins*
1904
1856
 
1905
- # Before:
1906
- person = Person.select('id').first
1907
- person[:name] # => nil
1908
- person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
1909
- person[:company_id] # => nil
1910
- person.company # => nil
1857
+ * Raise an exception when model without primary key calls `.find_with_ids`.
1911
1858
 
1912
- # After:
1913
- person = Person.select('id').first
1914
- person[:name] # => ActiveModel::MissingAttributeError: missing_attribute: name
1915
- person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
1916
- person[:company_id] # => ActiveModel::MissingAttributeError: missing_attribute: company_id
1917
- person.company # => ActiveModel::MissingAttributeError: missing_attribute: company_id
1859
+ *Shimpei Makimoto*
1918
1860
 
1919
- *Francesco Rodriguez*
1861
+ * Make `Relation#empty?` use `exists?` instead of `count`.
1920
1862
 
1921
- * Small binary fields use the `VARBINARY` MySQL type, instead of `TINYBLOB`.
1863
+ *Szymon Nowak*
1922
1864
 
1923
- *Victor Costan*
1865
+ * `rake db:structure:dump` no longer crashes when the port was specified as `Fixnum`.
1924
1866
 
1925
- * Decode URI encoded attributes on database connection URLs.
1867
+ *Kenta Okamoto*
1926
1868
 
1927
- *Shawn Veader*
1869
+ * `NullRelation#pluck` takes a list of columns
1928
1870
 
1929
- * Add `find_or_create_by`, `find_or_create_by!` and
1930
- `find_or_initialize_by` methods to `Relation`.
1871
+ The method signature in `NullRelation` was updated to mimic that in
1872
+ `Calculations`.
1931
1873
 
1932
- These are similar to the `first_or_create` family of methods, but
1933
- the behaviour when a record is created is slightly different:
1874
+ *Derek Prior*
1934
1875
 
1935
- User.where(first_name: 'Penélope').first_or_create
1876
+ * `scope_chain` should not be mutated for other reflections.
1936
1877
 
1937
- will execute:
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.
1938
1882
 
1939
- User.where(first_name: 'Penélope').create
1883
+ Fix is to dup the value before adding to the `scope_chain`.
1940
1884
 
1941
- Causing all the `create` callbacks to execute within the context of
1942
- the scope. This could affect queries that occur within callbacks.
1885
+ Fixes #3882.
1943
1886
 
1944
- User.find_or_create_by(first_name: 'Penélope')
1887
+ *Neeraj Singh*
1945
1888
 
1946
- will execute:
1889
+ * Prevent the inversed association from being reloaded on save.
1947
1890
 
1948
- User.create(first_name: 'Penélope')
1891
+ Fixes #9499.
1949
1892
 
1950
- Which obviously does not affect the scoping of queries within
1951
- callbacks.
1893
+ *Dmitry Polushkin*
1952
1894
 
1953
- The `find_or_create_by` version also reads better, frankly.
1895
+ * Generate subquery for `Relation` if it passed as array condition for `where`
1896
+ method.
1954
1897
 
1955
- If you need to add extra attributes during create, you can do one of:
1898
+ Example:
1956
1899
 
1957
- User.create_with(active: true).find_or_create_by(first_name: 'Jon')
1958
- User.find_or_create_by(first_name: 'Jon') { |u| u.active = true }
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))
1959
1904
 
1960
- The `first_or_create` family of methods have been nodoc'ed in favour
1961
- of this API. They may be deprecated in the future but their
1962
- implementation is very small and it's probably not worth putting users
1963
- through lots of annoying deprecation warnings.
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)
1964
1909
 
1965
- *Jon Leighton*
1910
+ Fixes #12415.
1966
1911
 
1967
- * Fix bug with presence validation of associations. Would incorrectly add duplicated errors
1968
- when the association was blank. Bug introduced in 1fab518c6a75dac5773654646eb724a59741bc13.
1912
+ *Paul Nikitochkin*
1969
1913
 
1970
- *Scott Willson*
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.
1971
1917
 
1972
- * Fix bug where sum(expression) returns string '0' for no matching records.
1973
- Fixes #7439
1918
+ *Paul Nikitochkin*
1974
1919
 
1975
- *Tim Macfarlane*
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.
1976
1922
 
1977
- * PostgreSQL adapter correctly fetches default values when using multiple schemas and domains in a db. Fixes #7914
1923
+ * `create_savepoint`, `rollback_to_savepoint` and `release_savepoint` accept
1924
+ a savepoint name.
1978
1925
 
1979
- *Arturo Pie*
1926
+ *Yves Senn*
1980
1927
 
1981
- * Learn ActiveRecord::QueryMethods#order work with hash arguments
1928
+ * Make `next_migration_number` accessible for third party generators.
1982
1929
 
1983
- When symbol or hash passed we convert it to Arel::Nodes::Ordering.
1984
- If we pass invalid direction(like name: :DeSc) ActiveRecord::QueryMethods#order will raise an exception
1930
+ *Yves Senn*
1985
1931
 
1986
- User.order(:name, email: :desc)
1987
- # SELECT "users".* FROM "users" ORDER BY "users"."name" ASC, "users"."email" DESC
1932
+ * Objects instantiated using a null relationship will now retain the
1933
+ attributes of the where clause.
1988
1934
 
1989
- *Tima Maslyuchenko*
1935
+ Fixes #11676, #11675, #11376.
1990
1936
 
1991
- * Rename `ActiveRecord::Fixtures` class to `ActiveRecord::FixtureSet`.
1992
- Instances of this class normally hold a collection of fixtures (records)
1993
- loaded either from a single YAML file, or from a file and a folder
1994
- with the same name. This change make the class name singular and makes
1995
- the class easier to distinguish from the modules like
1996
- `ActiveRecord::TestFixtures`, which operates on multiple fixture sets,
1997
- or `DelegatingFixtures`, `::Fixtures`, etc.,
1998
- and from the class `ActiveRecord::Fixture`, which corresponds to a single
1999
- fixture.
1937
+ *Paul Nikitochkin*, *Peter Brown*, *Nthalk*
2000
1938
 
2001
- *Alexey Muranov*
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.
2002
1942
 
2003
- * The postgres adapter now supports tables with capital letters.
2004
- Fixes #5920.
1943
+ *arthurnn*
2005
1944
 
2006
- *Yves Senn*
1945
+ * Callbacks on has_many should access the in memory parent if a inverse_of is set.
2007
1946
 
2008
- * `CollectionAssociation#count` returns `0` without querying if the
2009
- parent record is not persisted.
1947
+ *arthurnn*
2010
1948
 
2011
- Before:
1949
+ * `ActiveRecord::ConnectionAdapters.string_to_time` respects
1950
+ string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
2012
1951
 
2013
- person.pets.count
2014
- # SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
2015
- # => 0
1952
+ Fixes #12278.
2016
1953
 
2017
- After:
1954
+ *kennyj*
2018
1955
 
2019
- person.pets.count
2020
- # fires without sql query
2021
- # => 0
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`.
2022
1959
 
2023
- *Francesco Rodriguez*
1960
+ Example:
2024
1961
 
2025
- * Fix `reset_counters` crashing on `has_many :through` associations.
2026
- Fixes #7822.
1962
+ @my_comment.update_attributes(nil) # => raises ArgumentError
2027
1963
 
2028
- *lulalala*
1964
+ *John Wang*
2029
1965
 
2030
- * Support for partial inserts.
1966
+ * Deprecate `quoted_locking_column` method, which isn't used anywhere.
2031
1967
 
2032
- When inserting new records, only the fields which have been changed
2033
- from the defaults will actually be included in the INSERT statement.
2034
- The other fields will be populated by the database.
1968
+ *kennyj*
2035
1969
 
2036
- This is more efficient, and also means that it will be safe to
2037
- remove database columns without getting subsequent errors in running
2038
- app processes (so long as the code in those processes doesn't
2039
- contain any references to the removed column).
1970
+ * Migration dump UUID default functions to schema.rb.
2040
1971
 
2041
- The `partial_updates` configuration option is now renamed to
2042
- `partial_writes` to reflect the fact that it now impacts both inserts
2043
- and updates.
1972
+ Fixes #10751.
2044
1973
 
2045
- *Jon Leighton*
1974
+ *kennyj*
2046
1975
 
2047
- * Allow before and after validations to take an array of lifecycle events
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.
2048
1978
 
2049
- *John Foley*
1979
+ Fixes #10450.
2050
1980
 
2051
- * Support for specifying transaction isolation level
1981
+ *kennyj*
2052
1982
 
2053
- If your database supports setting the isolation level for a transaction, you can set
2054
- it like so:
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.
2055
1986
 
2056
- Post.transaction(isolation: :serializable) do
2057
- # ...
2058
- end
1987
+ Fixes #11963.
2059
1988
 
2060
- Valid isolation levels are:
1989
+ *Paul Nikitochkin*
2061
1990
 
2062
- * `:read_uncommitted`
2063
- * `:read_committed`
2064
- * `:repeatable_read`
2065
- * `:serializable`
1991
+ * `CollectionAssociation#first`/`#last` (e.g. `has_many`) use a `LIMIT`ed
1992
+ query to fetch results rather than loading the entire collection.
2066
1993
 
2067
- You should consult the documentation for your database to understand the
2068
- semantics of these different levels:
1994
+ *Lann Martin*
2069
1995
 
2070
- * http://www.postgresql.org/docs/9.1/static/transaction-iso.html
2071
- * https://dev.mysql.com/doc/refman/5.0/en/set-transaction.html
1996
+ * Make possible to run SQLite rake tasks without the `Rails` constant defined.
2072
1997
 
2073
- An `ActiveRecord::TransactionIsolationError` will be raised if:
1998
+ *Damien Mathieu*
2074
1999
 
2075
- * The adapter does not support setting the isolation level
2076
- * You are joining an existing open transaction
2077
- * You are creating a nested (savepoint) transaction
2000
+ * Allow Relation#from to accept other relations with bind values.
2078
2001
 
2079
- The mysql, mysql2 and postgresql adapters support setting the transaction
2080
- isolation level. However, support is disabled for mysql versions below 5,
2081
- because they are affected by a bug (http://bugs.mysql.com/bug.php?id=39170)
2082
- which means the isolation level gets persisted outside the transaction.
2002
+ *Ryan Wallace*
2083
2003
 
2084
- *Jon Leighton*
2004
+ * Fix inserts with prepared statements disabled.
2085
2005
 
2086
- * `ActiveModel::ForbiddenAttributesProtection` is included by default
2087
- in Active Record models. Check the docs of `ActiveModel::ForbiddenAttributesProtection`
2088
- for more details.
2006
+ Fixes #12023.
2089
2007
 
2090
- *Guillermo Iguaran*
2008
+ *Rafael Mendonça França*
2091
2009
 
2092
- * Remove integration between Active Record and
2093
- `ActiveModel::MassAssignmentSecurity`, `protected_attributes` gem
2094
- should be added to use `attr_accessible`/`attr_protected`. Mass
2095
- assignment options has been removed from all the AR methods that
2096
- used it (ex. `AR::Base.new`, `AR::Base.create`, `AR::Base#update_attributes`, etc).
2010
+ * Setting a has_one association on a new record no longer causes an empty
2011
+ transaction.
2097
2012
 
2098
- *Guillermo Iguaran*
2013
+ *Dylan Thacker-Smith*
2099
2014
 
2100
- * Fix the return of querying with an empty hash.
2101
- Fixes #6971.
2015
+ * Fix `AR::Relation#merge` sometimes failing to preserve `readonly(false)` flag.
2102
2016
 
2103
- User.where(token: {})
2017
+ *thedarkone*
2104
2018
 
2105
- Before:
2019
+ * Re-use `order` argument pre-processing for `reorder`.
2106
2020
 
2107
- #=> SELECT * FROM users;
2021
+ *Paul Nikitochkin*
2108
2022
 
2109
- After:
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).
2110
2026
 
2111
- #=> SELECT * FROM users WHERE 1=0;
2027
+ *Mikhail Dieterle*
2112
2028
 
2113
- *Damien Mathieu*
2029
+ * PostgreSQL adapter recognizes negative money values formatted with
2030
+ parentheses (eg. `($1.25) # => -1.25`)).
2031
+ Fixes #11899.
2114
2032
 
2115
- * Fix creation of through association models when using `collection=[]`
2116
- on a `has_many :through` association from an unsaved model.
2117
- Fixes #7661.
2033
+ *Yves Senn*
2118
2034
 
2119
- *Ernie Miller*
2035
+ * Stop interpreting SQL 'string' columns as :string type because there is no
2036
+ common STRING datatype in SQL.
2120
2037
 
2121
- * Explain only normal CRUD sql (select / update / insert / delete).
2122
- Fix problem that explains unexplainable sql.
2123
- Fixes #7544 #6458.
2038
+ *Ben Woosley*
2124
2039
 
2125
- *kennyj*
2040
+ * `ActiveRecord::FinderMethods#exists?` returns `true`/`false` in all cases.
2126
2041
 
2127
- * You can now override the generated accessor methods for stored attributes
2128
- and reuse the original behavior with `read_store_attribute` and `write_store_attribute`,
2129
- which are counterparts to `read_attribute` and `write_attribute`.
2042
+ *Xavier Noria*
2130
2043
 
2131
- *Matt Jones*
2044
+ * Assign inet/cidr attribute with `nil` value for invalid address.
2132
2045
 
2133
- * Accept `belongs_to` (including polymorphic) association keys in queries.
2046
+ Example:
2134
2047
 
2135
- The following queries are now equivalent:
2048
+ record = User.new
2049
+ record.logged_in_from_ip # is type of an inet or a cidr
2136
2050
 
2137
- Post.where(author: author)
2138
- Post.where(author_id: author)
2051
+ # Before:
2052
+ record.logged_in_from_ip = 'bad ip address' # raise exception
2139
2053
 
2140
- PriceEstimate.where(estimate_of: treasure)
2141
- PriceEstimate.where(estimate_of_type: 'Treasure', estimate_of_id: treasure)
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'
2142
2058
 
2143
- *Peter Brown*
2059
+ *Paul Nikitochkin*
2144
2060
 
2145
- * Use native `mysqldump` command instead of `structure_dump` method
2146
- when dumping the database structure to a sql file. Fixes #5547.
2061
+ * `add_to_target` now accepts a second optional `skip_callbacks` argument
2147
2062
 
2148
- *kennyj*
2063
+ If truthy, it will skip the :before_add and :after_add callbacks.
2149
2064
 
2150
- * PostgreSQL inet and cidr types are converted to `IPAddr` objects.
2065
+ *Ben Woosley*
2151
2066
 
2152
- *Dan McClain*
2067
+ * Fix interactions between `:before_add` callbacks and nested attributes
2068
+ assignment of `has_many` associations, when the association was not
2069
+ yet loaded:
2153
2070
 
2154
- * PostgreSQL array type support. Any datatype can be used to create an
2155
- array column, with full migration and schema dumper support.
2071
+ - A `:before_add` callback was being called when a nested attributes
2072
+ assignment assigned to an existing record.
2156
2073
 
2157
- To declare an array column, use the following syntax:
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
2158
2077
 
2159
- create_table :table_with_arrays do |t|
2160
- t.integer :int_array, array: true
2161
- # integer[]
2162
- t.integer :int_array, array: true, length: 2
2163
- # smallint[]
2164
- t.string :string_array, array: true, length: 30
2165
- # char varying(30)[]
2166
- end
2078
+ *Jörg Schray*
2167
2079
 
2168
- This respects any other migration detail (limits, defaults, etc).
2169
- Active Record will serialize and deserialize the array columns on
2170
- their way to and from the database.
2080
+ * Allow enable_extension migration method to be revertible.
2171
2081
 
2172
- One thing to note: PostgreSQL does not enforce any limits on the
2173
- number of elements, and any array can be multi-dimensional. Any
2174
- array that is multi-dimensional must be rectangular (each sub array
2175
- must have the same number of elements as its siblings).
2082
+ *Eric Tipton*
2176
2083
 
2177
- If the `pg_array_parser` gem is available, it will be used when
2178
- parsing PostgreSQL's array representation.
2084
+ * Type cast hstore values on write, so that the value is consistent
2085
+ with reading from the database.
2179
2086
 
2180
- *Dan McClain*
2087
+ Example:
2181
2088
 
2182
- * Attribute predicate methods, such as `article.title?`, will now raise
2183
- `ActiveModel::MissingAttributeError` if the attribute being queried for
2184
- truthiness was not read from the database, instead of just returning `false`.
2089
+ x = Hstore.new tags: {"bool" => true, "number" => 5}
2185
2090
 
2186
- *Ernie Miller*
2091
+ # Before:
2092
+ x.tags # => {"bool" => true, "number" => 5}
2187
2093
 
2188
- * `ActiveRecord::SchemaDumper` uses Ruby 1.9 style hash, which means that the
2189
- schema.rb file will be generated using this new syntax from now on.
2094
+ # After:
2095
+ x.tags # => {"bool" => "true", "number" => "5"}
2190
2096
 
2191
- *Konstantin Shabanov*
2097
+ *Yves Senn* , *Severin Schoepke*
2192
2098
 
2193
- * Map interval with precision to string datatype in PostgreSQL. Fixes #7518.
2099
+ * Fix multidimensional PostgreSQL arrays containing non-string items.
2194
2100
 
2195
2101
  *Yves Senn*
2196
2102
 
2197
- * Fix eagerly loading associations without primary keys. Fixes #4976.
2198
-
2199
- *Kelley Reynolds*
2103
+ * Fixes bug when using includes combined with select, the select statement was overwritten.
2200
2104
 
2201
- * Rails now raise an exception when you're trying to run a migration that has an invalid
2202
- file name. Only lower case letters, numbers, and '_' are allowed in migration's file name.
2203
- Please see #7419 for more details.
2105
+ Fixes #11773.
2204
2106
 
2205
- *Jan Bernacki*
2107
+ *Edo Balvers*
2206
2108
 
2207
- * Fix bug when calling `store_accessor` multiple times.
2208
- Fixes #7532.
2109
+ * Load fixtures from linked folders.
2209
2110
 
2210
- *Matt Jones*
2111
+ *Kassio Borges*
2211
2112
 
2212
- * Fix store attributes that show the changes incorrectly.
2213
- Fixes #7532.
2113
+ * Create a directory for sqlite3 file if not present on the system.
2214
2114
 
2215
- *Matt Jones*
2115
+ *Richard Schneeman*
2216
2116
 
2217
- * Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
2117
+ * Removed redundant override of `xml` column definition for PostgreSQL,
2118
+ in order to use `xml` column type instead of `text`.
2218
2119
 
2219
- *Ian Lesperance*
2120
+ *Paul Nikitochkin*, *Michael Nikitochkin*
2220
2121
 
2221
- * Allow JSON columns to be created in PostgreSQL and properly encoded/decoded.
2222
- to/from database.
2122
+ * Revert `ActiveRecord::Relation#order` change that make new order
2123
+ prepend the old one.
2223
2124
 
2224
- *Dickson S. Guedes*
2125
+ Before:
2225
2126
 
2226
- * Fix time column type casting for invalid time string values to correctly return `nil`.
2127
+ User.order("name asc").order("created_at desc")
2128
+ # SELECT * FROM users ORDER BY created_at desc, name asc
2227
2129
 
2228
- *Adam Meehan*
2130
+ After:
2229
2131
 
2230
- * Allow to pass Symbol or Proc into `:limit` option of #accepts_nested_attributes_for.
2132
+ User.order("name asc").order("created_at desc")
2133
+ # SELECT * FROM users ORDER BY name asc, created_at desc
2231
2134
 
2232
- *Mikhail Dieterle*
2135
+ This also affects order defined in `default_scope` or any kind of associations.
2233
2136
 
2234
- * ActiveRecord::SessionStore has been extracted from Active Record as `activerecord-session_store`
2235
- gem. Please read the `README.md` file on the gem for the usage.
2137
+ * Add ability to define how a class is converted to Arel predicates.
2138
+ For example, adding a very vendor specific regex implementation:
2236
2139
 
2237
- *Prem Sichanugrist*
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)
2238
2144
 
2239
- * Fix `reset_counters` when there are multiple `belongs_to` association with the
2240
- same foreign key and one of them have a counter cache.
2241
- Fixes #5200.
2145
+ *Sean Griffin & @joannecheng*
2242
2146
 
2243
- *Dave Desrochers*
2147
+ * Don't allow `quote_value` to be called without a column.
2244
2148
 
2245
- * `serialized_attributes` and `_attr_readonly` become class method only. Instance reader methods are deprecated.
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.
2246
2153
 
2247
- *kennyj*
2154
+ *Ben Woosley*
2248
2155
 
2249
- * Round usec when comparing timestamp attributes in the dirty tracking.
2250
- Fixes #6975.
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.
2251
2159
 
2252
- *kennyj*
2160
+ Fixes #6763.
2253
2161
 
2254
- * Use inversed parent for first and last child of `has_many` association.
2162
+ *Alfred Wong*
2255
2163
 
2256
- *Ravil Bayramgalin*
2164
+ * rescue from all exceptions in `ConnectionManagement#call`
2257
2165
 
2258
- * Fix `Column.microseconds` and `Column.fast_string_to_time` to avoid converting
2259
- timestamp seconds to a float, since it occasionally results in inaccuracies
2260
- with microsecond-precision times. Fixes #7352.
2166
+ Fixes #11497.
2261
2167
 
2262
- *Ari Pollak*
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.
2263
2172
 
2264
- * Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
2265
- and the dup'ed object shared the same errors.
2173
+ Rescuing from all exceptions and not just StandardError, fixes this
2174
+ behaviour.
2266
2175
 
2267
- *Christian Seiler*
2176
+ *Vipul A M*
2268
2177
 
2269
- * Raise `ArgumentError` if list of attributes to change is empty in `update_all`.
2178
+ * `change_column` for PostgreSQL adapter respects the `:array` option.
2270
2179
 
2271
- *Roman Shatsov*
2180
+ *Yves Senn*
2272
2181
 
2273
- * Fix AR#create to return an unsaved record when AR::RecordInvalid is
2274
- raised. Fixes #3217.
2182
+ * Remove deprecation warning from `attribute_missing` for attributes that are columns.
2275
2183
 
2276
- *Dave Yeu*
2184
+ *Arun Agrawal*
2277
2185
 
2278
- * Fixed table name prefix that is generated in engines for namespaced models.
2186
+ * Remove extra decrement of transaction deep level.
2279
2187
 
2280
- *Wojciech Wnętrzak*
2188
+ Fixes #4566.
2281
2189
 
2282
- * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`.
2283
- Fixes #4772.
2190
+ *Paul Nikitochkin*
2284
2191
 
2285
- *Seamus Abshere*
2192
+ * Reset @column_defaults when assigning `locking_column`.
2193
+ We had a potential problem. For example:
2286
2194
 
2287
- * Allow Relation#merge to take a proc.
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
2288
2199
 
2289
- This was requested by DHH to allow creating of one's own custom
2290
- association macros.
2200
+ Post.column_defaults["my_locking_column"]
2201
+ => nil # expected value is 0 !
2291
2202
 
2292
- For example:
2203
+ *kennyj*
2293
2204
 
2294
- module Commentable
2295
- def has_many_comments(extra)
2296
- has_many :comments, -> { where(:foo).merge(extra) }
2297
- end
2298
- end
2205
+ * Remove extra select and update queries on save/touch/destroy ActiveRecord model
2206
+ with belongs to reflection with option `touch: true`.
2299
2207
 
2300
- class Post < ActiveRecord::Base
2301
- extend Commentable
2302
- has_many_comments -> { where(:bar) }
2303
- end
2208
+ Fixes #11288.
2304
2209
 
2305
- *Jon Leighton*
2210
+ *Paul Nikitochkin*
2306
2211
 
2307
- * Add CollectionProxy#scope.
2212
+ * Remove deprecated nil-passing to the following `SchemaCache` methods:
2213
+ `primary_keys`, `tables`, `columns` and `columns_hash`.
2308
2214
 
2309
- This can be used to get a Relation from an association.
2215
+ *Yves Senn*
2310
2216
 
2311
- Previously we had a #scoped method, but we're deprecating that for
2312
- AR::Base, so it doesn't make sense to have it here.
2217
+ * Remove deprecated block filter from `ActiveRecord::Migrator#migrate`.
2313
2218
 
2314
- This was requested by DHH, to facilitate code like this:
2219
+ *Yves Senn*
2315
2220
 
2316
- Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do
2317
- @topics = @project.topics.scope
2318
- @todolists = @project.todolists.scope
2319
- @attachments = @project.attachments.scope
2320
- @documents = @project.documents.scope
2321
- end
2221
+ * Remove deprecated String constructor from `ActiveRecord::Migrator`.
2322
2222
 
2323
- *Jon Leighton*
2223
+ *Yves Senn*
2324
2224
 
2325
- * Add `Relation#load`.
2225
+ * Remove deprecated `scope` use without passing a callable object.
2326
2226
 
2327
- This method explicitly loads the records and then returns `self`.
2227
+ *Arun Agrawal*
2328
2228
 
2329
- Rather than deciding between "do I want an array or a relation?",
2330
- most people are actually asking themselves "do I want to eager load
2331
- or lazy load?" Therefore, this method provides a way to explicitly
2332
- eager-load without having to switch from a `Relation` to an array.
2229
+ * Remove deprecated `transaction_joinable=` in favor of `begin_transaction`
2230
+ with `:joinable` option.
2333
2231
 
2334
- Example:
2232
+ *Arun Agrawal*
2335
2233
 
2336
- @posts = Post.where(published: true).load
2234
+ * Remove deprecated `decrement_open_transactions`.
2337
2235
 
2338
- *Jon Leighton*
2236
+ *Arun Agrawal*
2339
2237
 
2340
- * `Relation#order`: make new order prepend old one.
2238
+ * Remove deprecated `increment_open_transactions`.
2341
2239
 
2342
- User.order("name asc").order("created_at desc")
2343
- # SELECT * FROM users ORDER BY created_at desc, name asc
2240
+ *Arun Agrawal*
2344
2241
 
2345
- This also affects order defined in `default_scope` or any kind of associations.
2242
+ * Remove deprecated `PostgreSQLAdapter#outside_transaction?`
2243
+ method. You can use `#transaction_open?` instead.
2346
2244
 
2347
- *Bogdan Gusiev*
2245
+ *Yves Senn*
2348
2246
 
2349
- * `Model.all` now returns an `ActiveRecord::Relation`, rather than an
2350
- array of records. Use `Relation#to_a` if you really want an array.
2247
+ * Remove deprecated `ActiveRecord::Fixtures.find_table_name` in favor of
2248
+ `ActiveRecord::Fixtures.default_fixture_model_name`.
2351
2249
 
2352
- In some specific cases, this may cause breakage when upgrading.
2353
- However in most cases the `ActiveRecord::Relation` will just act as a
2354
- lazy-loaded array and there will be no problems.
2250
+ *Vipul A M*
2355
2251
 
2356
- Note that calling `Model.all` with options (e.g.
2357
- `Model.all(conditions: '...')` was already deprecated, but it will
2358
- still return an array in order to make the transition easier.
2252
+ * Removed deprecated `columns_for_remove` from `SchemaStatements`.
2359
2253
 
2360
- `Model.scoped` is deprecated in favour of `Model.all`.
2254
+ *Neeraj Singh*
2361
2255
 
2362
- `Relation#all` still returns an array, but is deprecated (since it
2363
- would serve no purpose if we made it return a `Relation`).
2256
+ * Remove deprecated `SchemaStatements#distinct`.
2364
2257
 
2365
- *Jon Leighton*
2258
+ *Francesco Rodriguez*
2366
2259
 
2367
- * `:finder_sql` and `:counter_sql` options on collection associations
2368
- are deprecated. Please transition to using scopes.
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.
2369
2263
 
2370
- *Jon Leighton*
2264
+ *Yves Senn*
2371
2265
 
2372
- * `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
2373
- associations are deprecated. Please transition to using `has_many
2374
- :through`.
2266
+ * Removed support for deprecated option `:restrict` for `:dependent`
2267
+ in associations.
2375
2268
 
2376
- *Jon Leighton*
2269
+ *Neeraj Singh*
2377
2270
 
2378
- * Added `#update_columns` method which updates the attributes from
2379
- the passed-in hash without calling save, hence skipping validations and
2380
- callbacks. `ActiveRecordError` will be raised when called on new objects
2381
- or when at least one of the attributes is marked as read only.
2271
+ * Removed support for deprecated `delete_sql` in associations.
2382
2272
 
2383
- post.attributes # => {"id"=>2, "title"=>"My title", "body"=>"My content", "author"=>"Peter"}
2384
- post.update_columns(title: 'New title', author: 'Sebastian') # => true
2385
- post.attributes # => {"id"=>2, "title"=>"New title", "body"=>"My content", "author"=>"Sebastian"}
2273
+ *Neeraj Singh*
2386
2274
 
2387
- *Sebastian Martinez + Rafael Mendonça França*
2275
+ * Removed support for deprecated `insert_sql` in associations.
2388
2276
 
2389
- * The migration generator now creates a join table with (commented) indexes every time
2390
- the migration name contains the word `join_table`:
2277
+ *Neeraj Singh*
2391
2278
 
2392
- rails g migration create_join_table_for_artists_and_musics artist_id:index music_id
2279
+ * Removed support for deprecated `finder_sql` in associations.
2393
2280
 
2394
- *Aleksey Magusev*
2281
+ *Neeraj Singh*
2395
2282
 
2396
- * Add `add_reference` and `remove_reference` schema statements. Aliases, `add_belongs_to`
2397
- and `remove_belongs_to` are acceptable. References are reversible.
2283
+ * Support array as root element in JSON fields.
2398
2284
 
2399
- Examples:
2285
+ *Alexey Noskov & Francesco Rodriguez*
2400
2286
 
2401
- # Create a user_id column
2402
- add_reference(:products, :user)
2403
- # Create a supplier_id, supplier_type columns and appropriate index
2404
- add_reference(:products, :supplier, polymorphic: true, index: true)
2405
- # Remove polymorphic reference
2406
- remove_reference(:products, :supplier, polymorphic: true)
2287
+ * Removed support for deprecated `counter_sql` in associations.
2407
2288
 
2408
- *Aleksey Magusev*
2289
+ *Neeraj Singh*
2409
2290
 
2410
- * Add `:default` and `:null` options to `column_exists?`.
2291
+ * Do not invoke callbacks when `delete_all` is called on collection.
2411
2292
 
2412
- column_exists?(:testings, :taggable_id, :integer, null: false)
2413
- column_exists?(:testings, :taggable_type, :string, default: 'Photo')
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.
2414
2298
 
2415
- *Aleksey Magusev*
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)`.
2416
2301
 
2417
- * `ActiveRecord::Relation#inspect` now makes it clear that you are
2418
- dealing with a `Relation` object rather than an array:.
2302
+ *Neeraj Singh*
2419
2303
 
2420
- User.where(age: 30).inspect
2421
- # => <ActiveRecord::Relation [#<User ...>, #<User ...>, ...]>
2304
+ * Calling default_scope without a proc will now raise `ArgumentError`.
2422
2305
 
2423
- User.where(age: 30).to_a.inspect
2424
- # => [#<User ...>, #<User ...>]
2306
+ *Neeraj Singh*
2425
2307
 
2426
- The number of records displayed will be limited to 10.
2308
+ * Removed deprecated method `type_cast_code` from Column.
2427
2309
 
2428
- *Brian Cardarella, Jon Leighton & Damien Mathieu*
2310
+ *Neeraj Singh*
2429
2311
 
2430
- * Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
2431
- Example:
2312
+ * Removed deprecated options `delete_sql` and `insert_sql` from HABTM
2313
+ association.
2432
2314
 
2433
- development:
2434
- adapter: postgresql
2435
- host: localhost
2436
- database: rails_development
2437
- username: foo
2438
- password: bar
2439
- encoding: UTF8
2440
- collation: ja_JP.UTF8
2441
- ctype: ja_JP.UTF8
2315
+ Removed deprecated options `finder_sql` and `counter_sql` from
2316
+ collection association.
2442
2317
 
2443
- *kennyj*
2318
+ *Neeraj Singh*
2444
2319
 
2445
- * Changed `validates_presence_of` on an association so that children objects
2446
- do not validate as being present if they are marked for destruction. This
2447
- prevents you from saving the parent successfully and thus putting the parent
2448
- in an invalid state.
2320
+ * Remove deprecated `ActiveRecord::Base#connection` method.
2321
+ Make sure to access it via the class.
2449
2322
 
2450
- *Nick Monje & Brent Wheeldon*
2323
+ *Yves Senn*
2451
2324
 
2452
- * `FinderMethods#exists?` now returns `false` with the `false` argument.
2325
+ * Remove deprecation warning for `auto_explain_threshold_in_seconds`.
2453
2326
 
2454
- *Egor Lynko*
2327
+ *Yves Senn*
2455
2328
 
2456
- * Added support for specifying the precision of a timestamp in the PostgreSQL
2457
- adapter. So, instead of having to incorrectly specify the precision using the
2458
- `:limit` option, you may use `:precision`, as intended. For example, in a migration:
2329
+ * Remove deprecated `:distinct` option from `Relation#count`.
2459
2330
 
2460
- def change
2461
- create_table :foobars do |t|
2462
- t.timestamps precision: 0
2463
- end
2464
- end
2331
+ *Yves Senn*
2465
2332
 
2466
- *Tony Schneider*
2333
+ * Removed deprecated methods `partial_updates`, `partial_updates?` and
2334
+ `partial_updates=`.
2467
2335
 
2468
- * Allow `ActiveRecord::Relation#pluck` to accept multiple columns. Returns an
2469
- array of arrays containing the typecasted values:
2336
+ *Neeraj Singh*
2470
2337
 
2471
- Person.pluck(:id, :name)
2472
- # SELECT people.id, people.name FROM people
2473
- # [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]
2338
+ * Removed deprecated method `scoped`.
2474
2339
 
2475
- *Jeroen van Ingen & Carlos Antonio da Silva*
2340
+ *Neeraj Singh*
2476
2341
 
2477
- * Improve the derivation of HABTM join table name to take account of nesting.
2478
- It now takes the table names of the two models, sorts them lexically and
2479
- then joins them, stripping any common prefix from the second table name.
2342
+ * Removed deprecated method `default_scopes?`.
2480
2343
 
2481
- Some examples:
2344
+ *Neeraj Singh*
2482
2345
 
2483
- Top level models (Category <=> Product)
2484
- Old: categories_products
2485
- New: categories_products
2346
+ * Remove implicit join references that were deprecated in 4.0.
2486
2347
 
2487
- Top level models with a global table_name_prefix (Category <=> Product)
2488
- Old: site_categories_products
2489
- New: site_categories_products
2348
+ Example:
2490
2349
 
2491
- Nested models in a module without a table_name_prefix method (Admin::Category <=> Admin::Product)
2492
- Old: categories_products
2493
- New: categories_products
2350
+ # before with implicit joins
2351
+ Comment.where('posts.author_id' => 7)
2494
2352
 
2495
- Nested models in a module with a table_name_prefix method (Admin::Category <=> Admin::Product)
2496
- Old: categories_products
2497
- New: admin_categories_products
2353
+ # after
2354
+ Comment.references(:posts).where('posts.author_id' => 7)
2498
2355
 
2499
- Nested models in a parent model (Catalog::Category <=> Catalog::Product)
2500
- Old: categories_products
2501
- New: catalog_categories_products
2356
+ *Yves Senn*
2502
2357
 
2503
- Nested models in different parent models (Catalog::Category <=> Content::Page)
2504
- Old: categories_pages
2505
- New: catalog_categories_content_pages
2358
+ * Apply default scope when joining associations. For example:
2506
2359
 
2507
- *Andrew White*
2360
+ class Post < ActiveRecord::Base
2361
+ default_scope -> { where published: true }
2362
+ end
2508
2363
 
2509
- * Move HABTM validity checks to `ActiveRecord::Reflection`. One side effect of
2510
- this is to move when the exceptions are raised from the point of declaration
2511
- to when the association is built. This is consistent with other association
2512
- validity checks.
2364
+ class Comment
2365
+ belongs_to :post
2366
+ end
2513
2367
 
2514
- *Andrew White*
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.
2515
2371
 
2516
- * Added `stored_attributes` hash which contains the attributes stored using
2517
- `ActiveRecord::Store`. This allows you to retrieve the list of attributes
2518
- you've defined.
2372
+ Before this change, the default scope from `Post` was not applied,
2373
+ so we'd get comments on unpublished posts.
2519
2374
 
2520
- class User < ActiveRecord::Base
2521
- store :settings, accessors: [:color, :homepage]
2522
- end
2375
+ *Jon Leighton*
2523
2376
 
2524
- User.stored_attributes[:settings] # [:color, :homepage]
2377
+ * Remove `activerecord-deprecated_finders` as a dependency.
2525
2378
 
2526
- *Joost Baaij & Carlos Antonio da Silva*
2379
+ *Łukasz Strzałkowski*
2527
2380
 
2528
- * PostgreSQL default log level is now 'warning', to bypass the noisy notice
2529
- messages. You can change the log level using the `min_messages` option
2530
- available in your config/database.yml.
2381
+ * Remove Oracle / Sqlserver / Firebird database tasks that were deprecated in 4.0.
2531
2382
 
2532
2383
  *kennyj*
2533
2384
 
2534
- * Add uuid datatype support to PostgreSQL adapter.
2535
-
2536
- *Konstantin Shabanov*
2537
-
2538
- * Added `ActiveRecord::Migration.check_pending!` that raises an error if
2539
- migrations are pending.
2540
-
2541
- *Richard Schneeman*
2385
+ * `find_each` now returns an `Enumerator` when called without a block, so that it
2386
+ can be chained with other `Enumerable` methods.
2542
2387
 
2543
- * Added `#destroy!` which acts like `#destroy` but will raise an
2544
- `ActiveRecord::RecordNotDestroyed` exception instead of returning `false`.
2388
+ *Ben Woosley*
2545
2389
 
2546
- *Marc-André Lafortune*
2390
+ * `ActiveRecord::Result.each` now returns an `Enumerator` when called without
2391
+ a block, so that it can be chained with other `Enumerable` methods.
2547
2392
 
2548
- * Added support to `CollectionAssociation#delete` for passing `fixnum`
2549
- or `string` values as record ids. This finds the records responding
2550
- to the `id` and executes delete on them.
2393
+ *Ben Woosley*
2551
2394
 
2552
- class Person < ActiveRecord::Base
2553
- has_many :pets
2554
- end
2395
+ * Flatten merged join_values before building the joins.
2555
2396
 
2556
- person.pets.delete("1") # => [#<Pet id: 1>]
2557
- person.pets.delete(2, 3) # => [#<Pet id: 2>, #<Pet id: 3>]
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.
2558
2400
 
2559
- *Francesco Rodriguez*
2401
+ Fixes #10669.
2560
2402
 
2561
- * Deprecated most of the 'dynamic finder' methods. All dynamic methods
2562
- except for `find_by_...` and `find_by_...!` are deprecated. Here's
2563
- how you can rewrite the code:
2403
+ *Neeraj Singh and iwiznia*
2564
2404
 
2565
- * `find_all_by_...` can be rewritten using `where(...)`
2566
- * `find_last_by_...` can be rewritten using `where(...).last`
2567
- * `scoped_by_...` can be rewritten using `where(...)`
2568
- * `find_or_initialize_by_...` can be rewritten using
2569
- `where(...).first_or_initialize`
2570
- * `find_or_create_by_...` can be rewritten using
2571
- `find_or_create_by(...)` or where(...).first_or_create`
2572
- * `find_or_create_by_...!` can be rewritten using
2573
- `find_or_create_by!(...) or `where(...).first_or_create!`
2405
+ * Do not load all child records for inverse case.
2574
2406
 
2575
- The implementation of the deprecated dynamic finders has been moved
2576
- to the `activerecord-deprecated_finders` gem. See below for details.
2407
+ currently `post.comments.find(Comment.first.id)` would load all
2408
+ comments for the given post to set the inverse association.
2577
2409
 
2578
- *Jon Leighton*
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.
2579
2413
 
2580
- * Deprecated the old-style hash based finder API. This means that
2581
- methods which previously accepted "finder options" no longer do. For
2582
- example this:
2414
+ Fix is to use in-memory records only if loaded? is true. Otherwise
2415
+ load the records using full sql.
2583
2416
 
2584
- Post.find(:all, conditions: { comments_count: 10 }, limit: 5)
2417
+ Fixes #10509.
2585
2418
 
2586
- Should be rewritten in the new style which has existed since Rails 3:
2419
+ *Neeraj Singh*
2587
2420
 
2588
- Post.where(comments_count: 10).limit(5)
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.
2589
2425
 
2590
- Note that as an interim step, it is possible to rewrite the above as:
2426
+ Example:
2591
2427
 
2592
- Post.all.merge(where: { comments_count: 10 }, limit: 5)
2428
+ Author.inspect # => "Author(no database connection)"
2593
2429
 
2594
- This could save you a lot of work if there is a lot of old-style
2595
- finder usage in your application.
2430
+ *Yves Senn*
2596
2431
 
2597
- `Relation#merge` now accepts a hash of
2598
- options, but they must be identical to the names of the equivalent
2599
- finder method. These are mostly identical to the old-style finder
2600
- option names, except in the following cases:
2432
+ * Handle single quotes in PostgreSQL default column values.
2433
+ Fixes #10881.
2601
2434
 
2602
- * `:conditions` becomes `:where`.
2603
- * `:include` becomes `:includes`.
2435
+ *Dylan Markow*
2604
2436
 
2605
- The code to implement the deprecated features has been moved out to the
2606
- `activerecord-deprecated_finders` gem. This gem is a dependency of Active
2607
- Record in Rails 4.0, so the interface works out of the box. It will no
2608
- longer be a dependency from Rails 4.1 (you'll need to add it to the
2609
- `Gemfile` in 4.1), and will be maintained until Rails 5.0.
2437
+ * Log the sql that is actually sent to the database.
2610
2438
 
2611
- *Jon Leighton*
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'`.
2612
2443
 
2613
- * It's not possible anymore to destroy a model marked as read only.
2444
+ Do not squeeze whitespace out of sql queries. Fixes #10982.
2614
2445
 
2615
- *Johannes Barre*
2446
+ *Neeraj Singh*
2616
2447
 
2617
- * Added ability to ActiveRecord::Relation#from to accept other ActiveRecord::Relation objects.
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`.
2618
2450
 
2619
- Record.from(subquery)
2620
- Record.from(subquery, :a)
2451
+ *Yves Senn*
2621
2452
 
2622
- *Radoslav Stankov*
2453
+ * Fix mysql2 adapter raises the correct exception when executing a query on a
2454
+ closed connection.
2623
2455
 
2624
- * Added custom coders support for ActiveRecord::Store. Now you can set
2625
- your custom coder like this:
2456
+ *Yves Senn*
2626
2457
 
2627
- store :settings, accessors: [ :color, :homepage ], coder: JSON
2458
+ * Ambiguous reflections are on :through relationships are no longer supported.
2459
+ For example, you need to change this:
2628
2460
 
2629
- *Andrey Voronkov*
2461
+ class Author < ActiveRecord::Base
2462
+ has_many :posts
2463
+ has_many :taggings, through: :posts
2464
+ end
2630
2465
 
2631
- * `mysql` and `mysql2` connections will set `SQL_MODE=STRICT_ALL_TABLES` by
2632
- default to avoid silent data loss. This can be disabled by specifying
2633
- `strict: false` in your `database.yml`.
2466
+ class Post < ActiveRecord::Base
2467
+ has_one :tagging
2468
+ has_many :taggings
2469
+ end
2634
2470
 
2635
- *Michael Pearson*
2471
+ class Tagging < ActiveRecord::Base
2472
+ end
2636
2473
 
2637
- * Added default order to `first` to assure consistent results among
2638
- different database engines. Introduced `take` as a replacement to
2639
- the old behavior of `first`.
2474
+ To this:
2640
2475
 
2641
- *Marcelo Silveira*
2476
+ class Author < ActiveRecord::Base
2477
+ has_many :posts
2478
+ has_many :taggings, through: :posts, source: :tagging
2479
+ end
2642
2480
 
2643
- * Added an `:index` option to automatically create indexes for references
2644
- and belongs_to statements in migrations.
2481
+ class Post < ActiveRecord::Base
2482
+ has_one :tagging
2483
+ has_many :taggings
2484
+ end
2645
2485
 
2646
- The `references` and `belongs_to` methods now support an `index`
2647
- option that receives either a boolean value or an options hash
2648
- that is identical to options available to the add_index method:
2486
+ class Tagging < ActiveRecord::Base
2487
+ end
2649
2488
 
2650
- create_table :messages do |t|
2651
- t.references :person, index: true
2652
- end
2489
+ *Aaron Patterson*
2653
2490
 
2654
- Is the same as:
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.
2655
2494
 
2656
- create_table :messages do |t|
2657
- t.references :person
2658
- end
2659
- add_index :messages, :person_id
2495
+ Example:
2660
2496
 
2661
- Generators have also been updated to use the new syntax.
2497
+ User.select("name, username").count
2498
+ # Before => SELECT count(*) FROM users
2499
+ # After => ActiveRecord::StatementInvalid
2662
2500
 
2663
- *Joshua Wood*
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
2664
2504
 
2665
- * Added `#find_by` and `#find_by!` to mirror the functionality
2666
- provided by dynamic finders in a way that allows dynamic input more
2667
- easily:
2505
+ *Yves Senn*
2668
2506
 
2669
- Post.find_by name: 'Spartacus', rating: 4
2670
- Post.find_by "published_at < ?", 2.weeks.ago
2671
- Post.find_by! name: 'Spartacus'
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.
2672
2510
 
2673
- *Jon Leighton*
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.
2674
2514
 
2675
- * Added ActiveRecord::Base#slice to return a hash of the given methods with
2676
- their names as keys and returned values as values.
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.
2677
2518
 
2678
- *Guillermo Iguaran*
2519
+ You can turn off the automatic detection of inverse associations by setting
2520
+ the `:inverse_of` option to `false` like so:
2679
2521
 
2680
- * Deprecate eager-evaluated scopes.
2522
+ class Taggable < ActiveRecord::Base
2523
+ belongs_to :tag, inverse_of: false
2524
+ end
2681
2525
 
2682
- Don't use this:
2526
+ *John Wang*
2683
2527
 
2684
- scope :red, where(color: 'red')
2685
- default_scope where(color: 'red')
2528
+ * Fix `add_column` with `array` option when using PostgreSQL. Fixes #10432.
2686
2529
 
2687
- Use this:
2530
+ *Adam Anderson*
2688
2531
 
2689
- scope :red, -> { where(color: 'red') }
2690
- default_scope { where(color: 'red') }
2532
+ * Usage of `implicit_readonly` is being removed`. Please use `readonly` method
2533
+ explicitly to mark records as `readonly.
2534
+ Fixes #10615.
2691
2535
 
2692
- The former has numerous issues. It is a common newbie gotcha to do
2693
- the following:
2536
+ Example:
2694
2537
 
2695
- scope :recent, where(published_at: Time.now - 2.weeks)
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
2696
2541
 
2697
- Or a more subtle variant:
2542
+ *Yves Senn*
2698
2543
 
2699
- scope :recent, -> { where(published_at: Time.now - 2.weeks) }
2700
- scope :recent_red, recent.where(color: 'red')
2544
+ * Fix the `:primary_key` option for `has_many` associations.
2701
2545
 
2702
- Eager scopes are also very complex to implement within Active
2703
- Record, and there are still bugs. For example, the following does
2704
- not do what you expect:
2546
+ Fixes #10693.
2705
2547
 
2706
- scope :remove_conditions, except(:where)
2707
- where(...).remove_conditions # => still has conditions
2548
+ *Yves Senn*
2708
2549
 
2709
- *Jon Leighton*
2550
+ * Fix bug where tiny types are incorrectly coerced as boolean when the length is more than 1.
2710
2551
 
2711
- * Remove IdentityMap
2552
+ Fixes #10620.
2712
2553
 
2713
- IdentityMap has never graduated to be an "enabled-by-default" feature, due
2714
- to some inconsistencies with associations, as described in this commit:
2554
+ *Aaron Patterson*
2715
2555
 
2716
- https://github.com/rails/rails/commit/302c912bf6bcd0fa200d964ec2dc4a44abe328a6
2556
+ * Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1.
2717
2557
 
2718
- Hence the removal from the codebase, until such issues are fixed.
2558
+ *kennyj*
2719
2559
 
2720
- *Carlos Antonio da Silva*
2560
+ * Deprecate `ConnectionAdapters::SchemaStatements#distinct`,
2561
+ as it is no longer used by internals.
2721
2562
 
2722
- * Added the schema cache dump feature.
2563
+ *Ben Woosley*
2723
2564
 
2724
- `Schema cache dump` feature was implemented. This feature can dump/load internal state of `SchemaCache` instance
2725
- because we want to boot rails more quickly when we have many models.
2565
+ * Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix`
2566
+ is not blank.
2726
2567
 
2727
- Usage notes:
2568
+ Call `assume_migrated_upto_version` on connection to prevent it from first
2569
+ being picked up in `method_missing`.
2728
2570
 
2729
- 1) execute rake task.
2730
- RAILS_ENV=production bundle exec rake db:schema:cache:dump
2731
- => generate db/schema_cache.dump
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`.
2732
2575
 
2733
- 2) add config.active_record.use_schema_cache_dump = true in config/production.rb. BTW, true is default.
2576
+ Fixes #10411.
2734
2577
 
2735
- 3) boot rails.
2736
- RAILS_ENV=production bundle exec rails server
2737
- => use db/schema_cache.dump
2578
+ *Kyle Stevens*
2738
2579
 
2739
- 4) If you remove clear dumped cache, execute rake task.
2740
- RAILS_ENV=production bundle exec rake db:schema:cache:clear
2741
- => remove db/schema_cache.dump
2580
+ * Method `read_attribute_before_type_cast` should accept input as symbol.
2742
2581
 
2743
- *kennyj*
2582
+ *Neeraj Singh*
2744
2583
 
2745
- * Added support for partial indices to PostgreSQL adapter.
2584
+ * Confirm a record has not already been destroyed before decrementing counter cache.
2746
2585
 
2747
- The `add_index` method now supports a `where` option that receives a
2748
- string with the partial index criteria.
2586
+ *Ben Tucker*
2749
2587
 
2750
- add_index(:accounts, :code, where: 'active')
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`.
2751
2592
 
2752
- generates
2593
+ *Zach Ohlgren*
2753
2594
 
2754
- CREATE INDEX index_accounts_on_code ON accounts(code) WHERE active
2595
+ * While removing index if column option is missing then raise IrreversibleMigration exception.
2755
2596
 
2756
- *Marcelo Silveira*
2597
+ Following code should raise `IrreversibleMigration`. But the code was
2598
+ failing since options is an array and not a hash.
2757
2599
 
2758
- * Implemented `ActiveRecord::Relation#none` method.
2600
+ def change
2601
+ change_table :users do |t|
2602
+ t.remove_index [:name, :email]
2603
+ end
2604
+ end
2759
2605
 
2760
- The `none` method returns a chainable relation with zero records
2761
- (an instance of the NullRelation class).
2606
+ Fix was to check if the options is a Hash before operating on it.
2762
2607
 
2763
- Any subsequent condition chained to the returned relation will continue
2764
- generating an empty relation and will not fire any query to the database.
2608
+ Fixes #10419.
2765
2609
 
2766
- *Juanjo Bazán*
2610
+ *Neeraj Singh*
2767
2611
 
2768
- * Added the `ActiveRecord::NullRelation` class implementing the null
2769
- object pattern for the Relation class.
2612
+ * Do not overwrite manually built records during one-to-one nested attribute assignment
2770
2613
 
2771
- *Juanjo Bazán*
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.:
2772
2617
 
2773
- * Added new `dependent: :restrict_with_error` option. This will add
2774
- an error to the model, rather than raising an exception.
2618
+ class Member < ActiveRecord::Base
2619
+ has_one :avatar
2620
+ accepts_nested_attributes_for :avatar
2775
2621
 
2776
- The `:restrict` option is renamed to `:restrict_with_exception` to
2777
- make this distinction explicit.
2622
+ def avatar
2623
+ super || build_avatar(width: 200)
2624
+ end
2625
+ end
2778
2626
 
2779
- *Manoj Kumar & Jon Leighton*
2627
+ member = Member.new
2628
+ member.avatar_attributes = {icon: 'sad'}
2629
+ member.avatar.width # => 200
2780
2630
 
2781
- * Added `create_join_table` migration helper to create HABTM join tables.
2631
+ *Olek Janiszewski*
2782
2632
 
2783
- create_join_table :products, :categories
2784
- # =>
2785
- # create_table :categories_products, id: false do |td|
2786
- # td.integer :product_id, null: false
2787
- # td.integer :category_id, null: false
2788
- # end
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.
2789
2637
 
2790
- *Rafael Mendonça França*
2638
+ *Johnny Holton*
2791
2639
 
2792
- * The primary key is always initialized in the @attributes hash to `nil` (unless
2793
- another value has been specified).
2640
+ * Handle aliased attributes in ActiveRecord::Relation.
2794
2641
 
2795
- *Aaron Patterson*
2642
+ When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database:
2796
2643
 
2797
- * In previous releases, the following would generate a single query with
2798
- an `OUTER JOIN comments`, rather than two separate queries:
2644
+ With the model
2799
2645
 
2800
- Post.includes(:comments)
2801
- .where("comments.name = 'foo'")
2646
+ class Topic
2647
+ alias_attribute :heading, :title
2648
+ end
2802
2649
 
2803
- This behaviour relies on matching SQL string, which is an inherently
2804
- flawed idea unless we write an SQL parser, which we do not wish to
2805
- do.
2650
+ The call
2806
2651
 
2807
- Therefore, it is now deprecated.
2652
+ Topic.where(heading: 'The First Topic')
2808
2653
 
2809
- To avoid deprecation warnings and for future compatibility, you must
2810
- explicitly state which tables you reference, when using SQL snippets:
2654
+ should yield the same result as
2811
2655
 
2812
- Post.includes(:comments)
2813
- .where("comments.name = 'foo'")
2814
- .references(:comments)
2656
+ Topic.where(title: 'The First Topic')
2815
2657
 
2816
- Note that you do not need to explicitly specify references in the
2817
- following cases, as they can be automatically inferred:
2658
+ This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`.
2818
2659
 
2819
- Post.includes(:comments).where(comments: { name: 'foo' })
2820
- Post.includes(:comments).where('comments.name' => 'foo')
2821
- Post.includes(:comments).order('comments.name')
2660
+ This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`.
2822
2661
 
2823
- You do not need to worry about this unless you are doing eager
2824
- loading. Basically, don't worry unless you see a deprecation warning
2825
- or (in future releases) an SQL error due to a missing JOIN.
2662
+ *Godfrey Chan*
2826
2663
 
2827
- *Jon Leighton*
2664
+ * Mute `psql` output when running rake db:schema:load.
2828
2665
 
2829
- * Support for the `schema_info` table has been dropped. Please
2830
- switch to `schema_migrations`.
2666
+ *Godfrey Chan*
2831
2667
 
2832
- *Aaron Patterson*
2668
+ * Trigger a save on `has_one association=(associate)` when the associate contents have changed.
2833
2669
 
2834
- * Connections *must* be closed at the end of a thread. If not, your
2835
- connection pool can fill and an exception will be raised.
2670
+ Fixes #8856.
2836
2671
 
2837
- *Aaron Patterson*
2672
+ *Chris Thompson*
2838
2673
 
2839
- * PostgreSQL hstore records can be created.
2674
+ * Abort a rake task when missing db/structure.sql like `db:schema:load` task.
2840
2675
 
2841
- *Aaron Patterson*
2676
+ *kennyj*
2842
2677
 
2843
- * PostgreSQL hstore types are automatically deserialized from the database.
2678
+ * rake:db:test:prepare falls back to original environment after execution.
2844
2679
 
2845
- *Aaron Patterson*
2680
+ *Slava Markevich*
2846
2681
 
2847
- Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activerecord/CHANGELOG.md) for previous changes.
2682
+ Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/activerecord/CHANGELOG.md) for previous changes.