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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1632 -1797
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -2
- data/examples/performance.rb +30 -18
- data/examples/simple.rb +4 -4
- data/lib/active_record/aggregations.rb +2 -1
- data/lib/active_record/association_relation.rb +4 -0
- data/lib/active_record/associations/alias_tracker.rb +49 -29
- data/lib/active_record/associations/association.rb +9 -17
- data/lib/active_record/associations/association_scope.rb +59 -49
- data/lib/active_record/associations/belongs_to_association.rb +34 -25
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +6 -1
- data/lib/active_record/associations/builder/association.rb +84 -54
- data/lib/active_record/associations/builder/belongs_to.rb +90 -58
- data/lib/active_record/associations/builder/collection_association.rb +47 -45
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +119 -25
- data/lib/active_record/associations/builder/has_many.rb +3 -3
- data/lib/active_record/associations/builder/has_one.rb +5 -7
- data/lib/active_record/associations/builder/singular_association.rb +6 -7
- data/lib/active_record/associations/collection_association.rb +121 -111
- data/lib/active_record/associations/collection_proxy.rb +73 -18
- data/lib/active_record/associations/has_many_association.rb +14 -11
- data/lib/active_record/associations/has_many_through_association.rb +33 -6
- data/lib/active_record/associations/has_one_association.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +46 -104
- data/lib/active_record/associations/join_dependency/join_base.rb +6 -8
- data/lib/active_record/associations/join_dependency/join_part.rb +18 -37
- data/lib/active_record/associations/join_dependency.rb +208 -168
- data/lib/active_record/associations/preloader/association.rb +69 -27
- data/lib/active_record/associations/preloader/collection_association.rb +2 -2
- data/lib/active_record/associations/preloader/has_many_through.rb +1 -1
- data/lib/active_record/associations/preloader/singular_association.rb +3 -3
- data/lib/active_record/associations/preloader/through_association.rb +58 -26
- data/lib/active_record/associations/preloader.rb +63 -49
- data/lib/active_record/associations/singular_association.rb +6 -5
- data/lib/active_record/associations/through_association.rb +30 -9
- data/lib/active_record/associations.rb +116 -42
- data/lib/active_record/attribute_assignment.rb +6 -3
- data/lib/active_record/attribute_methods/before_type_cast.rb +2 -1
- data/lib/active_record/attribute_methods/dirty.rb +35 -26
- data/lib/active_record/attribute_methods/primary_key.rb +8 -1
- data/lib/active_record/attribute_methods/read.rb +56 -29
- data/lib/active_record/attribute_methods/serialization.rb +44 -12
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +13 -1
- data/lib/active_record/attribute_methods/write.rb +59 -26
- data/lib/active_record/attribute_methods.rb +82 -43
- data/lib/active_record/autosave_association.rb +209 -194
- data/lib/active_record/base.rb +6 -2
- data/lib/active_record/callbacks.rb +2 -2
- data/lib/active_record/coders/json.rb +13 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +5 -10
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +14 -24
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +13 -13
- data/lib/active_record/connection_adapters/abstract/quoting.rb +6 -3
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +21 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +90 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +9 -8
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +45 -70
- data/lib/active_record/connection_adapters/abstract/transaction.rb +1 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +28 -96
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +74 -66
- data/lib/active_record/connection_adapters/column.rb +1 -35
- data/lib/active_record/connection_adapters/connection_specification.rb +231 -43
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +10 -5
- data/lib/active_record/connection_adapters/mysql_adapter.rb +24 -17
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +22 -15
- data/lib/active_record/connection_adapters/postgresql/cast.rb +12 -4
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +18 -44
- data/lib/active_record/connection_adapters/postgresql/oid.rb +38 -14
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +37 -12
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +20 -11
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +98 -52
- data/lib/active_record/connection_adapters/schema_cache.rb +8 -29
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +55 -60
- data/lib/active_record/connection_handling.rb +39 -5
- data/lib/active_record/core.rb +38 -54
- data/lib/active_record/counter_cache.rb +9 -10
- data/lib/active_record/dynamic_matchers.rb +6 -2
- data/lib/active_record/enum.rb +199 -0
- data/lib/active_record/errors.rb +22 -5
- data/lib/active_record/fixture_set/file.rb +2 -1
- data/lib/active_record/fixtures.rb +173 -76
- data/lib/active_record/gem_version.rb +15 -0
- data/lib/active_record/inheritance.rb +23 -9
- data/lib/active_record/integration.rb +54 -1
- data/lib/active_record/locking/optimistic.rb +7 -2
- data/lib/active_record/locking/pessimistic.rb +1 -1
- data/lib/active_record/log_subscriber.rb +6 -13
- data/lib/active_record/migration/command_recorder.rb +8 -2
- data/lib/active_record/migration.rb +91 -56
- data/lib/active_record/model_schema.rb +7 -14
- data/lib/active_record/nested_attributes.rb +25 -13
- data/lib/active_record/no_touching.rb +52 -0
- data/lib/active_record/null_relation.rb +26 -6
- data/lib/active_record/persistence.rb +23 -29
- data/lib/active_record/querying.rb +15 -12
- data/lib/active_record/railtie.rb +12 -61
- data/lib/active_record/railties/databases.rake +37 -56
- data/lib/active_record/readonly_attributes.rb +0 -6
- data/lib/active_record/reflection.rb +230 -79
- data/lib/active_record/relation/batches.rb +74 -24
- data/lib/active_record/relation/calculations.rb +52 -48
- data/lib/active_record/relation/delegation.rb +54 -39
- data/lib/active_record/relation/finder_methods.rb +210 -67
- data/lib/active_record/relation/merger.rb +15 -12
- data/lib/active_record/relation/predicate_builder/array_handler.rb +29 -0
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +17 -0
- data/lib/active_record/relation/predicate_builder.rb +81 -40
- data/lib/active_record/relation/query_methods.rb +185 -108
- data/lib/active_record/relation/spawn_methods.rb +8 -5
- data/lib/active_record/relation.rb +79 -84
- data/lib/active_record/result.rb +45 -6
- data/lib/active_record/runtime_registry.rb +5 -0
- data/lib/active_record/sanitization.rb +4 -4
- data/lib/active_record/schema_dumper.rb +18 -6
- data/lib/active_record/schema_migration.rb +31 -18
- data/lib/active_record/scoping/default.rb +5 -18
- data/lib/active_record/scoping/named.rb +14 -29
- data/lib/active_record/scoping.rb +5 -0
- data/lib/active_record/store.rb +67 -18
- data/lib/active_record/tasks/database_tasks.rb +66 -26
- data/lib/active_record/tasks/mysql_database_tasks.rb +16 -10
- data/lib/active_record/tasks/postgresql_database_tasks.rb +1 -1
- data/lib/active_record/tasks/sqlite_database_tasks.rb +5 -1
- data/lib/active_record/timestamp.rb +6 -6
- data/lib/active_record/transactions.rb +10 -12
- data/lib/active_record/validations/presence.rb +1 -1
- data/lib/active_record/validations/uniqueness.rb +19 -9
- data/lib/active_record/version.rb +4 -7
- data/lib/active_record.rb +5 -7
- data/lib/rails/generators/active_record/migration/migration_generator.rb +4 -0
- data/lib/rails/generators/active_record/migration.rb +18 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +4 -0
- data/lib/rails/generators/active_record.rb +2 -8
- metadata +18 -30
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +0 -65
- data/lib/active_record/associations/join_helper.rb +0 -45
- data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +0 -60
- data/lib/active_record/tasks/firebird_database_tasks.rb +0 -56
- data/lib/active_record/tasks/oracle_database_tasks.rb +0 -45
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +0 -48
- data/lib/active_record/test_case.rb +0 -96
data/CHANGELOG.md
CHANGED
@@ -1,2847 +1,2682 @@
|
|
1
|
-
## Rails 4.
|
1
|
+
## Rails 4.1.16 (July 12, 2016) ##
|
2
2
|
|
3
|
-
*
|
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
|
-
|
5
|
+
Specifically, it fixes an issue when using SSL authentication.
|
8
6
|
|
9
|
-
*
|
10
|
-
conflicting private method defined on its ancestors.
|
7
|
+
*Alex Coomans*
|
11
8
|
|
12
|
-
Fixes #11569.
|
13
9
|
|
14
|
-
|
10
|
+
## Rails 4.1.15 (March 07, 2016) ##
|
15
11
|
|
16
|
-
*
|
12
|
+
* Fixes custom primary keys for associations when calling `Relation#where`
|
17
13
|
|
18
|
-
|
14
|
+
Fixes #23327.
|
19
15
|
|
20
|
-
*
|
16
|
+
*Rick Song*
|
21
17
|
|
22
|
-
|
18
|
+
* No longer pass deprecated option `-i` to `pg_dump`.
|
23
19
|
|
24
|
-
*
|
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
|
-
|
23
|
+
## Rails 4.1.14.2 (February 26, 2016) ##
|
30
24
|
|
31
|
-
|
25
|
+
* No changes.
|
32
26
|
|
33
|
-
* When inverting add_index use the index name if present instead of
|
34
|
-
the columns.
|
35
27
|
|
36
|
-
|
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
|
-
|
41
|
-
it is present.
|
30
|
+
* No changes.
|
42
31
|
|
43
|
-
*Hubert Dąbrowski*
|
44
32
|
|
45
|
-
|
33
|
+
## Rails 4.1.14 (November 12, 2015) ##
|
46
34
|
|
47
|
-
|
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
|
-
|
37
|
+
*Paul Sadauskas*
|
51
38
|
|
52
|
-
|
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
|
-
|
42
|
+
Fixes #16032.
|
55
43
|
|
56
|
-
|
57
|
-
not supported by the ActiveRecord schema dumper. For example, expressions
|
58
|
-
indexes would not be detected.
|
44
|
+
Examples:
|
59
45
|
|
60
|
-
|
46
|
+
before:
|
61
47
|
|
62
|
-
|
48
|
+
Project.first.salaried_developers.size # => 3
|
49
|
+
Project.includes(:salaried_developers).first.salaried_developers.size # => 1
|
63
50
|
|
64
|
-
|
51
|
+
after:
|
65
52
|
|
66
|
-
|
67
|
-
|
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
|
-
|
56
|
+
*Bigxiang*
|
72
57
|
|
73
|
-
*Maurício Linhares*
|
74
58
|
|
75
|
-
|
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
|
-
|
61
|
+
* Don't define autosave association callbacks twice from
|
62
|
+
`accepts_nested_attributes_for`.
|
80
63
|
|
81
|
-
|
64
|
+
Fixes #18704.
|
82
65
|
|
83
|
-
*
|
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
|
-
|
69
|
+
## Rails 4.1.12 (June 25, 2015) ##
|
90
70
|
|
91
|
-
|
71
|
+
* Raises the right exception when declares a has many through
|
72
|
+
association with missing source.
|
92
73
|
|
93
|
-
*
|
74
|
+
*Mauro George*
|
94
75
|
|
95
|
-
|
96
|
-
|
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 #
|
79
|
+
Fixes #19545.
|
102
80
|
|
103
|
-
*
|
81
|
+
*Yves Senn*
|
104
82
|
|
105
|
-
* `
|
83
|
+
* Rename `:class` to `:anonymous_class` in association options.
|
106
84
|
|
107
|
-
|
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
|
-
|
87
|
+
*Andrew White*
|
113
88
|
|
114
|
-
|
89
|
+
* Fix referencing wrong table aliases while joining tables of has many through
|
90
|
+
association (only when calling calculation methods).
|
115
91
|
|
116
|
-
|
117
|
-
in `find_in_batches`.
|
92
|
+
Fixes #19276.
|
118
93
|
|
119
|
-
|
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
|
-
|
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
|
-
|
99
|
+
* No changes.
|
130
100
|
|
131
|
-
*Godfrey Chan*
|
132
101
|
|
133
|
-
|
102
|
+
## Rails 4.1.10 (March 19, 2015) ##
|
134
103
|
|
135
|
-
|
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
|
-
|
106
|
+
Fixes #17139.
|
141
107
|
|
142
|
-
*
|
108
|
+
*Miklos Fazekas*
|
143
109
|
|
144
|
-
|
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
|
-
|
113
|
+
Closes #15176.
|
147
114
|
|
148
|
-
|
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
|
-
|
117
|
+
* Respect custom primary keys for associations when calling `Relation#where`
|
154
118
|
|
155
|
-
|
119
|
+
Fixes #18813.
|
156
120
|
|
157
|
-
|
121
|
+
*Sean Griffin*
|
158
122
|
|
159
|
-
|
123
|
+
* Fixed ActiveRecord::Relation#group method when argument is SQL reserved key word:
|
160
124
|
|
161
|
-
|
162
|
-
|
125
|
+
SplitTest.group(:key).count
|
126
|
+
Property.group(:value).count
|
163
127
|
|
164
|
-
*
|
128
|
+
*Bogdan Gusiev*
|
165
129
|
|
166
|
-
*
|
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 #
|
132
|
+
Fixes #12698.
|
172
133
|
|
173
|
-
*
|
134
|
+
*Ivan Antropov*
|
174
135
|
|
175
|
-
* Fixed
|
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
|
-
|
138
|
+
*Andrew McCloud*
|
179
139
|
|
180
|
-
|
140
|
+
* Fix `reaping_frequency` option when the value is a string.
|
181
141
|
|
182
|
-
|
142
|
+
This usually happens when it is configured using `DATABASE_URL`.
|
183
143
|
|
184
|
-
*
|
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
|
-
|
147
|
+
## Rails 4.1.9 (January 6, 2015) ##
|
190
148
|
|
191
|
-
|
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
|
-
|
194
|
-
comment.post.destroy
|
195
|
-
comment.destroy # no longer touches post
|
153
|
+
Closes #17945.
|
196
154
|
|
197
|
-
*
|
155
|
+
*Yves Senn*
|
198
156
|
|
199
|
-
*
|
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
|
-
|
159
|
+
Manual synchronization using `bin/rake db:test:prepare` is required
|
160
|
+
when a migration is rolled-back, edited and reapplied.
|
203
161
|
|
204
|
-
|
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
|
-
|
166
|
+
NOTE: `test:prepare` runs before the schema was synchronized.
|
207
167
|
|
208
|
-
|
209
|
-
particular column, for instance AR attribute query methods has a branch
|
210
|
-
like this:
|
168
|
+
Fixes #17171, #15787.
|
211
169
|
|
212
|
-
|
213
|
-
!value.zero?
|
214
|
-
end
|
170
|
+
*Yves Senn*
|
215
171
|
|
216
|
-
|
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
|
-
|
220
|
-
true for number?/text? checks.
|
174
|
+
Fixes #12856
|
221
175
|
|
222
|
-
*
|
176
|
+
*Sean Griffin*
|
223
177
|
|
224
|
-
*
|
225
|
-
PostgreSQL integer array column.
|
178
|
+
* Make it possible to access fixtures excluded by a `default_scope`.
|
226
179
|
|
227
|
-
|
180
|
+
*Yves Senn*
|
228
181
|
|
229
|
-
|
182
|
+
* `timestamps` and `add_timestamps` passes additional options along.
|
183
|
+
(like `null: false`)
|
230
184
|
|
231
|
-
|
232
|
-
Book.new(ratings: [1, 2]) # worked before
|
233
|
-
Book.new(ratings: ['1', '2']) # now works as well
|
185
|
+
Closes #17624.
|
234
186
|
|
235
|
-
*
|
187
|
+
*Yves Senn*
|
236
188
|
|
237
|
-
* `db:test:clone` and `db:test:prepare` must load Rails environment.
|
238
189
|
|
239
|
-
|
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
|
-
|
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
|
-
*
|
196
|
+
*Ben Woosley*
|
245
197
|
|
246
|
-
|
198
|
+
* Fix preloading of associations which unscope a default scope.
|
247
199
|
|
248
|
-
|
200
|
+
Fixes #11036.
|
249
201
|
|
250
|
-
|
251
|
-
Account.group(:firm_name).sum('0.01 * credit_limit')
|
252
|
-
# => { '37signals' => '0.5' }
|
202
|
+
*Byron Bischoff*
|
253
203
|
|
254
|
-
|
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
|
-
|
206
|
+
Fixes #15931.
|
259
207
|
|
260
|
-
*
|
261
|
-
on an association.
|
208
|
+
*Jeff Browning*
|
262
209
|
|
263
|
-
|
210
|
+
* Allow included modules to override association methods.
|
264
211
|
|
265
|
-
|
212
|
+
Fixes #16684.
|
266
213
|
|
267
|
-
*
|
268
|
-
string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
|
214
|
+
*Yves Senn*
|
269
215
|
|
270
|
-
|
216
|
+
* Schema loading rake tasks (like `db:schema:load` and `db:setup`) maintain
|
217
|
+
the database connection to the current environment.
|
271
218
|
|
272
|
-
|
219
|
+
Fixes #16757.
|
273
220
|
|
274
|
-
*
|
275
|
-
the old and new owner correctly when moved between owners of different types.
|
221
|
+
*Joshua Cody*, *Yves Senn*
|
276
222
|
|
277
|
-
|
223
|
+
* `db:purge` with MySQL respects `Rails.env`.
|
278
224
|
|
279
|
-
|
280
|
-
belongs_to :rateable, polymorphic: true, touch: true
|
281
|
-
end
|
225
|
+
*Yves Senn*
|
282
226
|
|
283
|
-
|
284
|
-
|
227
|
+
* Fixed automatic maintaining test schema to properly handle sql structure
|
228
|
+
schema format.
|
285
229
|
|
286
|
-
|
230
|
+
Fixes #15394.
|
287
231
|
|
288
|
-
*
|
289
|
-
when using unmapped array types in combination with PostgreSQL's `array: true`.
|
232
|
+
*Wojciech Wnętrzak*
|
290
233
|
|
291
|
-
|
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
|
-
|
237
|
+
Fixes #16128.
|
294
238
|
|
295
|
-
|
239
|
+
*Agis Anastasopoulos*
|
296
240
|
|
297
|
-
*Jens Fahnenbruck*, *Yves Senn*
|
298
241
|
|
299
|
-
|
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
|
-
|
244
|
+
* No changes.
|
305
245
|
|
306
|
-
* Update counter cache on a has_many relationship regardless of default scope
|
307
246
|
|
308
|
-
|
247
|
+
## Rails 4.1.7 (October 29, 2014) ##
|
309
248
|
|
310
|
-
|
249
|
+
* No changes.
|
311
250
|
|
312
|
-
* Fix bug when validating the uniqueness of an aliased attribute.
|
313
251
|
|
314
|
-
|
252
|
+
## Rails 4.1.6 (September 11, 2014) ##
|
315
253
|
|
316
|
-
|
254
|
+
* Fixed a regression where whitespaces were stripped from DISTINCT queries in
|
255
|
+
PostgreSQL.
|
317
256
|
|
318
|
-
*
|
257
|
+
*Agis Anastasopoulos*
|
319
258
|
|
320
|
-
|
259
|
+
Fixes #16623.
|
321
260
|
|
322
|
-
*
|
323
|
-
|
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 #
|
265
|
+
Fixes #16288.
|
326
266
|
|
327
|
-
|
267
|
+
* Baseclass becomes! subclass.
|
328
268
|
|
329
|
-
|
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 #
|
272
|
+
Fixes #14785.
|
332
273
|
|
333
|
-
*
|
274
|
+
*Matthew Draper*, *Earl St Sauver*, *Edo Balvers*
|
334
275
|
|
335
|
-
* Fix
|
276
|
+
* Fix regression on after_commit that didnt fire when having nested transactions.
|
336
277
|
|
337
|
-
Fixes #
|
278
|
+
Fixes #16425.
|
338
279
|
|
339
|
-
*
|
280
|
+
*arthurnn*
|
340
281
|
|
341
|
-
*
|
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
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
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
|
-
|
289
|
+
Fixes #16413.
|
351
290
|
|
352
|
-
|
291
|
+
*Rafael Mendonça França*
|
353
292
|
|
354
|
-
|
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
|
-
|
296
|
+
Fixes #16111.
|
357
297
|
|
358
|
-
|
298
|
+
*Andrey Novikov*
|
359
299
|
|
300
|
+
* Restore 4.0 behavior for using serialize attributes with `JSON` as coder.
|
360
301
|
|
361
|
-
|
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
|
-
|
305
|
+
Example:
|
364
306
|
|
365
|
-
|
307
|
+
class Post < ActiveRecord::Base
|
308
|
+
serialize :comment, JSON
|
309
|
+
end
|
366
310
|
|
367
|
-
|
311
|
+
class Comment
|
312
|
+
include ActiveModel::Model
|
313
|
+
attr_accessor :category, :text
|
314
|
+
end
|
368
315
|
|
369
|
-
|
316
|
+
post = Post.create!
|
317
|
+
post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
|
318
|
+
post.save!
|
370
319
|
|
371
|
-
|
320
|
+
# 4.0
|
321
|
+
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
|
372
322
|
|
373
|
-
|
323
|
+
# 4.1 before
|
324
|
+
post.comment # => "#<Comment:0x007f80ab48ff98>"
|
374
325
|
|
375
|
-
|
326
|
+
# 4.1 after
|
327
|
+
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
|
376
328
|
|
377
|
-
|
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
|
-
|
334
|
+
To keep the previous behaviour, supply a custom coder instead
|
335
|
+
([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
|
380
336
|
|
381
|
-
|
337
|
+
Fixes #15594.
|
382
338
|
|
383
|
-
|
384
|
-
record.logged_in_from_ip = 'bad ip address' # raise exception
|
339
|
+
*Jenn Cooper*
|
385
340
|
|
386
|
-
|
387
|
-
|
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
|
-
*
|
344
|
+
*Cade Truitt*
|
392
345
|
|
393
|
-
*
|
346
|
+
* After a successful `reload`, `new_record?` is always false.
|
394
347
|
|
395
|
-
|
348
|
+
Fixes #12101.
|
396
349
|
|
397
|
-
*
|
398
|
-
spaces.
|
350
|
+
*Matthew Draper*
|
399
351
|
|
400
|
-
|
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
|
-
|
355
|
+
Fixes #15705.
|
403
356
|
|
404
|
-
|
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
|
-
|
359
|
+
* Don't error when quoting user defined types in PostgreSQL.
|
409
360
|
|
361
|
+
Fixes #15697.
|
410
362
|
|
411
|
-
|
363
|
+
*Sean Griffin*
|
412
364
|
|
413
|
-
*
|
365
|
+
* Ensure both parent IDs are set on join records when both sides of a
|
366
|
+
through association are new.
|
414
367
|
|
415
|
-
|
368
|
+
*Sean Griffin*
|
416
369
|
|
370
|
+
* Pluck now works when selecting columns from different tables with the same
|
371
|
+
name.
|
417
372
|
|
418
|
-
|
373
|
+
Fixes #15649.
|
419
374
|
|
420
|
-
*
|
375
|
+
*Sean Griffin*
|
421
376
|
|
377
|
+
* `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
|
378
|
+
`Enumerable#find` does.
|
422
379
|
|
423
|
-
|
380
|
+
Fixes #15382.
|
424
381
|
|
425
|
-
*
|
382
|
+
*James Yang*
|
426
383
|
|
427
|
-
|
428
|
-
`
|
384
|
+
* `ActiveRecord::SchemaMigration` has no primary key regardless of the
|
385
|
+
`primary_key_prefix_type` configuration.
|
429
386
|
|
430
|
-
|
387
|
+
Fixes #15051.
|
431
388
|
|
432
|
-
*
|
389
|
+
*JoseLuis Torres*, *Yves Senn*
|
433
390
|
|
434
|
-
|
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
|
-
|
393
|
+
Fixes #15538.
|
440
394
|
|
441
|
-
|
395
|
+
*Yves Senn*
|
442
396
|
|
443
|
-
|
397
|
+
* Fixed `columns_for_distinct` of postgresql adapter to work correctly
|
398
|
+
with orders without sort direction modifiers.
|
444
399
|
|
445
|
-
*
|
400
|
+
*Nikolay Kondratyev*
|
446
401
|
|
447
|
-
|
402
|
+
* Keep PostgreSQL `hstore` and `json` attributes as `Hash` in `@attributes`.
|
403
|
+
Fixes duplication in combination with `store_accessor`.
|
448
404
|
|
449
|
-
|
405
|
+
Fixes #15369.
|
450
406
|
|
451
|
-
*
|
452
|
-
Fixes #11870.
|
407
|
+
*Yves Senn*
|
453
408
|
|
454
|
-
|
409
|
+
* `rake railties:install:migrations` respects the order of railties.
|
455
410
|
|
456
|
-
|
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
|
-
|
414
|
+
## Rails 4.1.5 (August 18, 2014) ##
|
463
415
|
|
464
|
-
*
|
465
|
-
method.
|
416
|
+
* No changes.
|
466
417
|
|
467
|
-
Example:
|
468
418
|
|
469
|
-
|
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
|
-
|
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
|
-
|
423
|
+
*Sean Griffin*, *Matthew Draper*
|
480
424
|
|
481
|
-
*Paul Nikitochkin*
|
482
425
|
|
483
|
-
|
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
|
-
|
428
|
+
* Fix SQL Injection Vulnerability in 'range' quoting.
|
488
429
|
|
489
|
-
|
430
|
+
Fixes CVE-2014-3483
|
490
431
|
|
491
|
-
|
432
|
+
*Rafael Mendonça França*
|
492
433
|
|
493
|
-
*Edo Balvers*
|
494
434
|
|
495
|
-
|
496
|
-
attributes of the where clause.
|
435
|
+
## Rails 4.1.2 (June 26, 2014) ##
|
497
436
|
|
498
|
-
|
437
|
+
* Fix regression on eager loading association based on SQL query rather than
|
438
|
+
existing column.
|
499
439
|
|
500
|
-
|
440
|
+
Fixes #15480.
|
501
441
|
|
502
|
-
*
|
503
|
-
|
504
|
-
|
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
|
-
*
|
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
|
-
*
|
460
|
+
* Fixed serialization for records with an attribute named `format`.
|
513
461
|
|
514
|
-
Fixes #
|
462
|
+
Fixes #15188.
|
515
463
|
|
516
|
-
*
|
464
|
+
*Godfrey Chan*
|
517
465
|
|
518
|
-
* Fixed
|
519
|
-
|
466
|
+
* Fixed serialized fields returning serialized data after being updated with
|
467
|
+
`update_column`.
|
520
468
|
|
521
|
-
|
469
|
+
*Simon Hørup Eskildsen*
|
522
470
|
|
523
|
-
|
471
|
+
* When a `group` is set, `sum`, `size`, `average`, `minimum` and `maximum`
|
472
|
+
on a NullRelation should return a Hash.
|
524
473
|
|
525
|
-
*
|
526
|
-
where constraints and at least of them is not `Arel::Nodes::Equality`,
|
527
|
-
generates invalid SQL expression.
|
474
|
+
*Kuldeep Aggarwal*
|
528
475
|
|
529
|
-
|
476
|
+
* Fixed polymorphic eager loading when using a String as foreign key.
|
530
477
|
|
531
|
-
|
478
|
+
Fixes #14734.
|
532
479
|
|
533
|
-
*
|
480
|
+
*Lauro Caetano*
|
534
481
|
|
535
|
-
|
482
|
+
* Fixed the inferred table name of a has_and_belongs_to_many auxiliar
|
483
|
+
table inside a schema.
|
536
484
|
|
537
|
-
|
485
|
+
Fixes #14824
|
538
486
|
|
539
|
-
*
|
487
|
+
*Eric Chahin*
|
540
488
|
|
541
|
-
*
|
489
|
+
* Fix bug that added `table_name_prefix` and `table_name_suffix` to
|
490
|
+
extension names in PostgreSQL when migrating.
|
542
491
|
|
543
|
-
*
|
492
|
+
*Joao Carlos*
|
544
493
|
|
545
|
-
*
|
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 #
|
497
|
+
Fixes #14135.
|
548
498
|
|
549
|
-
*
|
499
|
+
*Aaron Nelson*
|
550
500
|
|
551
|
-
*
|
552
|
-
|
501
|
+
* Fix how to calculate associated class name when using namespaced has_and_belongs_to_many
|
502
|
+
association.
|
553
503
|
|
554
|
-
|
504
|
+
Fixes #14709.
|
555
505
|
|
556
|
-
*
|
506
|
+
*Kassio Borges*
|
557
507
|
|
558
|
-
|
508
|
+
* `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and
|
509
|
+
strings in column names as equal.
|
559
510
|
|
560
|
-
|
561
|
-
|
562
|
-
|
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
|
-
*
|
515
|
+
*Nat Budin*
|
565
516
|
|
566
|
-
*
|
517
|
+
* Fix `stored_attributes` to correctly merge the details of stored
|
518
|
+
attributes defined in parent classes.
|
567
519
|
|
568
|
-
|
569
|
-
comments for the given post to set the inverse association.
|
520
|
+
Fixes #14672.
|
570
521
|
|
571
|
-
|
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
|
-
|
576
|
-
load the records using full sql.
|
524
|
+
* `change_column_default` allows `[]` as argument to `change_column_default`.
|
577
525
|
|
578
|
-
Fixes #
|
526
|
+
Fixes #11586.
|
579
527
|
|
580
|
-
*
|
528
|
+
*Yves Senn*
|
581
529
|
|
582
|
-
* `
|
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
|
-
|
533
|
+
Example:
|
585
534
|
|
586
|
-
|
535
|
+
# Before
|
536
|
+
Point.create(value: 1.0/0)
|
537
|
+
Point.last.value # => 0.0
|
587
538
|
|
588
|
-
|
539
|
+
# After
|
540
|
+
Point.create(value: 1.0/0)
|
541
|
+
Point.last.value # => Infinity
|
589
542
|
|
590
|
-
*
|
543
|
+
*Innokenty Mikhailov*
|
591
544
|
|
592
|
-
|
545
|
+
* Allow the PostgreSQL adapter to handle bigserial primary key types again.
|
593
546
|
|
594
|
-
|
595
|
-
in order to use `xml` column type instead of `text`.
|
547
|
+
Fixes #10410.
|
596
548
|
|
597
|
-
*
|
549
|
+
*Patrick Robertson*
|
598
550
|
|
599
|
-
*
|
600
|
-
prepend the old one.
|
551
|
+
* Fixed has_and_belongs_to_many's CollectionAssociation size calculation.
|
601
552
|
|
602
|
-
|
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
|
-
|
605
|
-
# SELECT * FROM users ORDER BY created_at desc, name asc
|
556
|
+
Fixes #14913 and #14914.
|
606
557
|
|
607
|
-
|
558
|
+
*Fred Wu*
|
608
559
|
|
609
|
-
|
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
|
-
|
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
|
-
*
|
565
|
+
*Bogdan Gusiev*
|
615
566
|
|
616
|
-
*
|
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
|
-
|
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
|
-
*
|
577
|
+
*James Coleman*
|
623
578
|
|
624
|
-
*
|
579
|
+
* Stringify all variables keys of MySQL connection configuration.
|
625
580
|
|
626
|
-
|
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
|
-
|
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
|
-
*
|
586
|
+
*Paul Nikitochkin*
|
634
587
|
|
635
|
-
*
|
588
|
+
* Ensure SQLite3 statements are closed on errors.
|
636
589
|
|
637
|
-
|
638
|
-
By flattening the array it ensures that string values are detected
|
639
|
-
as strings and not arrays.
|
590
|
+
Fixes #13631.
|
640
591
|
|
641
|
-
|
592
|
+
*Timur Alperovich*
|
642
593
|
|
643
|
-
|
594
|
+
* Fix excluding lower bounds of PostgreSQL date and int ranges.
|
644
595
|
|
645
|
-
*
|
646
|
-
with belongs to reflection with option `touch: true`.
|
596
|
+
*River MacLeod*, *Yves Senn*
|
647
597
|
|
648
|
-
|
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
|
-
|
602
|
+
Fixes #14845.
|
651
603
|
|
652
|
-
*
|
604
|
+
*Kassio Borges*
|
653
605
|
|
654
|
-
|
606
|
+
* `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions.
|
655
607
|
|
656
|
-
|
608
|
+
Fixes #14841.
|
657
609
|
|
658
|
-
|
659
|
-
default_scope -> { where published: true }
|
660
|
-
end
|
610
|
+
*Lucas Mazza*
|
661
611
|
|
662
|
-
|
663
|
-
belongs_to :post
|
664
|
-
end
|
612
|
+
* Fix name collision with `Array#select!` with `Relation#select!`.
|
665
613
|
|
666
|
-
|
667
|
-
comments on published posts, since that is the default scope for
|
668
|
-
posts.
|
614
|
+
Fixes #14752.
|
669
615
|
|
670
|
-
|
671
|
-
so we'd get comments on unpublished posts.
|
616
|
+
*Earl St Sauver*
|
672
617
|
|
673
|
-
|
618
|
+
* Fixed unexpected behavior for `has_many :through` associations going through a scoped `has_many`.
|
674
619
|
|
675
|
-
|
676
|
-
|
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 #
|
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
|
-
|
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
|
-
|
672
|
+
Fixes #13506.
|
686
673
|
|
687
|
-
*
|
688
|
-
closed connection.
|
674
|
+
*Lauro Caetano*
|
689
675
|
|
690
|
-
|
676
|
+
* PostgreSQL adapter only warns once for every missing OID per connection.
|
691
677
|
|
692
|
-
|
678
|
+
Fixes #14275.
|
693
679
|
|
694
|
-
|
680
|
+
*Matthew Draper*, *Yves Senn*
|
695
681
|
|
696
|
-
|
682
|
+
* Fixed error for aggregate methods (`empty?`, `any?`, `count`) with `select`
|
683
|
+
which created invalid SQL.
|
697
684
|
|
698
|
-
|
685
|
+
Fixes #13648.
|
699
686
|
|
700
|
-
|
687
|
+
*Simon Woker*
|
701
688
|
|
702
|
-
|
689
|
+
* Fix insertion of records via `has_many :through` association with scope.
|
703
690
|
|
704
|
-
|
691
|
+
Fixes #3548.
|
705
692
|
|
706
|
-
*
|
693
|
+
*Ivan Antropov*
|
707
694
|
|
708
|
-
*
|
709
|
-
|
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
|
-
|
716
|
+
* Fixed error when specifying a non-empty default value on a PostgreSQL array column.
|
712
717
|
|
713
|
-
|
718
|
+
Fixes #10613.
|
714
719
|
|
715
|
-
|
720
|
+
*Luke Steensen*
|
716
721
|
|
717
|
-
|
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
|
-
|
725
|
+
Fixes #14393.
|
720
726
|
|
721
|
-
*
|
727
|
+
*Chris Finne*
|
722
728
|
|
723
|
-
*
|
724
|
-
|
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
|
-
|
732
|
+
Fixes #14217.
|
729
733
|
|
730
|
-
*
|
734
|
+
*Yves Senn*
|
731
735
|
|
732
|
-
|
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
|
-
|
736
|
-
change_table :users do |t|
|
737
|
-
t.remove_index [:name, :email]
|
738
|
-
end
|
739
|
-
end
|
738
|
+
Fixes #14361.
|
740
739
|
|
741
|
-
|
740
|
+
*arthurnn*
|
742
741
|
|
743
|
-
|
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
|
-
*
|
746
|
+
*Alan Kennedy*
|
746
747
|
|
747
748
|
|
748
|
-
## Rails 4.
|
749
|
+
## Rails 4.1.1 (May 6, 2014) ##
|
749
750
|
|
750
|
-
*
|
751
|
+
* No changes.
|
751
752
|
|
752
|
-
* Do not overwrite manually built records during one-to-one nested attribute assignment
|
753
753
|
|
754
|
-
|
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
|
-
|
759
|
-
|
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
|
-
|
763
|
-
super || build_avatar(width: 200)
|
764
|
-
end
|
765
|
-
end
|
759
|
+
Fixes #14607.
|
766
760
|
|
767
|
-
|
768
|
-
member.avatar_attributes = {icon: 'sad'}
|
769
|
-
member.avatar.width # => 200
|
761
|
+
*Evan Whalen*
|
770
762
|
|
771
|
-
*Olek Janiszewski*
|
772
763
|
|
773
|
-
*
|
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
|
-
|
766
|
+
For instance, this will raise:
|
779
767
|
|
780
|
-
|
781
|
-
is not blank.
|
768
|
+
scope :public, -> { where(status: 1) }
|
782
769
|
|
783
|
-
|
784
|
-
being picked up in `method_missing`.
|
770
|
+
*arthurnn*
|
785
771
|
|
786
|
-
|
787
|
-
|
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
|
-
|
775
|
+
The current "correct" spellings for in-memory, relative, and
|
776
|
+
absolute URLs, respectively, are:
|
792
777
|
|
793
|
-
|
778
|
+
sqlite3::memory:
|
779
|
+
sqlite3:relative/path
|
780
|
+
sqlite3:/full/path
|
794
781
|
|
795
|
-
|
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
|
-
*
|
787
|
+
*Matthew Draper*
|
798
788
|
|
799
|
-
*
|
789
|
+
* `where.not` adds `references` for `includes` like normal `where` calls do.
|
800
790
|
|
801
|
-
|
791
|
+
Fixes #14406.
|
802
792
|
|
803
|
-
*
|
793
|
+
*Yves Senn*
|
804
794
|
|
805
|
-
*
|
795
|
+
* `includes` is able to detect the right preloading strategy when string
|
796
|
+
joins are involved.
|
806
797
|
|
807
|
-
|
798
|
+
Fixes #14109.
|
808
799
|
|
809
|
-
*
|
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
|
-
|
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
|
-
|
817
|
-
when record was pushed into a has_many association. For example:
|
806
|
+
Fixes #14172.
|
818
807
|
|
819
|
-
|
808
|
+
*Vilius Luneckas* *Ahmed AbouElhamayed*
|
820
809
|
|
821
|
-
|
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
|
-
|
816
|
+
Fixes #14144.
|
824
817
|
|
825
|
-
*
|
826
|
-
|
818
|
+
* Fixed STI classes not defining an attribute method if there is a
|
819
|
+
conflicting private method defined on its ancestors.
|
827
820
|
|
828
|
-
|
829
|
-
post.respond_to?(:body) # => false
|
821
|
+
Fixes #11569.
|
830
822
|
|
831
|
-
|
832
|
-
post.respond_to?(:title) # => false
|
823
|
+
*Godfrey Chan*
|
833
824
|
|
834
|
-
|
825
|
+
* Default scopes are no longer overriden by chained conditions.
|
835
826
|
|
836
|
-
|
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
|
-
|
831
|
+
Before:
|
839
832
|
|
840
|
-
|
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
|
-
|
839
|
+
User.all
|
840
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
|
843
841
|
|
844
|
-
|
842
|
+
User.active
|
843
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'active'
|
845
844
|
|
846
|
-
|
847
|
-
|
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
|
-
|
848
|
+
After:
|
851
849
|
|
852
|
-
|
853
|
-
|
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
|
-
|
856
|
+
User.all
|
857
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
|
857
858
|
|
858
|
-
|
859
|
-
|
859
|
+
User.active
|
860
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'pending' AND "users"."state" = 'active'
|
860
861
|
|
861
|
-
|
862
|
+
User.where(state: 'inactive')
|
863
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'pending' AND "users"."state" = 'inactive'
|
862
864
|
|
863
|
-
|
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
|
-
|
866
|
-
belongs_to :post
|
867
|
-
end
|
869
|
+
Example:
|
868
870
|
|
869
|
-
class
|
870
|
-
|
871
|
+
class User < ActiveRecord::Base
|
872
|
+
default_scope { where state: 'pending' }
|
873
|
+
scope :active, -> { unscope(where: :state).where(state: 'active') }
|
874
|
+
scope :inactive, -> { rewhere state: 'inactive' }
|
871
875
|
end
|
872
876
|
|
873
|
-
|
874
|
-
|
875
|
-
has_many :comments
|
876
|
-
end
|
877
|
+
User.all
|
878
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
|
877
879
|
|
878
|
-
|
879
|
-
|
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
|
-
|
883
|
-
|
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
|
-
|
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
|
-
|
888
|
+
Fixes #11135.
|
893
889
|
|
894
|
-
*
|
890
|
+
*Josh Goodall*, *Genadi Samokovarov*
|
895
891
|
|
896
|
-
|
892
|
+
* Properly detect if a connection is still active before using it
|
893
|
+
in multi-threaded environments.
|
897
894
|
|
898
|
-
|
899
|
-
schema correctly.
|
895
|
+
Fixes #12867.
|
900
896
|
|
901
|
-
*
|
897
|
+
*Kevin Casey*, *Matthew Draper*, *William (B.J.) Snow Orvis*
|
902
898
|
|
903
|
-
*
|
904
|
-
|
905
|
-
after the block.
|
899
|
+
* When inverting add_index use the index name if present instead of
|
900
|
+
the columns.
|
906
901
|
|
907
|
-
|
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
|
-
|
910
|
-
|
911
|
-
end
|
906
|
+
The inversion of add_index will now drop the index by its name if
|
907
|
+
it is present.
|
912
908
|
|
913
|
-
|
909
|
+
*Hubert Dąbrowski*
|
914
910
|
|
915
|
-
|
916
|
-
child.parent.equal?(parent) # true
|
911
|
+
* Add flag to disable schema dump after migration.
|
917
912
|
|
918
|
-
|
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
|
-
*
|
921
|
-
through association.
|
922
|
-
Fixes #10016.
|
917
|
+
*Emil Soman*
|
923
918
|
|
924
|
-
|
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
|
-
|
927
|
-
transitioning to new association.
|
922
|
+
See also #13938.
|
928
923
|
|
929
|
-
|
930
|
-
belongs_to :car, touch: true
|
931
|
-
end
|
924
|
+
*Marc-André Lafortune*
|
932
925
|
|
933
|
-
|
934
|
-
car_2 = Car.create
|
926
|
+
* Make sure transaction state gets reset after a commit operation on the record.
|
935
927
|
|
936
|
-
|
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
|
-
|
939
|
-
passenger.save
|
931
|
+
Fixes #12566.
|
940
932
|
|
941
|
-
|
942
|
-
will be touched.
|
933
|
+
*arthurnn*
|
943
934
|
|
944
|
-
|
935
|
+
* Pass `has_and_belongs_to_many` `:autosave` option to
|
936
|
+
the underlying `has_many :through` association.
|
945
937
|
|
946
|
-
|
947
|
-
These tasks should be supported by 3rd-party adapter.
|
938
|
+
Fixes #13923.
|
948
939
|
|
949
|
-
*
|
940
|
+
*Yves Senn*
|
950
941
|
|
951
|
-
*
|
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
|
-
|
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
|
-
|
958
|
-
Fixes #3493.
|
948
|
+
Fixes #11018.
|
959
949
|
|
960
|
-
*
|
950
|
+
*Jonathan Baudanza*
|
961
951
|
|
962
|
-
* PostgreSQL
|
952
|
+
* Parsing PostgreSQL arrays with empty strings now works correctly.
|
963
953
|
|
964
|
-
|
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
|
-
|
967
|
-
`algorithm: :concurrently` option.
|
959
|
+
Fixes #13907.
|
968
960
|
|
969
|
-
|
961
|
+
*Maurício Linhares*
|
970
962
|
|
971
|
-
|
972
|
-
`DEFAULT`) via the `:algorithm` option.
|
963
|
+
* Associations now raise `ArgumentError` on name conflicts.
|
973
964
|
|
974
|
-
|
965
|
+
Dangerous association names conflicts include instance or class methods already
|
966
|
+
defined by `ActiveRecord::Base`.
|
975
967
|
|
976
|
-
|
968
|
+
Example:
|
977
969
|
|
978
|
-
|
979
|
-
|
970
|
+
class Car < ActiveRecord::Base
|
971
|
+
has_many :errors
|
972
|
+
end
|
973
|
+
# Will raise ArgumentError.
|
980
974
|
|
981
|
-
|
982
|
-
add_index(:people, :last_name, type: 'SPATIAL')
|
975
|
+
Fixes #13217.
|
983
976
|
|
984
|
-
*
|
977
|
+
*Lauro Caetano*
|
985
978
|
|
986
|
-
*
|
987
|
-
|
988
|
-
|
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
|
-
|
984
|
+
Fixes #7538, #12017, #13731, #12056.
|
991
985
|
|
992
|
-
*
|
986
|
+
*arthurnn*
|
993
987
|
|
994
|
-
*
|
995
|
-
|
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
|
-
|
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
|
-
|
1003
|
-
See #7706.
|
997
|
+
Fixes #13861.
|
1004
998
|
|
1005
|
-
*
|
999
|
+
*Maurício Linhares*
|
1006
1000
|
|
1007
|
-
*
|
1008
|
-
|
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
|
-
*
|
1004
|
+
*Marc-André Lafortune*
|
1015
1005
|
|
1016
|
-
* `
|
1017
|
-
Fixes #8079.
|
1006
|
+
* `enum` now raises on "dangerous" name conflicts.
|
1018
1007
|
|
1019
|
-
|
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
|
-
|
1022
|
-
created by the `mysql2` adapter is 191 if the encoding is "utf8mb4".
|
1013
|
+
Fixes #13389.
|
1023
1014
|
|
1024
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
1041
|
-
belongs_to :post, counter_cache: true
|
1042
|
-
end
|
1025
|
+
*Godfrey Chan*, *Philippe Creux*
|
1043
1026
|
|
1044
|
-
|
1045
|
-
has_many :comments
|
1046
|
-
end
|
1027
|
+
* Correctly send an user provided statement to a `lock!()` call.
|
1047
1028
|
|
1048
|
-
|
1049
|
-
|
1029
|
+
person.lock! 'FOR SHARE NOWAIT'
|
1030
|
+
# Before: SELECT * ... LIMIT 1 FOR UPDATE
|
1031
|
+
# After: SELECT * ... LIMIT 1 FOR SHARE NOWAIT
|
1050
1032
|
|
1051
|
-
|
1052
|
-
post.save.reload.comments_count # => 1
|
1053
|
-
comment.update_attributes(post_id: nil)
|
1033
|
+
Fixes #13788.
|
1054
1034
|
|
1055
|
-
|
1035
|
+
*Maurício Linhares*
|
1056
1036
|
|
1057
|
-
|
1058
|
-
also keep the count accurate.
|
1037
|
+
* Handle aliased attributes `select()`, `order()` and `reorder()`.
|
1059
1038
|
|
1060
|
-
*
|
1039
|
+
*Tsutomu Kuroda*
|
1061
1040
|
|
1062
|
-
*
|
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
|
-
|
1043
|
+
Before:
|
1068
1044
|
|
1069
|
-
#
|
1070
|
-
|
1045
|
+
post.comments.loaded? # => true
|
1046
|
+
post.comments.reset
|
1047
|
+
post.comments.loaded? # => true
|
1071
1048
|
|
1072
|
-
|
1073
|
-
ActiveRecord::Base.disable_implicit_join_references = true
|
1049
|
+
After:
|
1074
1050
|
|
1075
|
-
|
1051
|
+
post.comments.loaded? # => true
|
1052
|
+
post.comments.reset
|
1053
|
+
post.comments.loaded? # => false
|
1076
1054
|
|
1077
|
-
|
1078
|
-
should use `Relation#distinct` instead.
|
1055
|
+
Fixes #13777.
|
1079
1056
|
|
1080
|
-
|
1057
|
+
*Kelsey Schlarman*
|
1081
1058
|
|
1082
|
-
|
1083
|
-
Post.select(:author_name).count(distinct: true)
|
1059
|
+
* Make enum fields work as expected with the `ActiveModel::Dirty` API.
|
1084
1060
|
|
1085
|
-
|
1086
|
-
Post.select(:author_name).distinct.count
|
1061
|
+
Before this change, using the dirty API would have surprising results:
|
1087
1062
|
|
1088
|
-
|
1063
|
+
conversation = Conversation.new
|
1064
|
+
conversation.status = :active
|
1065
|
+
conversation.status = :archived
|
1066
|
+
conversation.status_was # => 0
|
1089
1067
|
|
1090
|
-
|
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
|
-
|
1070
|
+
conversation = Conversation.new
|
1071
|
+
conversation.status = :active
|
1072
|
+
conversation.status = :archived
|
1073
|
+
conversation.status_was # => "active"
|
1096
1074
|
|
1097
|
-
*
|
1098
|
-
columns.
|
1075
|
+
*Rafael Mendonça França*
|
1099
1076
|
|
1100
|
-
|
1101
|
-
|
1102
|
-
correctly.
|
1077
|
+
* `has_one` and `belongs_to` accessors don't add ORDER BY to the queries
|
1078
|
+
anymore.
|
1103
1079
|
|
1104
|
-
|
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
|
-
|
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
|
-
*
|
1088
|
+
*Rafael Mendonça França*
|
1112
1089
|
|
1113
|
-
*
|
1114
|
-
the constraint lookup.
|
1090
|
+
* Prepend table name for column names passed to `Relation#select`.
|
1115
1091
|
|
1116
1092
|
Example:
|
1117
1093
|
|
1118
|
-
|
1094
|
+
Post.select(:id)
|
1095
|
+
# Before: => SELECT id FROM "posts"
|
1096
|
+
# After: => SELECT "posts"."id" FROM "posts"
|
1119
1097
|
|
1120
|
-
*
|
1098
|
+
*Yves Senn*
|
1121
1099
|
|
1122
|
-
*
|
1123
|
-
|
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
|
-
|
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
|
-
*
|
1107
|
+
*Alexander Balashov*
|
1129
1108
|
|
1130
|
-
|
1109
|
+
* Ensure `second` through `fifth` methods act like the `first` finder.
|
1131
1110
|
|
1132
|
-
|
1133
|
-
|
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
|
-
|
1116
|
+
Fixes #13743.
|
1136
1117
|
|
1137
|
-
|
1138
|
-
index by the conventional name.
|
1118
|
+
Example:
|
1139
1119
|
|
1140
|
-
|
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
|
-
|
1122
|
+
# Before
|
1123
|
+
# => 'SELECT "users".* FROM "users"'
|
1147
1124
|
|
1148
|
-
|
1149
|
-
|
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
|
-
|
1128
|
+
User.offset(3).second
|
1153
1129
|
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
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
|
-
|
1135
|
+
# After
|
1136
|
+
# => SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 OFFSET 4'
|
1159
1137
|
|
1160
|
-
*
|
1161
|
-
class methods which return scopes. For example:
|
1138
|
+
*Jason Meller*
|
1162
1139
|
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
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
|
-
|
1169
|
-
def self.active
|
1170
|
-
where state: 'active'
|
1171
|
-
end
|
1144
|
+
Fixes #13744.
|
1172
1145
|
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
end
|
1146
|
+
*Godfrey Chan*
|
1147
|
+
|
1148
|
+
* Make `touch` fire the `after_commit` and `after_rollback` callbacks.
|
1177
1149
|
|
1178
|
-
|
1150
|
+
*Harry Brundage*
|
1179
1151
|
|
1180
|
-
|
1181
|
-
# => SELECT * FROM users WHERE state = 'active' AND state = 'inactive'
|
1152
|
+
* Enable partial indexes for `sqlite >= 3.8.0`.
|
1182
1153
|
|
1183
|
-
|
1184
|
-
# => SELECT * FROM users WHERE state = 'inactive'
|
1154
|
+
See http://www.sqlite.org/partialindex.html
|
1185
1155
|
|
1186
|
-
|
1187
|
-
# => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
|
1156
|
+
*Cody Cutrer*
|
1188
1157
|
|
1189
|
-
|
1158
|
+
* Don't try to get the subclass if the inheritance column doesn't exist
|
1190
1159
|
|
1191
|
-
|
1192
|
-
|
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
|
-
|
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
|
-
|
1200
|
-
it like so:
|
1167
|
+
* Enum mappings are now exposed via class methods instead of constants.
|
1201
1168
|
|
1202
|
-
|
1169
|
+
Example:
|
1203
1170
|
|
1204
|
-
|
1171
|
+
class Conversation < ActiveRecord::Base
|
1172
|
+
enum status: [ :active, :archived ]
|
1173
|
+
end
|
1205
1174
|
|
1206
|
-
|
1175
|
+
Before:
|
1207
1176
|
|
1208
|
-
|
1177
|
+
Conversation::STATUS # => { "active" => 0, "archived" => 1 }
|
1209
1178
|
|
1210
|
-
|
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
|
-
|
1181
|
+
Conversation.statuses # => { "active" => 0, "archived" => 1 }
|
1217
1182
|
|
1218
|
-
*
|
1183
|
+
*Godfrey Chan*
|
1219
1184
|
|
1220
|
-
|
1185
|
+
* Set `NameError#name` when STI-class-lookup fails.
|
1221
1186
|
|
1222
|
-
*
|
1223
|
-
`mysqldump` is not in the PATH or fails.
|
1224
|
-
Fixes #9518.
|
1187
|
+
*Chulki Lee*
|
1225
1188
|
|
1226
|
-
|
1189
|
+
* Fix bug in `becomes!` when changing from the base model to a STI sub-class.
|
1227
1190
|
|
1228
|
-
|
1191
|
+
Fixes #13272.
|
1229
1192
|
|
1230
|
-
*
|
1231
|
-
if the database adapter supports DDL transactions.
|
1232
|
-
Fixes #9483.
|
1193
|
+
*the-web-dev*, *Yves Senn*
|
1233
1194
|
|
1234
|
-
|
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
|
-
|
1237
|
-
disable_ddl_transaction!
|
1254
|
+
*Richard Schneeman*
|
1238
1255
|
|
1239
|
-
|
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
|
-
*
|
1247
|
-
Fixes #9034.
|
1260
|
+
* Don't create/drop the test database if RAILS_ENV is specified explicitly.
|
1248
1261
|
|
1249
|
-
|
1262
|
+
Previously, when the environment was development, we would always
|
1263
|
+
create or drop both the test and development databases.
|
1250
1264
|
|
1251
|
-
|
1252
|
-
|
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
|
-
*
|
1268
|
+
*Damien Mathieu*
|
1257
1269
|
|
1258
|
-
*
|
1259
|
-
|
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
|
-
|
1273
|
+
*Dylan Thacker-Smith*
|
1262
1274
|
|
1263
|
-
|
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
|
-
|
1266
|
-
== User.where(name: "John")
|
1280
|
+
Fixes #13577, #13503.
|
1267
1281
|
|
1268
|
-
|
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
|
-
|
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
|
-
|
1275
|
-
ActiveSupport::TimeWithZone instance instead of a string
|
1287
|
+
Fixes #13570.
|
1276
1288
|
|
1277
|
-
*
|
1289
|
+
*Thales Oliveira*
|
1278
1290
|
|
1279
|
-
*
|
1280
|
-
|
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
|
-
*
|
1286
|
-
|
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
|
-
|
1301
|
+
rake db:schema:load RAILS_ENV=test
|
1289
1302
|
|
1290
|
-
|
1291
|
-
the listed attributes, without creating a model.
|
1292
|
-
|
1293
|
-
*Sammy Larbi*
|
1303
|
+
*Jon Leighton*
|
1294
1304
|
|
1295
|
-
* Fix
|
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
|
-
*
|
1307
|
+
*gmarik*
|
1300
1308
|
|
1301
|
-
*
|
1302
|
-
|
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
|
-
|
1312
|
+
Fixes #13437.
|
1305
1313
|
|
1306
|
-
|
1307
|
-
t.hstore :books
|
1308
|
-
t.json :metadata
|
1309
|
-
end
|
1314
|
+
*Vipul A M*, *khustochka*
|
1310
1315
|
|
1311
|
-
|
1316
|
+
* Add the ability to nullify the `enum` column.
|
1312
1317
|
|
1313
|
-
|
1318
|
+
Example:
|
1314
1319
|
|
1315
|
-
|
1320
|
+
class Conversation < ActiveRecord::Base
|
1321
|
+
enum gender: [:female, :male]
|
1322
|
+
end
|
1316
1323
|
|
1317
|
-
|
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
|
-
|
1326
|
+
# conversation.update! gender: 0
|
1327
|
+
conversation.female!
|
1328
|
+
conversation.female? # => true
|
1329
|
+
conversation.gender # => "female"
|
1324
1330
|
|
1325
|
-
|
1326
|
-
|
1331
|
+
# conversation.update! gender: nil
|
1332
|
+
conversation.gender = nil
|
1333
|
+
conversation.gender.nil? # => true
|
1334
|
+
conversation.gender # => nil
|
1327
1335
|
|
1328
|
-
|
1336
|
+
*Amr Tamimi*
|
1329
1337
|
|
1330
|
-
*
|
1331
|
-
|
1332
|
-
|
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
|
-
|
1342
|
+
*Richard Schneeman*
|
1335
1343
|
|
1336
|
-
|
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
|
-
|
1346
|
+
Example:
|
1340
1347
|
|
1341
|
-
|
1348
|
+
User.where.not(nil)
|
1342
1349
|
|
1343
|
-
|
1350
|
+
# Before
|
1351
|
+
# => 'SELECT `users`.* FROM `users` WHERE (NOT (NULL))'
|
1344
1352
|
|
1345
|
-
|
1353
|
+
# After
|
1354
|
+
# => ArgumentError, 'Invalid argument for .where.not(), got nil.'
|
1346
1355
|
|
1347
|
-
*
|
1348
|
-
new object that has not yet been persisted. For instance:
|
1356
|
+
*Kuldeep Aggarwal*
|
1349
1357
|
|
1350
|
-
|
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
|
-
|
1353
|
-
ball.touch :updated_at # => raises error
|
1361
|
+
*José Valim*
|
1354
1362
|
|
1355
|
-
|
1356
|
-
|
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
|
-
|
1366
|
+
Fixes #12261.
|
1359
1367
|
|
1360
|
-
*
|
1361
|
-
invalid ordering to the `:through` association.
|
1362
|
-
Fixes #8663.
|
1368
|
+
*Tadas Tamosauskas*, *Carlos Antonio da Silva*
|
1363
1369
|
|
1364
|
-
|
1370
|
+
* Do not consider PostgreSQL array columns as number or text columns.
|
1365
1371
|
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
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
|
-
|
1371
|
-
|
1376
|
+
if column.number?
|
1377
|
+
!value.zero?
|
1378
|
+
end
|
1372
1379
|
|
1373
|
-
|
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
|
-
|
1376
|
-
|
1377
|
-
Fixes #988.
|
1383
|
+
Fixing this by ensuring that array columns in PostgreSQL never return
|
1384
|
+
true for number?/text? checks.
|
1378
1385
|
|
1379
|
-
|
1386
|
+
*Carlos Antonio da Silva*
|
1380
1387
|
|
1381
|
-
|
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
|
-
*
|
1393
|
+
*Richard Schneeman*
|
1384
1394
|
|
1385
|
-
*
|
1386
|
-
|
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
|
-
|
1398
|
+
Fixes #13445.
|
1389
1399
|
|
1390
|
-
|
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
|
-
|
1402
|
+
# Given Comment has belongs_to :post, touch: true
|
1403
|
+
comment.post.destroy
|
1404
|
+
comment.destroy # no longer raises an error
|
1397
1405
|
|
1398
|
-
*
|
1406
|
+
*Paul Nikitochkin*
|
1399
1407
|
|
1400
|
-
|
1401
|
-
|
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
|
-
|
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
|
-
|
1415
|
-
in which case the AR object has to recursively follow parent pointers of
|
1416
|
-
TransactionState objects.
|
1413
|
+
Example:
|
1417
1414
|
|
1418
|
-
|
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
|
-
*
|
1421
|
-
Fixes #7313.
|
1419
|
+
*Damien Mathieu*
|
1422
1420
|
|
1423
|
-
|
1421
|
+
* Fix `PostgreSQL` insert to properly extract table name from multiline string SQL.
|
1424
1422
|
|
1425
|
-
|
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
|
-
|
1425
|
+
insert into articles(
|
1426
|
+
number)
|
1427
|
+
values(
|
1428
|
+
5152
|
1429
|
+
)
|
1429
1430
|
|
1430
|
-
|
1431
|
+
would not work because the adapter was unable to extract the correct `articles`
|
1432
|
+
table name.
|
1431
1433
|
|
1432
|
-
*
|
1434
|
+
*Kuldeep Aggarwal*
|
1433
1435
|
|
1434
|
-
*
|
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
|
-
|
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
|
-
|
1445
|
-
|
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
|
-
|
1449
|
-
|
1443
|
+
It intends to prevent odd bugs and confusion in code that call mutator
|
1444
|
+
methods directly on the `Relation`.
|
1450
1445
|
|
1451
|
-
|
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
|
-
#
|
1458
|
-
|
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
|
-
|
1464
|
-
|
1451
|
+
# Now you have to do this
|
1452
|
+
authors = Author.where(name: 'Hank Moody').to_a
|
1453
|
+
authors.compact!
|
1465
1454
|
|
1466
|
-
|
1467
|
-
=> Wed, 13 Feb 2013 00:00:00 UTC +00:00
|
1455
|
+
*Lauro Caetano*
|
1468
1456
|
|
1469
|
-
|
1470
|
-
|
1457
|
+
* Better support for `where()` conditions that use a `belongs_to`
|
1458
|
+
association name.
|
1471
1459
|
|
1472
|
-
|
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
|
-
|
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
|
-
|
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
|
1482
|
-
|
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
|
-
|
1487
|
-
|
1488
|
-
# This is preloaded.
|
1489
|
-
a_user.recent_comments
|
1475
|
+
`nil` value finds records where the association is not set:
|
1490
1476
|
|
1491
|
-
|
1492
|
-
|
1477
|
+
Post.where(author: nil)
|
1478
|
+
# SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL
|
1493
1479
|
|
1494
|
-
|
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
|
-
|
1497
|
-
|
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
|
-
|
1488
|
+
`ActiveRecord::Relation` values find records using the same
|
1489
|
+
query as `Post.where(author_id: Author.where(last_name: "Emde"))`
|
1500
1490
|
|
1501
|
-
|
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
|
-
|
1504
|
-
|
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
|
-
|
1507
|
-
|
1508
|
-
end
|
1502
|
+
class Post < ActiveRecord::Base
|
1503
|
+
belongs_to :author, polymorphic: true
|
1509
1504
|
end
|
1510
1505
|
|
1511
|
-
|
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
|
-
*
|
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
|
-
|
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
|
-
|
1514
|
+
Normal DROP TABLE also works, but commits the transaction.
|
1527
1515
|
|
1528
|
-
|
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
|
-
|
1518
|
+
*Cody Cutrer*
|
1534
1519
|
|
1535
|
-
|
1536
|
-
DATABASE_URL=postgresql://localhost/test_db?prepared_statements=false
|
1520
|
+
* Add option to create tables from a query.
|
1537
1521
|
|
1538
|
-
|
1522
|
+
create_table(:long_query, temporary: true,
|
1523
|
+
as: "SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id")
|
1539
1524
|
|
1540
|
-
|
1541
|
-
merge. Consider:
|
1525
|
+
Generates:
|
1542
1526
|
|
1543
|
-
|
1544
|
-
|
1527
|
+
CREATE TEMPORARY TABLE long_query AS
|
1528
|
+
SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id
|
1545
1529
|
|
1546
|
-
|
1530
|
+
*Cody Cutrer*
|
1547
1531
|
|
1548
|
-
|
1532
|
+
* `db:test:clone` and `db:test:prepare` must load Rails environment.
|
1549
1533
|
|
1550
|
-
`
|
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
|
-
|
1537
|
+
*arthurnn*
|
1553
1538
|
|
1554
|
-
|
1555
|
-
condition being removed:
|
1539
|
+
* Use the right column to type cast grouped calculations with custom expressions.
|
1556
1540
|
|
1557
|
-
|
1541
|
+
Fixes #13230.
|
1558
1542
|
|
1559
|
-
|
1560
|
-
the RHS remains as it is:
|
1543
|
+
Example:
|
1561
1544
|
|
1562
|
-
|
1545
|
+
# Before
|
1546
|
+
Account.group(:firm_name).sum('0.01 * credit_limit')
|
1547
|
+
# => { '37signals' => '0.5' }
|
1563
1548
|
|
1564
|
-
|
1549
|
+
# After
|
1550
|
+
Account.group(:firm_name).sum('0.01 * credit_limit')
|
1551
|
+
# => { '37signals' => 0.5 }
|
1565
1552
|
|
1566
|
-
*
|
1553
|
+
*Paul Nikitochkin*
|
1567
1554
|
|
1568
|
-
|
1569
|
-
|
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
|
-
|
1577
|
-
|
1578
|
-
|
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
|
-
|
1584
|
-
|
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
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
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
|
-
*
|
1572
|
+
*John Bachir*
|
1593
1573
|
|
1594
|
-
*
|
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
|
-
|
1578
|
+
Model.offset(4).last
|
1579
|
+
# => returns the 4th record from the end.
|
1600
1580
|
|
1601
|
-
|
1581
|
+
Fixes #7441.
|
1602
1582
|
|
1603
|
-
*
|
1604
|
-
numrange, tsrange, tstzrange, daterange
|
1583
|
+
*kostya*, *Lauro Caetano*
|
1605
1584
|
|
1606
|
-
|
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
|
-
|
1611
|
-
|
1612
|
-
|
1590
|
+
change_colum :table, :column, :bigint, array: true
|
1591
|
+
|
1592
|
+
Fixes #13146.
|
1613
1593
|
|
1614
|
-
|
1615
|
-
Room.first.availability # => Wed, 19 Sep 2012..Infinity
|
1594
|
+
*Jens Fahnenbruck*, *Yves Senn*
|
1616
1595
|
|
1617
|
-
|
1618
|
-
|
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
|
-
*
|
1599
|
+
*Vipul A M*
|
1621
1600
|
|
1622
|
-
*
|
1623
|
-
|
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
|
-
*
|
1605
|
+
*Victor Costan*
|
1626
1606
|
|
1627
|
-
*
|
1628
|
-
|
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
|
-
|
1611
|
+
*Godfrey Chan*
|
1631
1612
|
|
1632
|
-
|
1633
|
-
widget.things.build
|
1634
|
-
widget.things.empty? # => false
|
1613
|
+
* Implement `rename_index` natively for MySQL >= 5.7.
|
1635
1614
|
|
1636
|
-
*
|
1615
|
+
*Cody Cutrer*
|
1637
1616
|
|
1638
|
-
*
|
1617
|
+
* Fix bug when validating the uniqueness of an aliased attribute.
|
1639
1618
|
|
1640
|
-
|
1619
|
+
Fixes #12402.
|
1641
1620
|
|
1642
|
-
*
|
1643
|
-
Array; Fix FloatDomainError when setting integer column to NaN.
|
1644
|
-
Fixes #8718, #8734, #8757.
|
1621
|
+
*Lauro Caetano*
|
1645
1622
|
|
1646
|
-
|
1623
|
+
* Update counter cache on a `has_many` relationship regardless of default scope.
|
1647
1624
|
|
1648
|
-
|
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
|
-
*
|
1627
|
+
*Uku Taht*
|
1654
1628
|
|
1655
|
-
* `
|
1656
|
-
|
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
|
-
|
1632
|
+
Cannot drop index 'index_engines_on_car_id': needed in a foreign key constraint
|
1659
1633
|
|
1660
|
-
*
|
1634
|
+
*Cody Cutrer*, *Yves Senn*
|
1661
1635
|
|
1662
|
-
|
1663
|
-
|
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
|
-
|
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
|
-
*
|
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
|
-
|
1674
|
-
raise an `IrreversibleMigration` instead of actually executing them without any output.
|
1643
|
+
* Fix validation on uniqueness of empty association.
|
1675
1644
|
|
1676
|
-
*
|
1645
|
+
*Evgeny Li*
|
1677
1646
|
|
1678
|
-
*
|
1679
|
-
Fixes #8575.
|
1647
|
+
* Make `ActiveRecord::Relation#unscope` affect relations it is merged in to.
|
1680
1648
|
|
1681
|
-
*
|
1649
|
+
*Jon Leighton*
|
1682
1650
|
|
1683
|
-
*
|
1684
|
-
Fixes #3489.
|
1651
|
+
* Use strings to represent non-string `order_values`.
|
1685
1652
|
|
1686
1653
|
*Yves Senn*
|
1687
1654
|
|
1688
|
-
*
|
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
|
-
*
|
1694
|
-
Fixes #8075.
|
1657
|
+
*Edo Balvers*
|
1695
1658
|
|
1696
|
-
|
1659
|
+
* Added `ActiveRecord::Base.to_param` for convenient "pretty" URLs derived from a model's attribute or method.
|
1697
1660
|
|
1698
|
-
|
1661
|
+
Example:
|
1699
1662
|
|
1700
|
-
|
1663
|
+
class User < ActiveRecord::Base
|
1664
|
+
to_param :name
|
1665
|
+
end
|
1701
1666
|
|
1702
|
-
|
1667
|
+
user = User.find_by(name: 'Fancy Pants')
|
1668
|
+
user.id # => 123
|
1669
|
+
user.to_param # => "123-fancy-pants"
|
1703
1670
|
|
1704
|
-
*
|
1671
|
+
*Javan Makhmali*
|
1705
1672
|
|
1706
|
-
*
|
1707
|
-
associations.
|
1673
|
+
* Added `ActiveRecord::Base.no_touching`, which allows ignoring touch on models.
|
1708
1674
|
|
1709
|
-
|
1675
|
+
Example:
|
1710
1676
|
|
1711
|
-
|
1712
|
-
|
1677
|
+
Post.no_touching do
|
1678
|
+
Post.first.touch
|
1679
|
+
end
|
1713
1680
|
|
1714
|
-
*
|
1681
|
+
*Sam Stephenson*, *Damien Mathieu*
|
1715
1682
|
|
1716
|
-
*
|
1717
|
-
|
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
|
-
|
1686
|
+
Fixes #11079.
|
1721
1687
|
|
1722
|
-
*
|
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
|
-
|
1690
|
+
* Unify boolean type casting for `MysqlAdapter` and `Mysql2Adapter`.
|
1691
|
+
`type_cast` will return `1` for `true` and `0` for `false`.
|
1729
1692
|
|
1730
|
-
|
1731
|
-
http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS
|
1693
|
+
Fixes #11119.
|
1732
1694
|
|
1733
|
-
*
|
1695
|
+
*Adam Williams*, *Yves Senn*
|
1734
1696
|
|
1735
|
-
*
|
1697
|
+
* Fix bug where `has_one` association record update result in crash, when replaced with itself.
|
1736
1698
|
|
1737
|
-
|
1699
|
+
Fixes #12834.
|
1738
1700
|
|
1739
|
-
|
1701
|
+
*Denis Redozubov*, *Sergio Cambra*
|
1740
1702
|
|
1741
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
1755
|
-
user.active = false
|
1756
|
-
user.save!
|
1714
|
+
Fixes #12790.
|
1757
1715
|
|
1758
|
-
|
1716
|
+
*Jason Ayre*
|
1759
1717
|
|
1760
|
-
|
1761
|
-
update the record based on the primary key. With this change:
|
1718
|
+
* `.unscope` now removes conditions specified in `default_scope`.
|
1762
1719
|
|
1763
|
-
|
1720
|
+
*Jon Leighton*
|
1764
1721
|
|
1765
|
-
|
1722
|
+
* Added `ActiveRecord::QueryMethods#rewhere` which will overwrite an existing, named where condition.
|
1766
1723
|
|
1767
|
-
|
1724
|
+
Examples:
|
1768
1725
|
|
1769
|
-
|
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
|
-
*
|
1730
|
+
*DHH*
|
1772
1731
|
|
1773
|
-
*
|
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
|
-
|
1734
|
+
Example:
|
1778
1735
|
|
1779
|
-
|
1780
|
-
|
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
|
-
*
|
1739
|
+
*DHH*
|
1784
1740
|
|
1785
|
-
*
|
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
|
-
|
1743
|
+
Example:
|
1793
1744
|
|
1794
|
-
|
1745
|
+
class Conversation < ActiveRecord::Base
|
1746
|
+
enum status: [:active, :archived]
|
1747
|
+
end
|
1795
1748
|
|
1796
|
-
|
1749
|
+
Conversation::STATUS # => { active: 0, archived: 1 }
|
1797
1750
|
|
1798
|
-
|
1751
|
+
# conversation.update! status: 0
|
1752
|
+
conversation.active!
|
1753
|
+
conversation.active? # => true
|
1754
|
+
conversation.status # => "active"
|
1799
1755
|
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1756
|
+
# conversation.update! status: 1
|
1757
|
+
conversation.archived!
|
1758
|
+
conversation.archived? # => true
|
1759
|
+
conversation.status # => "archived"
|
1804
1760
|
|
1805
|
-
|
1761
|
+
# conversation.update! status: 1
|
1762
|
+
conversation.status = :archived
|
1806
1763
|
|
1807
|
-
*
|
1808
|
-
Fixes #8265.
|
1764
|
+
*DHH*
|
1809
1765
|
|
1810
|
-
|
1766
|
+
* `ActiveRecord::Base#attribute_for_inspect` now truncates long arrays (more than 10 elements).
|
1811
1767
|
|
1812
|
-
*
|
1813
|
-
the array result of the relation, use `to_a.sum(&block)`.
|
1768
|
+
*Jan Bernacki*
|
1814
1769
|
|
1815
|
-
|
1770
|
+
* Allow for the name of the `schema_migrations` table to be configured.
|
1816
1771
|
|
1817
|
-
*
|
1772
|
+
*Jerad Phelps*
|
1818
1773
|
|
1819
|
-
|
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
|
-
|
1777
|
+
Example:
|
1822
1778
|
|
1823
|
-
|
1824
|
-
|
1779
|
+
class Vendor < ActiveRecord::Base
|
1780
|
+
has_many :relationships, -> { includes(:user) }
|
1781
|
+
has_many :users, through: :relationships
|
1782
|
+
end
|
1825
1783
|
|
1826
|
-
|
1784
|
+
vendor = Vendor.first
|
1827
1785
|
|
1828
|
-
|
1829
|
-
Add `ActiveRecord::Base#becomes!` with the previous behavior.
|
1786
|
+
# Before
|
1830
1787
|
|
1831
|
-
|
1788
|
+
vendor.users.to_a # => Raises exception: not found `:user` for `User`
|
1832
1789
|
|
1833
|
-
|
1790
|
+
# After
|
1834
1791
|
|
1835
|
-
|
1792
|
+
vendor.users.to_a # => No exception is raised
|
1836
1793
|
|
1837
|
-
|
1838
|
-
t.rename_index :user_id, :account_id
|
1839
|
-
end
|
1794
|
+
Fixes #12242, #9517, #10240.
|
1840
1795
|
|
1841
|
-
*
|
1796
|
+
*Paul Nikitochkin*
|
1842
1797
|
|
1843
|
-
*
|
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
|
-
|
1848
|
-
|
1849
|
-
*Yves Senn*
|
1803
|
+
x = JsonDataType.new tags: {"string" => "foo", :symbol => :bar}
|
1850
1804
|
|
1851
|
-
|
1805
|
+
# Before:
|
1806
|
+
x.tags # => {"string" => "foo", :symbol => :bar}
|
1852
1807
|
|
1853
|
-
|
1808
|
+
# After:
|
1809
|
+
x.tags # => {"string" => "foo", "symbol" => "bar"}
|
1854
1810
|
|
1855
|
-
|
1856
|
-
User.new.build_profile
|
1811
|
+
*Severin Schoepke*
|
1857
1812
|
|
1858
|
-
|
1813
|
+
* `ActiveRecord::Store` works together with PostgreSQL `hstore` columns.
|
1859
1814
|
|
1860
|
-
|
1861
|
-
Fixes #7993.
|
1815
|
+
Fixes #12452.
|
1862
1816
|
|
1863
1817
|
*Yves Senn*
|
1864
1818
|
|
1865
|
-
*
|
1866
|
-
|
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
|
-
|
1869
|
-
|
1870
|
-
*Rafael Mendonça França*
|
1823
|
+
*Yves Senn*
|
1871
1824
|
|
1872
|
-
*
|
1825
|
+
* Save `has_one` association when primary key is manually set.
|
1873
1826
|
|
1874
|
-
|
1827
|
+
Fixes #12302.
|
1875
1828
|
|
1876
|
-
*
|
1829
|
+
*Lauro Caetano*
|
1877
1830
|
|
1878
|
-
|
1831
|
+
* Allow any version of BCrypt when using `has_secure_password`.
|
1879
1832
|
|
1880
|
-
*
|
1833
|
+
*Mike Perham*
|
1881
1834
|
|
1882
|
-
|
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
|
-
|
1885
|
-
Fixes #6951.
|
1838
|
+
Generate sub-query with inline bind values.
|
1886
1839
|
|
1887
|
-
|
1840
|
+
Fixes #12586.
|
1888
1841
|
|
1889
|
-
*
|
1842
|
+
*Paul Nikitochkin*
|
1890
1843
|
|
1891
|
-
|
1844
|
+
* Fix a bug where rake db:structure:load crashed when the path contained
|
1845
|
+
spaces.
|
1892
1846
|
|
1893
|
-
*
|
1894
|
-
Fixes #6378.
|
1847
|
+
*Kevin Mook*
|
1895
1848
|
|
1896
|
-
|
1849
|
+
* `ActiveRecord::QueryMethods#unscope` unscopes negative equality
|
1897
1850
|
|
1898
|
-
|
1899
|
-
|
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
|
-
|
1902
|
-
belongs_to :company
|
1903
|
-
end
|
1855
|
+
*Eric Hankins*
|
1904
1856
|
|
1905
|
-
|
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
|
-
|
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
|
-
|
1861
|
+
* Make `Relation#empty?` use `exists?` instead of `count`.
|
1920
1862
|
|
1921
|
-
*
|
1863
|
+
*Szymon Nowak*
|
1922
1864
|
|
1923
|
-
|
1865
|
+
* `rake db:structure:dump` no longer crashes when the port was specified as `Fixnum`.
|
1924
1866
|
|
1925
|
-
*
|
1867
|
+
*Kenta Okamoto*
|
1926
1868
|
|
1927
|
-
|
1869
|
+
* `NullRelation#pluck` takes a list of columns
|
1928
1870
|
|
1929
|
-
|
1930
|
-
`
|
1871
|
+
The method signature in `NullRelation` was updated to mimic that in
|
1872
|
+
`Calculations`.
|
1931
1873
|
|
1932
|
-
|
1933
|
-
the behaviour when a record is created is slightly different:
|
1874
|
+
*Derek Prior*
|
1934
1875
|
|
1935
|
-
|
1876
|
+
* `scope_chain` should not be mutated for other reflections.
|
1936
1877
|
|
1937
|
-
|
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
|
-
|
1883
|
+
Fix is to dup the value before adding to the `scope_chain`.
|
1940
1884
|
|
1941
|
-
|
1942
|
-
the scope. This could affect queries that occur within callbacks.
|
1885
|
+
Fixes #3882.
|
1943
1886
|
|
1944
|
-
|
1887
|
+
*Neeraj Singh*
|
1945
1888
|
|
1946
|
-
|
1889
|
+
* Prevent the inversed association from being reloaded on save.
|
1947
1890
|
|
1948
|
-
|
1891
|
+
Fixes #9499.
|
1949
1892
|
|
1950
|
-
|
1951
|
-
callbacks.
|
1893
|
+
*Dmitry Polushkin*
|
1952
1894
|
|
1953
|
-
|
1895
|
+
* Generate subquery for `Relation` if it passed as array condition for `where`
|
1896
|
+
method.
|
1954
1897
|
|
1955
|
-
|
1898
|
+
Example:
|
1956
1899
|
|
1957
|
-
|
1958
|
-
|
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
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
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
|
-
|
1910
|
+
Fixes #12415.
|
1966
1911
|
|
1967
|
-
*
|
1968
|
-
when the association was blank. Bug introduced in 1fab518c6a75dac5773654646eb724a59741bc13.
|
1912
|
+
*Paul Nikitochkin*
|
1969
1913
|
|
1970
|
-
|
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
|
-
*
|
1973
|
-
Fixes #7439
|
1918
|
+
*Paul Nikitochkin*
|
1974
1919
|
|
1975
|
-
|
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
|
-
*
|
1923
|
+
* `create_savepoint`, `rollback_to_savepoint` and `release_savepoint` accept
|
1924
|
+
a savepoint name.
|
1978
1925
|
|
1979
|
-
*
|
1926
|
+
*Yves Senn*
|
1980
1927
|
|
1981
|
-
*
|
1928
|
+
* Make `next_migration_number` accessible for third party generators.
|
1982
1929
|
|
1983
|
-
|
1984
|
-
If we pass invalid direction(like name: :DeSc) ActiveRecord::QueryMethods#order will raise an exception
|
1930
|
+
*Yves Senn*
|
1985
1931
|
|
1986
|
-
|
1987
|
-
|
1932
|
+
* Objects instantiated using a null relationship will now retain the
|
1933
|
+
attributes of the where clause.
|
1988
1934
|
|
1989
|
-
|
1935
|
+
Fixes #11676, #11675, #11376.
|
1990
1936
|
|
1991
|
-
*
|
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
|
-
|
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
|
-
*
|
2004
|
-
Fixes #5920.
|
1943
|
+
*arthurnn*
|
2005
1944
|
|
2006
|
-
|
1945
|
+
* Callbacks on has_many should access the in memory parent if a inverse_of is set.
|
2007
1946
|
|
2008
|
-
*
|
2009
|
-
parent record is not persisted.
|
1947
|
+
*arthurnn*
|
2010
1948
|
|
2011
|
-
|
1949
|
+
* `ActiveRecord::ConnectionAdapters.string_to_time` respects
|
1950
|
+
string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
|
2012
1951
|
|
2013
|
-
|
2014
|
-
# SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
|
2015
|
-
# => 0
|
1952
|
+
Fixes #12278.
|
2016
1953
|
|
2017
|
-
|
1954
|
+
*kennyj*
|
2018
1955
|
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
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
|
-
|
1960
|
+
Example:
|
2024
1961
|
|
2025
|
-
|
2026
|
-
Fixes #7822.
|
1962
|
+
@my_comment.update_attributes(nil) # => raises ArgumentError
|
2027
1963
|
|
2028
|
-
*
|
1964
|
+
*John Wang*
|
2029
1965
|
|
2030
|
-
*
|
1966
|
+
* Deprecate `quoted_locking_column` method, which isn't used anywhere.
|
2031
1967
|
|
2032
|
-
|
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
|
-
|
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
|
-
|
2042
|
-
`partial_writes` to reflect the fact that it now impacts both inserts
|
2043
|
-
and updates.
|
1972
|
+
Fixes #10751.
|
2044
1973
|
|
2045
|
-
*
|
1974
|
+
*kennyj*
|
2046
1975
|
|
2047
|
-
*
|
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
|
-
|
1979
|
+
Fixes #10450.
|
2050
1980
|
|
2051
|
-
*
|
1981
|
+
*kennyj*
|
2052
1982
|
|
2053
|
-
|
2054
|
-
|
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
|
-
|
2057
|
-
# ...
|
2058
|
-
end
|
1987
|
+
Fixes #11963.
|
2059
1988
|
|
2060
|
-
|
1989
|
+
*Paul Nikitochkin*
|
2061
1990
|
|
2062
|
-
|
2063
|
-
|
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
|
-
|
2068
|
-
semantics of these different levels:
|
1994
|
+
*Lann Martin*
|
2069
1995
|
|
2070
|
-
|
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
|
-
|
1998
|
+
*Damien Mathieu*
|
2074
1999
|
|
2075
|
-
|
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
|
-
|
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
|
-
|
2004
|
+
* Fix inserts with prepared statements disabled.
|
2085
2005
|
|
2086
|
-
|
2087
|
-
in Active Record models. Check the docs of `ActiveModel::ForbiddenAttributesProtection`
|
2088
|
-
for more details.
|
2006
|
+
Fixes #12023.
|
2089
2007
|
|
2090
|
-
*
|
2008
|
+
*Rafael Mendonça França*
|
2091
2009
|
|
2092
|
-
*
|
2093
|
-
|
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
|
-
*
|
2013
|
+
*Dylan Thacker-Smith*
|
2099
2014
|
|
2100
|
-
* Fix
|
2101
|
-
Fixes #6971.
|
2015
|
+
* Fix `AR::Relation#merge` sometimes failing to preserve `readonly(false)` flag.
|
2102
2016
|
|
2103
|
-
|
2017
|
+
*thedarkone*
|
2104
2018
|
|
2105
|
-
|
2019
|
+
* Re-use `order` argument pre-processing for `reorder`.
|
2106
2020
|
|
2107
|
-
|
2021
|
+
*Paul Nikitochkin*
|
2108
2022
|
|
2109
|
-
|
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
|
-
|
2027
|
+
*Mikhail Dieterle*
|
2112
2028
|
|
2113
|
-
|
2029
|
+
* PostgreSQL adapter recognizes negative money values formatted with
|
2030
|
+
parentheses (eg. `($1.25) # => -1.25`)).
|
2031
|
+
Fixes #11899.
|
2114
2032
|
|
2115
|
-
*
|
2116
|
-
on a `has_many :through` association from an unsaved model.
|
2117
|
-
Fixes #7661.
|
2033
|
+
*Yves Senn*
|
2118
2034
|
|
2119
|
-
|
2035
|
+
* Stop interpreting SQL 'string' columns as :string type because there is no
|
2036
|
+
common STRING datatype in SQL.
|
2120
2037
|
|
2121
|
-
*
|
2122
|
-
Fix problem that explains unexplainable sql.
|
2123
|
-
Fixes #7544 #6458.
|
2038
|
+
*Ben Woosley*
|
2124
2039
|
|
2125
|
-
|
2040
|
+
* `ActiveRecord::FinderMethods#exists?` returns `true`/`false` in all cases.
|
2126
2041
|
|
2127
|
-
*
|
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
|
-
|
2044
|
+
* Assign inet/cidr attribute with `nil` value for invalid address.
|
2132
2045
|
|
2133
|
-
|
2046
|
+
Example:
|
2134
2047
|
|
2135
|
-
|
2048
|
+
record = User.new
|
2049
|
+
record.logged_in_from_ip # is type of an inet or a cidr
|
2136
2050
|
|
2137
|
-
|
2138
|
-
|
2051
|
+
# Before:
|
2052
|
+
record.logged_in_from_ip = 'bad ip address' # raise exception
|
2139
2053
|
|
2140
|
-
|
2141
|
-
|
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
|
-
*
|
2059
|
+
*Paul Nikitochkin*
|
2144
2060
|
|
2145
|
-
*
|
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
|
-
|
2063
|
+
If truthy, it will skip the :before_add and :after_add callbacks.
|
2149
2064
|
|
2150
|
-
*
|
2065
|
+
*Ben Woosley*
|
2151
2066
|
|
2152
|
-
|
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
|
-
|
2155
|
-
|
2071
|
+
- A `:before_add` callback was being called when a nested attributes
|
2072
|
+
assignment assigned to an existing record.
|
2156
2073
|
|
2157
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
2178
|
-
|
2084
|
+
* Type cast hstore values on write, so that the value is consistent
|
2085
|
+
with reading from the database.
|
2179
2086
|
|
2180
|
-
|
2087
|
+
Example:
|
2181
2088
|
|
2182
|
-
|
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
|
-
|
2091
|
+
# Before:
|
2092
|
+
x.tags # => {"bool" => true, "number" => 5}
|
2187
2093
|
|
2188
|
-
|
2189
|
-
|
2094
|
+
# After:
|
2095
|
+
x.tags # => {"bool" => "true", "number" => "5"}
|
2190
2096
|
|
2191
|
-
*
|
2097
|
+
*Yves Senn* , *Severin Schoepke*
|
2192
2098
|
|
2193
|
-
*
|
2099
|
+
* Fix multidimensional PostgreSQL arrays containing non-string items.
|
2194
2100
|
|
2195
2101
|
*Yves Senn*
|
2196
2102
|
|
2197
|
-
*
|
2198
|
-
|
2199
|
-
*Kelley Reynolds*
|
2103
|
+
* Fixes bug when using includes combined with select, the select statement was overwritten.
|
2200
2104
|
|
2201
|
-
|
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
|
-
*
|
2107
|
+
*Edo Balvers*
|
2206
2108
|
|
2207
|
-
*
|
2208
|
-
Fixes #7532.
|
2109
|
+
* Load fixtures from linked folders.
|
2209
2110
|
|
2210
|
-
*
|
2111
|
+
*Kassio Borges*
|
2211
2112
|
|
2212
|
-
*
|
2213
|
-
Fixes #7532.
|
2113
|
+
* Create a directory for sqlite3 file if not present on the system.
|
2214
2114
|
|
2215
|
-
*
|
2115
|
+
*Richard Schneeman*
|
2216
2116
|
|
2217
|
-
*
|
2117
|
+
* Removed redundant override of `xml` column definition for PostgreSQL,
|
2118
|
+
in order to use `xml` column type instead of `text`.
|
2218
2119
|
|
2219
|
-
*
|
2120
|
+
*Paul Nikitochkin*, *Michael Nikitochkin*
|
2220
2121
|
|
2221
|
-
*
|
2222
|
-
|
2122
|
+
* Revert `ActiveRecord::Relation#order` change that make new order
|
2123
|
+
prepend the old one.
|
2223
2124
|
|
2224
|
-
|
2125
|
+
Before:
|
2225
2126
|
|
2226
|
-
|
2127
|
+
User.order("name asc").order("created_at desc")
|
2128
|
+
# SELECT * FROM users ORDER BY created_at desc, name asc
|
2227
2129
|
|
2228
|
-
|
2130
|
+
After:
|
2229
2131
|
|
2230
|
-
|
2132
|
+
User.order("name asc").order("created_at desc")
|
2133
|
+
# SELECT * FROM users ORDER BY name asc, created_at desc
|
2231
2134
|
|
2232
|
-
|
2135
|
+
This also affects order defined in `default_scope` or any kind of associations.
|
2233
2136
|
|
2234
|
-
*
|
2235
|
-
|
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
|
-
|
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
|
-
*
|
2240
|
-
same foreign key and one of them have a counter cache.
|
2241
|
-
Fixes #5200.
|
2145
|
+
*Sean Griffin & @joannecheng*
|
2242
2146
|
|
2243
|
-
|
2147
|
+
* Don't allow `quote_value` to be called without a column.
|
2244
2148
|
|
2245
|
-
|
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
|
-
*
|
2154
|
+
*Ben Woosley*
|
2248
2155
|
|
2249
|
-
*
|
2250
|
-
|
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
|
-
|
2160
|
+
Fixes #6763.
|
2253
2161
|
|
2254
|
-
*
|
2162
|
+
*Alfred Wong*
|
2255
2163
|
|
2256
|
-
|
2164
|
+
* rescue from all exceptions in `ConnectionManagement#call`
|
2257
2165
|
|
2258
|
-
|
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
|
-
|
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
|
-
|
2265
|
-
|
2173
|
+
Rescuing from all exceptions and not just StandardError, fixes this
|
2174
|
+
behaviour.
|
2266
2175
|
|
2267
|
-
*
|
2176
|
+
*Vipul A M*
|
2268
2177
|
|
2269
|
-
*
|
2178
|
+
* `change_column` for PostgreSQL adapter respects the `:array` option.
|
2270
2179
|
|
2271
|
-
*
|
2180
|
+
*Yves Senn*
|
2272
2181
|
|
2273
|
-
*
|
2274
|
-
raised. Fixes #3217.
|
2182
|
+
* Remove deprecation warning from `attribute_missing` for attributes that are columns.
|
2275
2183
|
|
2276
|
-
*
|
2184
|
+
*Arun Agrawal*
|
2277
2185
|
|
2278
|
-
*
|
2186
|
+
* Remove extra decrement of transaction deep level.
|
2279
2187
|
|
2280
|
-
|
2188
|
+
Fixes #4566.
|
2281
2189
|
|
2282
|
-
*
|
2283
|
-
Fixes #4772.
|
2190
|
+
*Paul Nikitochkin*
|
2284
2191
|
|
2285
|
-
|
2192
|
+
* Reset @column_defaults when assigning `locking_column`.
|
2193
|
+
We had a potential problem. For example:
|
2286
2194
|
|
2287
|
-
|
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
|
-
|
2290
|
-
|
2200
|
+
Post.column_defaults["my_locking_column"]
|
2201
|
+
=> nil # expected value is 0 !
|
2291
2202
|
|
2292
|
-
|
2203
|
+
*kennyj*
|
2293
2204
|
|
2294
|
-
|
2295
|
-
|
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
|
-
|
2301
|
-
extend Commentable
|
2302
|
-
has_many_comments -> { where(:bar) }
|
2303
|
-
end
|
2208
|
+
Fixes #11288.
|
2304
2209
|
|
2305
|
-
*
|
2210
|
+
*Paul Nikitochkin*
|
2306
2211
|
|
2307
|
-
*
|
2212
|
+
* Remove deprecated nil-passing to the following `SchemaCache` methods:
|
2213
|
+
`primary_keys`, `tables`, `columns` and `columns_hash`.
|
2308
2214
|
|
2309
|
-
|
2215
|
+
*Yves Senn*
|
2310
2216
|
|
2311
|
-
|
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
|
-
|
2219
|
+
*Yves Senn*
|
2315
2220
|
|
2316
|
-
|
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
|
-
*
|
2223
|
+
*Yves Senn*
|
2324
2224
|
|
2325
|
-
*
|
2225
|
+
* Remove deprecated `scope` use without passing a callable object.
|
2326
2226
|
|
2327
|
-
|
2227
|
+
*Arun Agrawal*
|
2328
2228
|
|
2329
|
-
|
2330
|
-
|
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
|
-
|
2232
|
+
*Arun Agrawal*
|
2335
2233
|
|
2336
|
-
|
2234
|
+
* Remove deprecated `decrement_open_transactions`.
|
2337
2235
|
|
2338
|
-
*
|
2236
|
+
*Arun Agrawal*
|
2339
2237
|
|
2340
|
-
*
|
2238
|
+
* Remove deprecated `increment_open_transactions`.
|
2341
2239
|
|
2342
|
-
|
2343
|
-
# SELECT * FROM users ORDER BY created_at desc, name asc
|
2240
|
+
*Arun Agrawal*
|
2344
2241
|
|
2345
|
-
|
2242
|
+
* Remove deprecated `PostgreSQLAdapter#outside_transaction?`
|
2243
|
+
method. You can use `#transaction_open?` instead.
|
2346
2244
|
|
2347
|
-
*
|
2245
|
+
*Yves Senn*
|
2348
2246
|
|
2349
|
-
*
|
2350
|
-
|
2247
|
+
* Remove deprecated `ActiveRecord::Fixtures.find_table_name` in favor of
|
2248
|
+
`ActiveRecord::Fixtures.default_fixture_model_name`.
|
2351
2249
|
|
2352
|
-
|
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
|
-
|
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
|
-
|
2254
|
+
*Neeraj Singh*
|
2361
2255
|
|
2362
|
-
|
2363
|
-
would serve no purpose if we made it return a `Relation`).
|
2256
|
+
* Remove deprecated `SchemaStatements#distinct`.
|
2364
2257
|
|
2365
|
-
*
|
2258
|
+
*Francesco Rodriguez*
|
2366
2259
|
|
2367
|
-
*
|
2368
|
-
|
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
|
-
*
|
2264
|
+
*Yves Senn*
|
2371
2265
|
|
2372
|
-
*
|
2373
|
-
associations
|
2374
|
-
:through`.
|
2266
|
+
* Removed support for deprecated option `:restrict` for `:dependent`
|
2267
|
+
in associations.
|
2375
2268
|
|
2376
|
-
*
|
2269
|
+
*Neeraj Singh*
|
2377
2270
|
|
2378
|
-
*
|
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
|
-
|
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
|
-
|
2275
|
+
* Removed support for deprecated `insert_sql` in associations.
|
2388
2276
|
|
2389
|
-
*
|
2390
|
-
the migration name contains the word `join_table`:
|
2277
|
+
*Neeraj Singh*
|
2391
2278
|
|
2392
|
-
|
2279
|
+
* Removed support for deprecated `finder_sql` in associations.
|
2393
2280
|
|
2394
|
-
*
|
2281
|
+
*Neeraj Singh*
|
2395
2282
|
|
2396
|
-
*
|
2397
|
-
and `remove_belongs_to` are acceptable. References are reversible.
|
2283
|
+
* Support array as root element in JSON fields.
|
2398
2284
|
|
2399
|
-
|
2285
|
+
*Alexey Noskov & Francesco Rodriguez*
|
2400
2286
|
|
2401
|
-
|
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
|
-
*
|
2289
|
+
*Neeraj Singh*
|
2409
2290
|
|
2410
|
-
*
|
2291
|
+
* Do not invoke callbacks when `delete_all` is called on collection.
|
2411
2292
|
|
2412
|
-
|
2413
|
-
|
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
|
-
|
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
|
-
*
|
2418
|
-
dealing with a `Relation` object rather than an array:.
|
2302
|
+
*Neeraj Singh*
|
2419
2303
|
|
2420
|
-
|
2421
|
-
# => <ActiveRecord::Relation [#<User ...>, #<User ...>, ...]>
|
2304
|
+
* Calling default_scope without a proc will now raise `ArgumentError`.
|
2422
2305
|
|
2423
|
-
|
2424
|
-
# => [#<User ...>, #<User ...>]
|
2306
|
+
*Neeraj Singh*
|
2425
2307
|
|
2426
|
-
|
2308
|
+
* Removed deprecated method `type_cast_code` from Column.
|
2427
2309
|
|
2428
|
-
*
|
2310
|
+
*Neeraj Singh*
|
2429
2311
|
|
2430
|
-
*
|
2431
|
-
|
2312
|
+
* Removed deprecated options `delete_sql` and `insert_sql` from HABTM
|
2313
|
+
association.
|
2432
2314
|
|
2433
|
-
|
2434
|
-
|
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
|
-
*
|
2318
|
+
*Neeraj Singh*
|
2444
2319
|
|
2445
|
-
*
|
2446
|
-
|
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
|
-
*
|
2323
|
+
*Yves Senn*
|
2451
2324
|
|
2452
|
-
*
|
2325
|
+
* Remove deprecation warning for `auto_explain_threshold_in_seconds`.
|
2453
2326
|
|
2454
|
-
*
|
2327
|
+
*Yves Senn*
|
2455
2328
|
|
2456
|
-
*
|
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
|
-
|
2461
|
-
create_table :foobars do |t|
|
2462
|
-
t.timestamps precision: 0
|
2463
|
-
end
|
2464
|
-
end
|
2331
|
+
*Yves Senn*
|
2465
2332
|
|
2466
|
-
|
2333
|
+
* Removed deprecated methods `partial_updates`, `partial_updates?` and
|
2334
|
+
`partial_updates=`.
|
2467
2335
|
|
2468
|
-
*
|
2469
|
-
array of arrays containing the typecasted values:
|
2336
|
+
*Neeraj Singh*
|
2470
2337
|
|
2471
|
-
|
2472
|
-
# SELECT people.id, people.name FROM people
|
2473
|
-
# [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]
|
2338
|
+
* Removed deprecated method `scoped`.
|
2474
2339
|
|
2475
|
-
*
|
2340
|
+
*Neeraj Singh*
|
2476
2341
|
|
2477
|
-
*
|
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
|
-
|
2344
|
+
*Neeraj Singh*
|
2482
2345
|
|
2483
|
-
|
2484
|
-
Old: categories_products
|
2485
|
-
New: categories_products
|
2346
|
+
* Remove implicit join references that were deprecated in 4.0.
|
2486
2347
|
|
2487
|
-
|
2488
|
-
Old: site_categories_products
|
2489
|
-
New: site_categories_products
|
2348
|
+
Example:
|
2490
2349
|
|
2491
|
-
|
2492
|
-
|
2493
|
-
New: categories_products
|
2350
|
+
# before with implicit joins
|
2351
|
+
Comment.where('posts.author_id' => 7)
|
2494
2352
|
|
2495
|
-
|
2496
|
-
|
2497
|
-
New: admin_categories_products
|
2353
|
+
# after
|
2354
|
+
Comment.references(:posts).where('posts.author_id' => 7)
|
2498
2355
|
|
2499
|
-
|
2500
|
-
Old: categories_products
|
2501
|
-
New: catalog_categories_products
|
2356
|
+
*Yves Senn*
|
2502
2357
|
|
2503
|
-
|
2504
|
-
Old: categories_pages
|
2505
|
-
New: catalog_categories_content_pages
|
2358
|
+
* Apply default scope when joining associations. For example:
|
2506
2359
|
|
2507
|
-
|
2360
|
+
class Post < ActiveRecord::Base
|
2361
|
+
default_scope -> { where published: true }
|
2362
|
+
end
|
2508
2363
|
|
2509
|
-
|
2510
|
-
|
2511
|
-
|
2512
|
-
validity checks.
|
2364
|
+
class Comment
|
2365
|
+
belongs_to :post
|
2366
|
+
end
|
2513
2367
|
|
2514
|
-
|
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
|
-
|
2517
|
-
|
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
|
-
|
2521
|
-
store :settings, accessors: [:color, :homepage]
|
2522
|
-
end
|
2375
|
+
*Jon Leighton*
|
2523
2376
|
|
2524
|
-
|
2377
|
+
* Remove `activerecord-deprecated_finders` as a dependency.
|
2525
2378
|
|
2526
|
-
|
2379
|
+
*Łukasz Strzałkowski*
|
2527
2380
|
|
2528
|
-
*
|
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
|
-
*
|
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
|
-
*
|
2544
|
-
`ActiveRecord::RecordNotDestroyed` exception instead of returning `false`.
|
2388
|
+
*Ben Woosley*
|
2545
2389
|
|
2546
|
-
|
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
|
-
*
|
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
|
-
|
2553
|
-
has_many :pets
|
2554
|
-
end
|
2395
|
+
* Flatten merged join_values before building the joins.
|
2555
2396
|
|
2556
|
-
|
2557
|
-
|
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
|
-
|
2401
|
+
Fixes #10669.
|
2560
2402
|
|
2561
|
-
*
|
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
|
-
|
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
|
-
|
2576
|
-
|
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
|
-
|
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
|
-
|
2581
|
-
|
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
|
-
|
2417
|
+
Fixes #10509.
|
2585
2418
|
|
2586
|
-
|
2419
|
+
*Neeraj Singh*
|
2587
2420
|
|
2588
|
-
|
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
|
-
|
2426
|
+
Example:
|
2591
2427
|
|
2592
|
-
|
2428
|
+
Author.inspect # => "Author(no database connection)"
|
2593
2429
|
|
2594
|
-
|
2595
|
-
finder usage in your application.
|
2430
|
+
*Yves Senn*
|
2596
2431
|
|
2597
|
-
|
2598
|
-
|
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
|
-
|
2603
|
-
* `:include` becomes `:includes`.
|
2435
|
+
*Dylan Markow*
|
2604
2436
|
|
2605
|
-
|
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
|
-
|
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
|
-
|
2444
|
+
Do not squeeze whitespace out of sql queries. Fixes #10982.
|
2614
2445
|
|
2615
|
-
*
|
2446
|
+
*Neeraj Singh*
|
2616
2447
|
|
2617
|
-
*
|
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
|
-
|
2620
|
-
Record.from(subquery, :a)
|
2451
|
+
*Yves Senn*
|
2621
2452
|
|
2622
|
-
|
2453
|
+
* Fix mysql2 adapter raises the correct exception when executing a query on a
|
2454
|
+
closed connection.
|
2623
2455
|
|
2624
|
-
*
|
2625
|
-
your custom coder like this:
|
2456
|
+
*Yves Senn*
|
2626
2457
|
|
2627
|
-
|
2458
|
+
* Ambiguous reflections are on :through relationships are no longer supported.
|
2459
|
+
For example, you need to change this:
|
2628
2460
|
|
2629
|
-
|
2461
|
+
class Author < ActiveRecord::Base
|
2462
|
+
has_many :posts
|
2463
|
+
has_many :taggings, through: :posts
|
2464
|
+
end
|
2630
2465
|
|
2631
|
-
|
2632
|
-
|
2633
|
-
|
2466
|
+
class Post < ActiveRecord::Base
|
2467
|
+
has_one :tagging
|
2468
|
+
has_many :taggings
|
2469
|
+
end
|
2634
2470
|
|
2635
|
-
|
2471
|
+
class Tagging < ActiveRecord::Base
|
2472
|
+
end
|
2636
2473
|
|
2637
|
-
|
2638
|
-
different database engines. Introduced `take` as a replacement to
|
2639
|
-
the old behavior of `first`.
|
2474
|
+
To this:
|
2640
2475
|
|
2641
|
-
|
2476
|
+
class Author < ActiveRecord::Base
|
2477
|
+
has_many :posts
|
2478
|
+
has_many :taggings, through: :posts, source: :tagging
|
2479
|
+
end
|
2642
2480
|
|
2643
|
-
|
2644
|
-
|
2481
|
+
class Post < ActiveRecord::Base
|
2482
|
+
has_one :tagging
|
2483
|
+
has_many :taggings
|
2484
|
+
end
|
2645
2485
|
|
2646
|
-
|
2647
|
-
|
2648
|
-
that is identical to options available to the add_index method:
|
2486
|
+
class Tagging < ActiveRecord::Base
|
2487
|
+
end
|
2649
2488
|
|
2650
|
-
|
2651
|
-
t.references :person, index: true
|
2652
|
-
end
|
2489
|
+
*Aaron Patterson*
|
2653
2490
|
|
2654
|
-
|
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
|
-
|
2657
|
-
t.references :person
|
2658
|
-
end
|
2659
|
-
add_index :messages, :person_id
|
2495
|
+
Example:
|
2660
2496
|
|
2661
|
-
|
2497
|
+
User.select("name, username").count
|
2498
|
+
# Before => SELECT count(*) FROM users
|
2499
|
+
# After => ActiveRecord::StatementInvalid
|
2662
2500
|
|
2663
|
-
|
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
|
-
*
|
2666
|
-
provided by dynamic finders in a way that allows dynamic input more
|
2667
|
-
easily:
|
2505
|
+
*Yves Senn*
|
2668
2506
|
|
2669
|
-
|
2670
|
-
|
2671
|
-
|
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
|
-
|
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
|
-
|
2676
|
-
|
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
|
-
|
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
|
-
|
2522
|
+
class Taggable < ActiveRecord::Base
|
2523
|
+
belongs_to :tag, inverse_of: false
|
2524
|
+
end
|
2681
2525
|
|
2682
|
-
|
2526
|
+
*John Wang*
|
2683
2527
|
|
2684
|
-
|
2685
|
-
default_scope where(color: 'red')
|
2528
|
+
* Fix `add_column` with `array` option when using PostgreSQL. Fixes #10432.
|
2686
2529
|
|
2687
|
-
|
2530
|
+
*Adam Anderson*
|
2688
2531
|
|
2689
|
-
|
2690
|
-
|
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
|
-
|
2693
|
-
the following:
|
2536
|
+
Example:
|
2694
2537
|
|
2695
|
-
|
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
|
-
|
2542
|
+
*Yves Senn*
|
2698
2543
|
|
2699
|
-
|
2700
|
-
scope :recent_red, recent.where(color: 'red')
|
2544
|
+
* Fix the `:primary_key` option for `has_many` associations.
|
2701
2545
|
|
2702
|
-
|
2703
|
-
Record, and there are still bugs. For example, the following does
|
2704
|
-
not do what you expect:
|
2546
|
+
Fixes #10693.
|
2705
2547
|
|
2706
|
-
|
2707
|
-
where(...).remove_conditions # => still has conditions
|
2548
|
+
*Yves Senn*
|
2708
2549
|
|
2709
|
-
|
2550
|
+
* Fix bug where tiny types are incorrectly coerced as boolean when the length is more than 1.
|
2710
2551
|
|
2711
|
-
|
2552
|
+
Fixes #10620.
|
2712
2553
|
|
2713
|
-
|
2714
|
-
to some inconsistencies with associations, as described in this commit:
|
2554
|
+
*Aaron Patterson*
|
2715
2555
|
|
2716
|
-
|
2556
|
+
* Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1.
|
2717
2557
|
|
2718
|
-
|
2558
|
+
*kennyj*
|
2719
2559
|
|
2720
|
-
|
2560
|
+
* Deprecate `ConnectionAdapters::SchemaStatements#distinct`,
|
2561
|
+
as it is no longer used by internals.
|
2721
2562
|
|
2722
|
-
*
|
2563
|
+
*Ben Woosley*
|
2723
2564
|
|
2724
|
-
|
2725
|
-
|
2565
|
+
* Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix`
|
2566
|
+
is not blank.
|
2726
2567
|
|
2727
|
-
|
2568
|
+
Call `assume_migrated_upto_version` on connection to prevent it from first
|
2569
|
+
being picked up in `method_missing`.
|
2728
2570
|
|
2729
|
-
|
2730
|
-
|
2731
|
-
|
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
|
-
|
2576
|
+
Fixes #10411.
|
2734
2577
|
|
2735
|
-
|
2736
|
-
RAILS_ENV=production bundle exec rails server
|
2737
|
-
=> use db/schema_cache.dump
|
2578
|
+
*Kyle Stevens*
|
2738
2579
|
|
2739
|
-
|
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
|
-
*
|
2582
|
+
*Neeraj Singh*
|
2744
2583
|
|
2745
|
-
*
|
2584
|
+
* Confirm a record has not already been destroyed before decrementing counter cache.
|
2746
2585
|
|
2747
|
-
|
2748
|
-
string with the partial index criteria.
|
2586
|
+
*Ben Tucker*
|
2749
2587
|
|
2750
|
-
|
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
|
-
|
2593
|
+
*Zach Ohlgren*
|
2753
2594
|
|
2754
|
-
|
2595
|
+
* While removing index if column option is missing then raise IrreversibleMigration exception.
|
2755
2596
|
|
2756
|
-
|
2597
|
+
Following code should raise `IrreversibleMigration`. But the code was
|
2598
|
+
failing since options is an array and not a hash.
|
2757
2599
|
|
2758
|
-
|
2600
|
+
def change
|
2601
|
+
change_table :users do |t|
|
2602
|
+
t.remove_index [:name, :email]
|
2603
|
+
end
|
2604
|
+
end
|
2759
2605
|
|
2760
|
-
|
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
|
-
|
2764
|
-
generating an empty relation and will not fire any query to the database.
|
2608
|
+
Fixes #10419.
|
2765
2609
|
|
2766
|
-
*
|
2610
|
+
*Neeraj Singh*
|
2767
2611
|
|
2768
|
-
*
|
2769
|
-
object pattern for the Relation class.
|
2612
|
+
* Do not overwrite manually built records during one-to-one nested attribute assignment
|
2770
2613
|
|
2771
|
-
|
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
|
-
|
2774
|
-
|
2618
|
+
class Member < ActiveRecord::Base
|
2619
|
+
has_one :avatar
|
2620
|
+
accepts_nested_attributes_for :avatar
|
2775
2621
|
|
2776
|
-
|
2777
|
-
|
2622
|
+
def avatar
|
2623
|
+
super || build_avatar(width: 200)
|
2624
|
+
end
|
2625
|
+
end
|
2778
2626
|
|
2779
|
-
|
2627
|
+
member = Member.new
|
2628
|
+
member.avatar_attributes = {icon: 'sad'}
|
2629
|
+
member.avatar.width # => 200
|
2780
2630
|
|
2781
|
-
*
|
2631
|
+
*Olek Janiszewski*
|
2782
2632
|
|
2783
|
-
|
2784
|
-
|
2785
|
-
|
2786
|
-
|
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
|
-
*
|
2638
|
+
*Johnny Holton*
|
2791
2639
|
|
2792
|
-
*
|
2793
|
-
another value has been specified).
|
2640
|
+
* Handle aliased attributes in ActiveRecord::Relation.
|
2794
2641
|
|
2795
|
-
|
2642
|
+
When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database:
|
2796
2643
|
|
2797
|
-
|
2798
|
-
an `OUTER JOIN comments`, rather than two separate queries:
|
2644
|
+
With the model
|
2799
2645
|
|
2800
|
-
|
2801
|
-
|
2646
|
+
class Topic
|
2647
|
+
alias_attribute :heading, :title
|
2648
|
+
end
|
2802
2649
|
|
2803
|
-
|
2804
|
-
flawed idea unless we write an SQL parser, which we do not wish to
|
2805
|
-
do.
|
2650
|
+
The call
|
2806
2651
|
|
2807
|
-
|
2652
|
+
Topic.where(heading: 'The First Topic')
|
2808
2653
|
|
2809
|
-
|
2810
|
-
explicitly state which tables you reference, when using SQL snippets:
|
2654
|
+
should yield the same result as
|
2811
2655
|
|
2812
|
-
|
2813
|
-
.where("comments.name = 'foo'")
|
2814
|
-
.references(:comments)
|
2656
|
+
Topic.where(title: 'The First Topic')
|
2815
2657
|
|
2816
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
2664
|
+
* Mute `psql` output when running rake db:schema:load.
|
2828
2665
|
|
2829
|
-
*
|
2830
|
-
switch to `schema_migrations`.
|
2666
|
+
*Godfrey Chan*
|
2831
2667
|
|
2832
|
-
|
2668
|
+
* Trigger a save on `has_one association=(associate)` when the associate contents have changed.
|
2833
2669
|
|
2834
|
-
|
2835
|
-
connection pool can fill and an exception will be raised.
|
2670
|
+
Fixes #8856.
|
2836
2671
|
|
2837
|
-
*
|
2672
|
+
*Chris Thompson*
|
2838
2673
|
|
2839
|
-
*
|
2674
|
+
* Abort a rake task when missing db/structure.sql like `db:schema:load` task.
|
2840
2675
|
|
2841
|
-
*
|
2676
|
+
*kennyj*
|
2842
2677
|
|
2843
|
-
*
|
2678
|
+
* rake:db:test:prepare falls back to original environment after execution.
|
2844
2679
|
|
2845
|
-
*
|
2680
|
+
*Slava Markevich*
|
2846
2681
|
|
2847
|
-
Please check [
|
2682
|
+
Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/activerecord/CHANGELOG.md) for previous changes.
|