activerecord 4.0.0.beta1 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +573 -30
- data/README.rdoc +3 -3
- data/lib/active_record.rb +8 -2
- data/lib/active_record/associations.rb +16 -9
- data/lib/active_record/associations/association.rb +8 -6
- data/lib/active_record/associations/association_scope.rb +2 -1
- data/lib/active_record/associations/belongs_to_association.rb +2 -2
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -1
- data/lib/active_record/associations/builder/belongs_to.rb +37 -5
- data/lib/active_record/associations/collection_association.rb +38 -14
- data/lib/active_record/associations/collection_proxy.rb +18 -15
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +3 -3
- data/lib/active_record/associations/has_many_association.rb +4 -3
- data/lib/active_record/associations/has_many_through_association.rb +1 -1
- data/lib/active_record/associations/has_one_association.rb +1 -1
- data/lib/active_record/associations/join_dependency.rb +29 -8
- data/lib/active_record/associations/join_dependency/join_association.rb +26 -6
- data/lib/active_record/associations/join_dependency/join_base.rb +2 -2
- data/lib/active_record/associations/join_dependency/join_part.rb +6 -6
- data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +1 -1
- data/lib/active_record/associations/preloader/has_many_through.rb +6 -2
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/attribute_assignment.rb +5 -5
- data/lib/active_record/attribute_methods.rb +20 -5
- data/lib/active_record/attribute_methods/dirty.rb +5 -1
- data/lib/active_record/attribute_methods/primary_key.rb +1 -1
- data/lib/active_record/attribute_methods/serialization.rb +9 -2
- data/lib/active_record/autosave_association.rb +19 -5
- data/lib/active_record/base.rb +3 -3
- data/lib/active_record/callbacks.rb +1 -1
- data/lib/active_record/coders/yaml_column.rb +8 -13
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +3 -9
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +2 -1
- data/lib/active_record/connection_adapters/abstract/quoting.rb +2 -8
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +60 -61
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +13 -2
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +291 -153
- data/lib/active_record/connection_adapters/abstract/transaction.rb +1 -1
- data/lib/active_record/connection_adapters/abstract_adapter.rb +92 -1
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +55 -29
- data/lib/active_record/connection_adapters/column.rb +4 -4
- data/lib/active_record/connection_adapters/connection_specification.rb +2 -2
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -3
- data/lib/active_record/connection_adapters/mysql_adapter.rb +5 -5
- data/lib/active_record/connection_adapters/postgresql/cast.rb +22 -2
- data/lib/active_record/connection_adapters/postgresql/oid.rb +25 -6
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +26 -13
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +50 -9
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +53 -24
- data/lib/active_record/connection_adapters/schema_cache.rb +35 -7
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +13 -5
- data/lib/active_record/connection_handling.rb +7 -7
- data/lib/active_record/core.rb +43 -8
- data/lib/active_record/counter_cache.rb +2 -1
- data/lib/active_record/errors.rb +11 -10
- data/lib/active_record/explain.rb +9 -7
- data/lib/active_record/explain_registry.rb +30 -0
- data/lib/active_record/explain_subscriber.rb +3 -2
- data/lib/active_record/fixture_set/file.rb +1 -2
- data/lib/active_record/fixtures.rb +13 -7
- data/lib/active_record/inheritance.rb +12 -4
- data/lib/active_record/integration.rb +3 -3
- data/lib/active_record/locking/optimistic.rb +2 -2
- data/lib/active_record/log_subscriber.rb +2 -2
- data/lib/active_record/migration.rb +69 -21
- data/lib/active_record/model_schema.rb +1 -1
- data/lib/active_record/nested_attributes.rb +98 -46
- data/lib/active_record/persistence.rb +3 -3
- data/lib/active_record/querying.rb +1 -1
- data/lib/active_record/railtie.rb +18 -4
- data/lib/active_record/railties/console_sandbox.rb +3 -2
- data/lib/active_record/railties/controller_runtime.rb +2 -1
- data/lib/active_record/railties/databases.rake +38 -80
- data/lib/active_record/reflection.rb +36 -3
- data/lib/active_record/relation.rb +18 -8
- data/lib/active_record/relation/calculations.rb +10 -5
- data/lib/active_record/relation/delegation.rb +3 -5
- data/lib/active_record/relation/finder_methods.rb +27 -14
- data/lib/active_record/relation/merger.rb +30 -2
- data/lib/active_record/relation/predicate_builder.rb +1 -6
- data/lib/active_record/relation/query_methods.rb +113 -16
- data/lib/active_record/runtime_registry.rb +17 -0
- data/lib/active_record/schema_dumper.rb +5 -1
- data/lib/active_record/schema_migration.rb +8 -5
- data/lib/active_record/scoping.rb +56 -2
- data/lib/active_record/scoping/default.rb +12 -11
- data/lib/active_record/scoping/named.rb +7 -3
- data/lib/active_record/serialization.rb +1 -1
- data/lib/active_record/statement_cache.rb +26 -0
- data/lib/active_record/tasks/database_tasks.rb +55 -10
- data/lib/active_record/tasks/firebird_database_tasks.rb +56 -0
- data/lib/active_record/tasks/mysql_database_tasks.rb +7 -2
- data/lib/active_record/tasks/oracle_database_tasks.rb +45 -0
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +48 -0
- data/lib/active_record/timestamp.rb +6 -0
- data/lib/active_record/transactions.rb +7 -3
- data/lib/active_record/validations.rb +1 -2
- data/lib/active_record/validations/uniqueness.rb +7 -3
- data/lib/active_record/version.rb +7 -6
- data/lib/rails/generators/active_record/migration/migration_generator.rb +9 -2
- data/lib/rails/generators/active_record/{model/templates/migration.rb → migration/templates/create_table_migration.rb} +4 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb +4 -1
- metadata +17 -12
- data/examples/associations.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e12def830bf51f562de866b6caa052b2e1a83e0d
|
4
|
+
data.tar.gz: 79b4cd4a02f533963a80428fb27c1ed480050b78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f28a1e30ab0bee886be06ec885742bb7fec8d1483dc649683f9bad24423bd84009356a099b05bc41fda143f976760d207b787c27ebe0e8d86a7317fbc9e8da1a
|
7
|
+
data.tar.gz: 15d81a227f51f12a3a965ed46522ed3ffbb954f64e86f4b24fcd1bc17baf554273bbe4e0c8e61f68c36e3a4107f14e3f32a52cb5512d6ae221ef14b13de76463
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,550 @@
|
|
1
|
+
## Rails 4.0.0 (unreleased) ##
|
2
|
+
|
3
|
+
* Allow to use databases.rake tasks without having `Rails.application`.
|
4
|
+
|
5
|
+
*Piotr Sarnacki*
|
6
|
+
|
7
|
+
* Fix a `SystemStackError` problem when using time zone aware or serialized attributes.
|
8
|
+
In current implementation, we reuse `column_types` argument when initiating an instance.
|
9
|
+
If an instance has serialized or time zone aware attributes, `column_types` is
|
10
|
+
wrapped multiple times in `decorate_columns` method. Thus the above error occurs.
|
11
|
+
|
12
|
+
*Dan Erikson & kennyj*
|
13
|
+
|
14
|
+
* Fix for a regression bug in which counter cache columns were not being updated
|
15
|
+
when record was pushed into a has_many association. For example:
|
16
|
+
|
17
|
+
Post.first.comments << Comment.create
|
18
|
+
|
19
|
+
Fixes #3891.
|
20
|
+
|
21
|
+
*Matthew Robertson*
|
22
|
+
|
23
|
+
* If a model was instantiated from the database using `select`, `respond_to?`
|
24
|
+
returns false for non-selected attributes. For example:
|
25
|
+
|
26
|
+
post = Post.select(:title).first
|
27
|
+
post.respond_to?(:body) # => false
|
28
|
+
|
29
|
+
post = Post.select('title as post_title').first
|
30
|
+
post.respond_to?(:title) # => false
|
31
|
+
|
32
|
+
Fixes #4208.
|
33
|
+
|
34
|
+
*Neeraj Singh*
|
35
|
+
|
36
|
+
* Run `rake migrate:down` & `rake migrate:up` in transaction if database supports.
|
37
|
+
|
38
|
+
*Alexander Bondarev*
|
39
|
+
|
40
|
+
* `0x` prefix must be added when assigning hexadecimal string into `bit` column in PostgreSQL.
|
41
|
+
|
42
|
+
*kennyj*
|
43
|
+
|
44
|
+
* Added Statement Cache to allow the caching of a single statement. The cache works by
|
45
|
+
duping the relation returned from yielding a statement, which allows skipping the AST
|
46
|
+
building phase for following executes. The cache returns results in array format.
|
47
|
+
|
48
|
+
Example:
|
49
|
+
|
50
|
+
cache = ActiveRecord::StatementCache.new do
|
51
|
+
Book.where(name: "my book").limit(100)
|
52
|
+
end
|
53
|
+
|
54
|
+
books = cache.execute
|
55
|
+
|
56
|
+
The solution attempts to get closer to the speed of `find_by_sql` but still maintaining
|
57
|
+
the expressiveness of the Active Record queries.
|
58
|
+
|
59
|
+
*Olli Rissanen*
|
60
|
+
|
61
|
+
* Preserve context while merging relations with join information.
|
62
|
+
|
63
|
+
class Comment < ActiveRecord::Base
|
64
|
+
belongs_to :post
|
65
|
+
end
|
66
|
+
|
67
|
+
class Author < ActiveRecord::Base
|
68
|
+
has_many :posts
|
69
|
+
end
|
70
|
+
|
71
|
+
class Post < ActiveRecord::Base
|
72
|
+
belongs_to :author
|
73
|
+
has_many :comments
|
74
|
+
end
|
75
|
+
|
76
|
+
`Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all`
|
77
|
+
would fail with
|
78
|
+
`ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`.
|
79
|
+
|
80
|
+
It is failing because `all` is being called on relation which looks like this after all
|
81
|
+
the merging: `{:joins=>[:post, :author], :where=>[#<Arel::Nodes::Equality: ....}`. In this
|
82
|
+
relation all the context that `Post` was joined with `Author` is lost and hence the error
|
83
|
+
that `author` was not found on `Comment`.
|
84
|
+
|
85
|
+
The solution is to build `JoinAssociation` when two relations with join information are being
|
86
|
+
merged. And later while building the Arel use the previously built `JoinAssociation` record
|
87
|
+
in `JoinDependency#graft` to build the right from clause.
|
88
|
+
Fixes #3002.
|
89
|
+
|
90
|
+
*Jared Armstrong and Neeraj Singh*
|
91
|
+
|
92
|
+
* `default_scopes?` is deprecated. Check for `default_scopes.empty?` instead.
|
93
|
+
|
94
|
+
*Agis Anastasopoulos*
|
95
|
+
|
96
|
+
* Default values for PostgreSQL bigint types now get parsed and dumped to the
|
97
|
+
schema correctly.
|
98
|
+
|
99
|
+
*Erik Peterson*
|
100
|
+
|
101
|
+
* Fix associations with `:inverse_of` option when building association
|
102
|
+
with a block. Inside the block the parent object was different then
|
103
|
+
after the block.
|
104
|
+
|
105
|
+
Example:
|
106
|
+
|
107
|
+
parent.association.build do |child|
|
108
|
+
child.parent.equal?(parent) # false
|
109
|
+
end
|
110
|
+
|
111
|
+
# vs
|
112
|
+
|
113
|
+
child = parent.association.build
|
114
|
+
child.parent.equal?(parent) # true
|
115
|
+
|
116
|
+
*Michal Cichra*
|
117
|
+
|
118
|
+
* `has_many` using `:through` now obeys the order clause mentioned in
|
119
|
+
through association.
|
120
|
+
Fixes #10016.
|
121
|
+
|
122
|
+
*Neeraj Singh*
|
123
|
+
|
124
|
+
* `belongs_to :touch` behavior now touches old association when
|
125
|
+
transitioning to new association.
|
126
|
+
|
127
|
+
class Passenger < ActiveRecord::Base
|
128
|
+
belongs_to :car, touch: true
|
129
|
+
end
|
130
|
+
|
131
|
+
car_1 = Car.create
|
132
|
+
car_2 = Car.create
|
133
|
+
|
134
|
+
passenger = Passenger.create car: car_1
|
135
|
+
|
136
|
+
passenger.car = car_2
|
137
|
+
passenger.save
|
138
|
+
|
139
|
+
Previously only car_2 would be touched. Now both car_1 and car_2
|
140
|
+
will be touched.
|
141
|
+
|
142
|
+
*Adam Gamble*
|
143
|
+
|
144
|
+
* Extract and deprecate Firebird / Sqlserver / Oracle database tasks, because
|
145
|
+
These tasks should be supported by 3rd-party adapter.
|
146
|
+
|
147
|
+
*kennyj*
|
148
|
+
|
149
|
+
* Allow `ActiveRecord::Base.connection_handler` to have thread affinity and be
|
150
|
+
settable, this effectively allows Active Record to be used in a multithreaded
|
151
|
+
setup with multiple connections to multiple databases.
|
152
|
+
|
153
|
+
*Sam Saffron*
|
154
|
+
|
155
|
+
* `rename_column` preserves `auto_increment` in MySQL migrations.
|
156
|
+
Fixes #3493.
|
157
|
+
|
158
|
+
*Vipul A M*
|
159
|
+
|
160
|
+
* PostgreSQL geometric type point is now supported by Active Record. Fixes #7324.
|
161
|
+
|
162
|
+
*Martin Schuerrer*
|
163
|
+
|
164
|
+
* Add support for concurrent indexing in PostgreSQL adapter via the
|
165
|
+
`algorithm: :concurrently` option.
|
166
|
+
|
167
|
+
add_index(:people, :last_name, algorithm: :concurrently)
|
168
|
+
|
169
|
+
Also add support for MySQL index algorithms (`COPY`, `INPLACE`,
|
170
|
+
`DEFAULT`) via the `:algorithm` option.
|
171
|
+
|
172
|
+
add_index(:people, :last_name, algorithm: :copy) # or :inplace/:default
|
173
|
+
|
174
|
+
*Dan McClain*
|
175
|
+
|
176
|
+
* Add support for fulltext and spatial indexes on MySQL tables with MyISAM database
|
177
|
+
engine via the `type: 'FULLTEXT'` / `type: 'SPATIAL'` option.
|
178
|
+
|
179
|
+
add_index(:people, :last_name, type: 'FULLTEXT')
|
180
|
+
add_index(:people, :last_name, type: 'SPATIAL')
|
181
|
+
|
182
|
+
*Ken Mazaika*
|
183
|
+
|
184
|
+
* Add an `add_index` override in PostgreSQL adapter and MySQL adapter
|
185
|
+
to allow custom index type support.
|
186
|
+
Fixes #6101.
|
187
|
+
|
188
|
+
add_index(:wikis, :body, :using => 'gin')
|
189
|
+
|
190
|
+
*Stefan Huber* and *Doabit*
|
191
|
+
|
192
|
+
* After extraction of mass-assignment attributes (which protects [id, type]
|
193
|
+
by default) we can pass id to `update_attributes` and it will update
|
194
|
+
another record because id will be used in where statement. We never have
|
195
|
+
to change id in where statement because we try to set/replace fields for
|
196
|
+
already loaded record but we have to try to set new id for that record.
|
197
|
+
|
198
|
+
*Dmitry Vorotilin*
|
199
|
+
|
200
|
+
* Models with multiple counter cache associations now update correctly on destroy.
|
201
|
+
See #7706.
|
202
|
+
|
203
|
+
*Ian Young*
|
204
|
+
|
205
|
+
* If `:inverse_of` is true on an association, then when one calls `find()` on
|
206
|
+
the association, Active Record will first look through the in-memory objects
|
207
|
+
in the association for a particular id. Then, it will go to the DB if it
|
208
|
+
is not found. This is accomplished by calling `find_by_scan` in
|
209
|
+
collection associations whenever `options[:inverse_of]` is not nil.
|
210
|
+
Fixes #9470.
|
211
|
+
|
212
|
+
*John Wang*
|
213
|
+
|
214
|
+
* `rake db:create` does not change permissions of the MySQL root user.
|
215
|
+
Fixes #8079.
|
216
|
+
|
217
|
+
*Yves Senn*
|
218
|
+
|
219
|
+
* The length of the `version` column in the `schema_migrations` table
|
220
|
+
created by the `mysql2` adapter is 191 if the encoding is "utf8mb4".
|
221
|
+
|
222
|
+
The "utf8" encoding in MySQL has support for a maximum of 3 bytes per character,
|
223
|
+
and only contains characters from the BMP. The recently added
|
224
|
+
[utf8mb4](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html)
|
225
|
+
encoding extends the support to four bytes. As of this writing, said encoding
|
226
|
+
is supported in the betas of the `mysql2` gem.
|
227
|
+
|
228
|
+
Setting the encoding to "utf8mb4" has
|
229
|
+
[a few implications](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-upgrading.html).
|
230
|
+
This change addresses the max length for indexes, which is 191 instead of 255.
|
231
|
+
|
232
|
+
*Xavier Noria*
|
233
|
+
|
234
|
+
* Counter caches on associations will now stay valid when attributes are
|
235
|
+
updated (not just when records are created or destroyed), for example,
|
236
|
+
when calling `update_attributes`. The following code now works:
|
237
|
+
|
238
|
+
class Comment < ActiveRecord::Base
|
239
|
+
belongs_to :post, counter_cache: true
|
240
|
+
end
|
241
|
+
|
242
|
+
class Post < ActiveRecord::Base
|
243
|
+
has_many :comments
|
244
|
+
end
|
245
|
+
|
246
|
+
post = Post.create
|
247
|
+
comment = Comment.create
|
248
|
+
|
249
|
+
post.comments << comment
|
250
|
+
post.save.reload.comments_count # => 1
|
251
|
+
comment.update_attributes(post_id: nil)
|
252
|
+
|
253
|
+
post.save.reload.comments_count # => 0
|
254
|
+
|
255
|
+
Updating the id of a `belongs_to` object with the id of a new object will
|
256
|
+
also keep the count accurate.
|
257
|
+
|
258
|
+
*John Wang*
|
259
|
+
|
260
|
+
* Referencing join tables implicitly was deprecated. There is a
|
261
|
+
possibility that these deprecation warnings are shown even if you
|
262
|
+
don't make use of that feature. You can now disable the feature entirely.
|
263
|
+
Fixes #9712.
|
264
|
+
|
265
|
+
Example:
|
266
|
+
|
267
|
+
# in your configuration
|
268
|
+
config.active_record.disable_implicit_join_references = true
|
269
|
+
|
270
|
+
# or directly
|
271
|
+
ActiveRecord::Base.disable_implicit_join_references = true
|
272
|
+
|
273
|
+
*Yves Senn*
|
274
|
+
|
275
|
+
* The `:distinct` option for `Relation#count` is deprecated. You
|
276
|
+
should use `Relation#distinct` instead.
|
277
|
+
|
278
|
+
Example:
|
279
|
+
|
280
|
+
# Before
|
281
|
+
Post.select(:author_name).count(distinct: true)
|
282
|
+
|
283
|
+
# After
|
284
|
+
Post.select(:author_name).distinct.count
|
285
|
+
|
286
|
+
*Yves Senn*
|
287
|
+
|
288
|
+
* Rename `Relation#uniq` to `Relation#distinct`. `#uniq` is still
|
289
|
+
available as an alias but we encourage to use `#distinct` instead.
|
290
|
+
Also `Relation#uniq_value` is aliased to `Relation#distinct_value`,
|
291
|
+
this is a temporary solution and you should migrate to `distinct_value`.
|
292
|
+
|
293
|
+
*Yves Senn*
|
294
|
+
|
295
|
+
* Fix quoting for sqlite migrations using `copy_table_contents` with binary
|
296
|
+
columns.
|
297
|
+
|
298
|
+
These would fail with "SQLite3::SQLException: unrecognized token" because
|
299
|
+
the column was not being passed to `quote` so the data was not quoted
|
300
|
+
correctly.
|
301
|
+
|
302
|
+
*Matthew M. Boedicker*
|
303
|
+
|
304
|
+
* Promotes `change_column_null` to the migrations API. This macro sets/removes
|
305
|
+
`NOT NULL` constraints, and accepts an optional argument to replace existing
|
306
|
+
`NULL`s if needed. The adapters for SQLite, MySQL, PostgreSQL, and (at least)
|
307
|
+
Oracle, already implement this method.
|
308
|
+
|
309
|
+
*Xavier Noria*
|
310
|
+
|
311
|
+
* Uniqueness validation allows you to pass `:conditions` to limit
|
312
|
+
the constraint lookup.
|
313
|
+
|
314
|
+
Example:
|
315
|
+
|
316
|
+
validates_uniqueness_of :title, conditions: -> { where('approved = ?', true) }
|
317
|
+
|
318
|
+
*Mattias Pfeiffer + Yves Senn*
|
319
|
+
|
320
|
+
* `connection` is deprecated as an instance method.
|
321
|
+
This allows end-users to have a `connection` method on their models
|
322
|
+
without clashing with Active Record internals.
|
323
|
+
|
324
|
+
*Ben Moss*
|
325
|
+
|
326
|
+
* When copying migrations, preserve their magic comments and content encoding.
|
327
|
+
|
328
|
+
*OZAWA Sakuro*
|
329
|
+
|
330
|
+
* Fix `subclass_from_attrs` when `eager_load` is false. It cannot find
|
331
|
+
subclass because all classes are loaded automatically when it needs.
|
332
|
+
|
333
|
+
*Dmitry Vorotilin*
|
334
|
+
|
335
|
+
* When `:name` option is provided to `remove_index`, use it if there is no
|
336
|
+
index by the conventional name.
|
337
|
+
|
338
|
+
For example, previously if an index was removed like so
|
339
|
+
`remove_index :values, column: :value, name: 'a_different_name'`
|
340
|
+
the generated SQL would not contain the specified index name,
|
341
|
+
and hence the migration would fail.
|
342
|
+
Fixes #8858.
|
343
|
+
|
344
|
+
*Ezekiel Smithburg*
|
345
|
+
|
346
|
+
* Created block to by-pass the prepared statement bindings.
|
347
|
+
This will allow to compose fragments of large SQL statements to
|
348
|
+
avoid multiple round-trips between Ruby and the DB.
|
349
|
+
|
350
|
+
Example:
|
351
|
+
|
352
|
+
sql = Post.connection.unprepared_statement do
|
353
|
+
Post.first.comments.to_sql
|
354
|
+
end
|
355
|
+
|
356
|
+
*Cédric Fabianski*
|
357
|
+
|
358
|
+
* Change the semantics of combining scopes to be the same as combining
|
359
|
+
class methods which return scopes. For example:
|
360
|
+
|
361
|
+
class User < ActiveRecord::Base
|
362
|
+
scope :active, -> { where state: 'active' }
|
363
|
+
scope :inactive, -> { where state: 'inactive' }
|
364
|
+
end
|
365
|
+
|
366
|
+
class Post < ActiveRecord::Base
|
367
|
+
def self.active
|
368
|
+
where state: 'active'
|
369
|
+
end
|
370
|
+
|
371
|
+
def self.inactive
|
372
|
+
where state: 'inactive'
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
### BEFORE ###
|
377
|
+
|
378
|
+
User.where(state: 'active').where(state: 'inactive')
|
379
|
+
# => SELECT * FROM users WHERE state = 'active' AND state = 'inactive'
|
380
|
+
|
381
|
+
User.active.inactive
|
382
|
+
# => SELECT * FROM users WHERE state = 'inactive'
|
383
|
+
|
384
|
+
Post.active.inactive
|
385
|
+
# => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
|
386
|
+
|
387
|
+
### AFTER ###
|
388
|
+
|
389
|
+
User.active.inactive
|
390
|
+
# => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
|
391
|
+
|
392
|
+
Before this change, invoking a scope would merge it into the current
|
393
|
+
scope and return the result. `Relation#merge` applies "last where
|
394
|
+
wins" logic to de-duplicate the conditions, but this lead to
|
395
|
+
confusing and inconsistent behaviour. This fixes that.
|
396
|
+
|
397
|
+
If you really do want the "last where wins" logic, you can opt-in to
|
398
|
+
it like so:
|
399
|
+
|
400
|
+
User.active.merge(User.inactive)
|
401
|
+
|
402
|
+
Fixes #7365.
|
403
|
+
|
404
|
+
*Neeraj Singh* and *Jon Leighton*
|
405
|
+
|
406
|
+
* Expand `#cache_key` to consult all relevant updated timestamps.
|
407
|
+
|
408
|
+
Previously only `updated_at` column was checked, now it will
|
409
|
+
consult other columns that received updated timestamps on save,
|
410
|
+
such as `updated_on`. When multiple columns are present it will
|
411
|
+
use the most recent timestamp.
|
412
|
+
Fixes #9033.
|
413
|
+
|
414
|
+
*Brendon Murphy*
|
415
|
+
|
416
|
+
* Throw `NotImplementedError` when trying to instantiate `ActiveRecord::Base` or an abstract class.
|
417
|
+
|
418
|
+
*Aaron Weiner*
|
419
|
+
|
420
|
+
* Warn when `rake db:structure:dump` with a MySQL database and
|
421
|
+
`mysqldump` is not in the PATH or fails.
|
422
|
+
Fixes #9518.
|
423
|
+
|
424
|
+
*Yves Senn*
|
425
|
+
|
426
|
+
* Remove `connection#structure_dump`, which is no longer used. *Yves Senn*
|
427
|
+
|
428
|
+
* Make it possible to execute migrations without a transaction even
|
429
|
+
if the database adapter supports DDL transactions.
|
430
|
+
Fixes #9483.
|
431
|
+
|
432
|
+
Example:
|
433
|
+
|
434
|
+
class ChangeEnum < ActiveRecord::Migration
|
435
|
+
disable_ddl_transaction!
|
436
|
+
|
437
|
+
def up
|
438
|
+
execute "ALTER TYPE model_size ADD VALUE 'new_value'"
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
*Yves Senn*
|
443
|
+
|
444
|
+
* Assigning "0.0" to a nullable numeric column does not make it dirty.
|
445
|
+
Fixes #9034.
|
446
|
+
|
447
|
+
Example:
|
448
|
+
|
449
|
+
product = Product.create price: 0.0
|
450
|
+
product.price = '0.0'
|
451
|
+
product.changed? # => false (this used to return true)
|
452
|
+
product.changes # => {} (this used to return { price: [0.0, 0.0] })
|
453
|
+
|
454
|
+
*Yves Senn*
|
455
|
+
|
456
|
+
* Added functionality to unscope relations in a relations chain. For
|
457
|
+
instance, if you are passed in a chain of relations as follows:
|
458
|
+
|
459
|
+
User.where(name: "John").order('id DESC')
|
460
|
+
|
461
|
+
but you want to get rid of order, then this feature allows you to do:
|
462
|
+
|
463
|
+
User.where(name: "John").order('id DESC').unscope(:order)
|
464
|
+
== User.where(name: "John")
|
465
|
+
|
466
|
+
The .unscope() function is more general than the .except() method because
|
467
|
+
.except() only works on the relation it is acting on. However, .unscope()
|
468
|
+
works for any relation in the entire relation chain.
|
469
|
+
|
470
|
+
*John Wang*
|
471
|
+
|
472
|
+
* PostgreSQL timestamp with time zone (timestamptz) datatype now returns a
|
473
|
+
ActiveSupport::TimeWithZone instance instead of a string
|
474
|
+
|
475
|
+
*Troy Kruthoff*
|
476
|
+
|
477
|
+
* The `#append` method for collection associations behaves like`<<`.
|
478
|
+
`#prepend` is not defined and `<<` or `#append` should be used.
|
479
|
+
Fixes #7364.
|
480
|
+
|
481
|
+
*Yves Senn*
|
482
|
+
|
483
|
+
* Added support for creating a table via Rails migration generator.
|
484
|
+
For example,
|
485
|
+
|
486
|
+
rails g migration create_books title:string content:text
|
487
|
+
|
488
|
+
will generate a migration that creates a table called books with
|
489
|
+
the listed attributes, without creating a model.
|
490
|
+
|
491
|
+
*Sammy Larbi*
|
492
|
+
|
493
|
+
* Fix bug that raises the wrong exception when the exception handled by PostgreSQL adapter
|
494
|
+
doesn't respond to `#result`.
|
495
|
+
Fixes #8617.
|
496
|
+
|
497
|
+
*kennyj*
|
498
|
+
|
499
|
+
* Support PostgreSQL specific column types when using `change_table`.
|
500
|
+
Fixes #9480.
|
501
|
+
|
502
|
+
Example:
|
503
|
+
|
504
|
+
change_table :authors do |t|
|
505
|
+
t.hstore :books
|
506
|
+
t.json :metadata
|
507
|
+
end
|
508
|
+
|
509
|
+
*Yves Senn*
|
510
|
+
|
511
|
+
* Revert 408227d9c5ed7d, 'quote numeric'. This introduced some regressions.
|
512
|
+
|
513
|
+
*Steve Klabnik*
|
514
|
+
|
515
|
+
* Fix calculation of `db_runtime` property in
|
516
|
+
`ActiveRecord::Railties::ControllerRuntime#cleanup_view_runtime`.
|
517
|
+
Previously, after raising `ActionView::MissingTemplate`, `db_runtime` was
|
518
|
+
not populated.
|
519
|
+
Fixes #9215.
|
520
|
+
|
521
|
+
*Igor Fedoronchuk*
|
522
|
+
|
523
|
+
* Do not try to touch invalid (and thus not persisted) parent record
|
524
|
+
for a `belongs_to :parent, touch: true` association
|
525
|
+
|
526
|
+
*Olek Janiszewski*
|
527
|
+
|
528
|
+
* Fix when performing an ordered join query. The bug only
|
529
|
+
affected queries where the order was given with a symbol.
|
530
|
+
Fixes #9275.
|
531
|
+
|
532
|
+
Example:
|
533
|
+
|
534
|
+
# This will expand the order :name to "authors".name.
|
535
|
+
Author.joins(:books).where('books.published = 1').order(:name)
|
536
|
+
|
537
|
+
|
1
538
|
## Rails 4.0.0.beta1 (February 25, 2013) ##
|
2
539
|
|
3
|
-
* Fix overriding of attributes by default_scope on `ActiveRecord::Base#dup`.
|
540
|
+
* Fix overriding of attributes by `default_scope` on `ActiveRecord::Base#dup`.
|
4
541
|
|
5
542
|
*Hiroshige UMINO*
|
6
543
|
|
544
|
+
* Update queries now use prepared statements.
|
545
|
+
|
546
|
+
*Olli Rissanen*
|
547
|
+
|
7
548
|
* Fixing issue #8345. Now throwing an error when one attempts to touch a
|
8
549
|
new object that has not yet been persisted. For instance:
|
9
550
|
|
@@ -158,7 +699,7 @@
|
|
158
699
|
|
159
700
|
*James Miller*
|
160
701
|
|
161
|
-
* Allow store accessors to be
|
702
|
+
* Allow store accessors to be overridden like other attribute methods, e.g.:
|
162
703
|
|
163
704
|
class User < ActiveRecord::Base
|
164
705
|
store :settings, accessors: [ :color, :homepage ], coder: JSON
|
@@ -181,11 +722,11 @@
|
|
181
722
|
*Dylan Smith*
|
182
723
|
|
183
724
|
* Schema dumper supports dumping the enabled database extensions to `schema.rb`
|
184
|
-
(currently only supported by
|
725
|
+
(currently only supported by PostgreSQL).
|
185
726
|
|
186
727
|
*Justin George*
|
187
728
|
|
188
|
-
* The database
|
729
|
+
* The database adapters now converts the options passed thought `DATABASE_URL`
|
189
730
|
environment variable to the proper Ruby types before using. For example, SQLite requires
|
190
731
|
that the timeout value is an integer, and PostgreSQL requires that the
|
191
732
|
prepared_statements option is a boolean. These now work as expected:
|
@@ -284,7 +825,7 @@
|
|
284
825
|
|
285
826
|
*John Wang*
|
286
827
|
|
287
|
-
* Collection associations `#empty?` always respects
|
828
|
+
* Collection associations `#empty?` always respects built records.
|
288
829
|
Fixes #8879.
|
289
830
|
|
290
831
|
Example:
|
@@ -336,17 +877,17 @@
|
|
336
877
|
*Marc-André Lafortune*
|
337
878
|
|
338
879
|
* Serialized attributes can be serialized in integer columns.
|
339
|
-
|
880
|
+
Fixes #8575.
|
340
881
|
|
341
882
|
*Rafael Mendonça França*
|
342
883
|
|
343
884
|
* Keep index names when using `alter_table` with sqlite3.
|
344
|
-
|
885
|
+
Fixes #3489.
|
345
886
|
|
346
887
|
*Yves Senn*
|
347
888
|
|
348
|
-
* Add ability for
|
349
|
-
|
889
|
+
* Add ability for PostgreSQL adapter to disable user triggers in `disable_referential_integrity`.
|
890
|
+
Fixes #5523.
|
350
891
|
|
351
892
|
*Gary S. Weaver*
|
352
893
|
|
@@ -369,7 +910,7 @@
|
|
369
910
|
*Matthew Robertson*
|
370
911
|
|
371
912
|
* Recognize migrations placed in directories containing numbers and 'rb'.
|
372
|
-
|
913
|
+
Fixes #8492.
|
373
914
|
|
374
915
|
*Yves Senn*
|
375
916
|
|
@@ -427,13 +968,13 @@
|
|
427
968
|
|
428
969
|
* Fix performance problem with `primary_key` method in PostgreSQL adapter when having many schemas.
|
429
970
|
Uses `pg_constraint` table instead of `pg_depend` table which has many records in general.
|
430
|
-
|
971
|
+
Fixes #8414.
|
431
972
|
|
432
973
|
*kennyj*
|
433
974
|
|
434
975
|
* Do not instantiate intermediate Active Record objects when eager loading.
|
435
976
|
These records caused `after_find` to run more than expected.
|
436
|
-
|
977
|
+
Fixes #3313.
|
437
978
|
|
438
979
|
*Yves Senn*
|
439
980
|
|
@@ -454,12 +995,13 @@
|
|
454
995
|
|
455
996
|
* Fix dirty attribute checks for `TimeZoneConversion` with nil and blank
|
456
997
|
datetime attributes. Setting a nil datetime to a blank string should not
|
457
|
-
result in a change being flagged.
|
998
|
+
result in a change being flagged.
|
999
|
+
Fixes #8310.
|
458
1000
|
|
459
1001
|
*Alisdair McDiarmid*
|
460
1002
|
|
461
1003
|
* Prevent mass assignment to the type column of polymorphic associations when using `build`
|
462
|
-
|
1004
|
+
Fixes #8265.
|
463
1005
|
|
464
1006
|
*Yves Senn*
|
465
1007
|
|
@@ -468,14 +1010,14 @@
|
|
468
1010
|
|
469
1011
|
*Carlos Antonio da Silva*
|
470
1012
|
|
471
|
-
* Fix
|
1013
|
+
* Fix PostgreSQL adapter to handle BC timestamps correctly
|
472
1014
|
|
473
1015
|
HistoryEvent.create!(name: "something", occured_at: Date.new(0) - 5.years)
|
474
1016
|
|
475
1017
|
*Bogdan Gusiev*
|
476
1018
|
|
477
|
-
* When running migrations on
|
478
|
-
Previously, these migrations caused sql exceptions, because
|
1019
|
+
* When running migrations on PostgreSQL, the `:limit` option for `binary` and `text` columns is silently dropped.
|
1020
|
+
Previously, these migrations caused sql exceptions, because PostgreSQL doesn't support limits on these types.
|
479
1021
|
|
480
1022
|
*Victor Costan*
|
481
1023
|
|
@@ -512,7 +1054,7 @@
|
|
512
1054
|
*Bogdan Gusiev*
|
513
1055
|
|
514
1056
|
* `:counter_cache` option for `has_many` associations to support custom named counter caches.
|
515
|
-
|
1057
|
+
Fixes #7993.
|
516
1058
|
|
517
1059
|
*Yves Senn*
|
518
1060
|
|
@@ -536,7 +1078,7 @@
|
|
536
1078
|
*Nikita Afanasenko*
|
537
1079
|
|
538
1080
|
* Use query cache/uncache when using `DATABASE_URL`.
|
539
|
-
|
1081
|
+
Fixes #6951.
|
540
1082
|
|
541
1083
|
*kennyj*
|
542
1084
|
|
@@ -545,7 +1087,7 @@
|
|
545
1087
|
*Henrik Nyh*
|
546
1088
|
|
547
1089
|
* The `create_table` method raises an `ArgumentError` when the primary key column is redefined.
|
548
|
-
|
1090
|
+
Fixes #6378.
|
549
1091
|
|
550
1092
|
*Yves Senn*
|
551
1093
|
|
@@ -655,7 +1197,7 @@
|
|
655
1197
|
*Alexey Muranov*
|
656
1198
|
|
657
1199
|
* The postgres adapter now supports tables with capital letters.
|
658
|
-
|
1200
|
+
Fixes #5920.
|
659
1201
|
|
660
1202
|
*Yves Senn*
|
661
1203
|
|
@@ -677,7 +1219,7 @@
|
|
677
1219
|
*Francesco Rodriguez*
|
678
1220
|
|
679
1221
|
* Fix `reset_counters` crashing on `has_many :through` associations.
|
680
|
-
|
1222
|
+
Fixes #7822.
|
681
1223
|
|
682
1224
|
*lulalala*
|
683
1225
|
|
@@ -752,7 +1294,7 @@
|
|
752
1294
|
*Guillermo Iguaran*
|
753
1295
|
|
754
1296
|
* Fix the return of querying with an empty hash.
|
755
|
-
|
1297
|
+
Fixes #6971.
|
756
1298
|
|
757
1299
|
User.where(token: {})
|
758
1300
|
|
@@ -768,13 +1310,13 @@
|
|
768
1310
|
|
769
1311
|
* Fix creation of through association models when using `collection=[]`
|
770
1312
|
on a `has_many :through` association from an unsaved model.
|
771
|
-
|
1313
|
+
Fixes #7661.
|
772
1314
|
|
773
1315
|
*Ernie Miller*
|
774
1316
|
|
775
1317
|
* Explain only normal CRUD sql (select / update / insert / delete).
|
776
1318
|
Fix problem that explains unexplainable sql.
|
777
|
-
|
1319
|
+
Fixes #7544 #6458.
|
778
1320
|
|
779
1321
|
*kennyj*
|
780
1322
|
|
@@ -1107,7 +1649,7 @@
|
|
1107
1649
|
|
1108
1650
|
*Egor Lynko*
|
1109
1651
|
|
1110
|
-
* Added support for specifying the precision of a timestamp in the
|
1652
|
+
* Added support for specifying the precision of a timestamp in the PostgreSQL
|
1111
1653
|
adapter. So, instead of having to incorrectly specify the precision using the
|
1112
1654
|
`:limit` option, you may use `:precision`, as intended. For example, in a migration:
|
1113
1655
|
|
@@ -1162,7 +1704,7 @@
|
|
1162
1704
|
|
1163
1705
|
* Move HABTM validity checks to `ActiveRecord::Reflection`. One side effect of
|
1164
1706
|
this is to move when the exceptions are raised from the point of declaration
|
1165
|
-
to when the association is built. This is
|
1707
|
+
to when the association is built. This is consistent with other association
|
1166
1708
|
validity checks.
|
1167
1709
|
|
1168
1710
|
*Andrew White*
|
@@ -1375,7 +1917,7 @@
|
|
1375
1917
|
|
1376
1918
|
* Added the schema cache dump feature.
|
1377
1919
|
|
1378
|
-
`Schema cache dump` feature was
|
1920
|
+
`Schema cache dump` feature was implemented. This feature can dump/load internal state of `SchemaCache` instance
|
1379
1921
|
because we want to boot rails more quickly when we have many models.
|
1380
1922
|
|
1381
1923
|
Usage notes:
|
@@ -1403,13 +1945,13 @@
|
|
1403
1945
|
|
1404
1946
|
add_index(:accounts, :code, where: 'active')
|
1405
1947
|
|
1406
|
-
|
1948
|
+
generates
|
1407
1949
|
|
1408
1950
|
CREATE INDEX index_accounts_on_code ON accounts(code) WHERE active
|
1409
1951
|
|
1410
1952
|
*Marcelo Silveira*
|
1411
1953
|
|
1412
|
-
* Implemented ActiveRecord::Relation#none method.
|
1954
|
+
* Implemented `ActiveRecord::Relation#none` method.
|
1413
1955
|
|
1414
1956
|
The `none` method returns a chainable relation with zero records
|
1415
1957
|
(an instance of the NullRelation class).
|
@@ -1498,4 +2040,5 @@
|
|
1498
2040
|
|
1499
2041
|
*Aaron Patterson*
|
1500
2042
|
|
2043
|
+
|
1501
2044
|
Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activerecord/CHANGELOG.md) for previous changes.
|