Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 823 lines (536 sloc) 26.967 kb
776af48 @tenderlove PostgreSQL hstore types are automatically deserialized from the datab…
tenderlove authored
1 ## Rails 4.0.0 (unreleased) ##
9b40f5c @rafaelfranca Copy edit [ci skip]
rafaelfranca authored
2
f31ea4d Add CHANGELOG entry and update the guide
John Foley authored
3 * Allow before and after validations to take an array of lifecycle events
4
5 *John Foley*
6
392eeec @jonleighton Support for specifying transaction isolation level
jonleighton authored
7 * Support for specifying transaction isolation level
8
9 If your database supports setting the isolation level for a transaction, you can set
10 it like so:
11
12 Post.transaction(isolation: :serializable) do
13 # ...
14 end
15
16 Valid isolation levels are:
17
18 * `:read_uncommitted`
19 * `:read_committed`
20 * `:repeatable_read`
21 * `:serializable`
22
23 You should consult the documentation for your database to understand the
24 semantics of these different levels:
25
26 * http://www.postgresql.org/docs/9.1/static/transaction-iso.html
27 * https://dev.mysql.com/doc/refman/5.0/en/set-transaction.html
28
29 An `ActiveRecord::TransactionIsolationError` will be raised if:
30
31 * The adapter does not support setting the isolation level
32 * You are joining an existing open transaction
33 * You are creating a nested (savepoint) transaction
34
35 The mysql, mysql2 and postgresql adapters support setting the transaction
36 isolation level. However, support is disabled for mysql versions below 5,
37 because they are affected by a bug (http://bugs.mysql.com/bug.php?id=39170)
38 which means the isolation level gets persisted outside the transaction.
39
40 *Jon Leighton*
41
1f4c89f @guilleiguaran Update changelogs to add entries about strong_parameters integration
guilleiguaran authored
42 * `ActiveModel::ForbiddenAttributesProtection` is included by default
43 in Active Record models. Check the docs of `ActiveModel::ForbiddenAttributesProtection`
44 for more details.
45
46 *Guillermo Iguaran*
47
48 * Remove integration between Active Record and
49 `ActiveModel::MassAssignmentSecurity`, `protected_attributes` gem
50 should be added to use `attr_accessible`/`attr_protected`. Mass
51 assignment options has been removed from all the AR methods that
f4a9d7d remove unnecessary entry and make minor edits to AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
52 used it (ex. `AR::Base.new`, `AR::Base.create`, `AR::Base#update_attributes`, etc).
1f4c89f @guilleiguaran Update changelogs to add entries about strong_parameters integration
guilleiguaran authored
53
54 *Guillermo Iguaran*
55
69e0e3f @rafaelfranca Improve the CHANGELOG entry for #6971
rafaelfranca authored
56 * Fix the return of querying with an empty hash.
57 Fix #6971.
58
59 User.where(token: {})
60
61 Before:
62
63 #=> SELECT * FROM users;
64
65 After:
66
67 #=> SELECT * FROM users WHERE 1 = 2;
68
69 *Damien Mathieu*
30a576f @dmathieu fix querying with an empty hash
dmathieu authored
70
c35a7d7 @rafaelfranca Use the CHANGELOG convention [ci skip]
rafaelfranca authored
71 * Fix creation of through association models when using `collection=[]`
72 on a `has_many :through` association from an unsaved model.
73 Fix #7661.
610b632 @ernie Fix collection= on hm:t join models when unsaved
ernie authored
74
75 *Ernie Miller*
76
5bb056d @kennyj Don't explain except normal CRUD sql.
kennyj authored
77 * Explain only normal CRUD sql (select / update / insert / delete).
c35a7d7 @rafaelfranca Use the CHANGELOG convention [ci skip]
rafaelfranca authored
78 Fix problem that explains unexplainable sql.
79 Closes #7544 #6458.
5bb056d @kennyj Don't explain except normal CRUD sql.
kennyj authored
80
81 *kennyj*
82
46873ae @al2o3cr refactor store_accessor
al2o3cr authored
83 * You can now override the generated accessor methods for stored attributes
84 and reuse the original behavior with `read_store_attribute` and `write_store_attribute`,
85 which are counterparts to `read_attribute` and `write_attribute`.
86
87 *Matt Jones*
88
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
89 * Accept belongs_to (including polymorphic) association keys in queries.
3da275c @beerlington Accept belongs_to assoc. keys in ActiveRecord queries
beerlington authored
90
91 The following queries are now equivalent:
92
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
93 Post.where(author: author)
94 Post.where(author_id: author)
3da275c @beerlington Accept belongs_to assoc. keys in ActiveRecord queries
beerlington authored
95
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
96 PriceEstimate.where(estimate_of: treasure)
97 PriceEstimate.where(estimate_of_type: 'Treasure', estimate_of_id: treasure)
3da275c @beerlington Accept belongs_to assoc. keys in ActiveRecord queries
beerlington authored
98
99 *Peter Brown*
100
ccc6910 @kennyj Use native mysqldump command for 'rake db:structure:dump'.
kennyj authored
101 * Use native `mysqldump` command instead of `structure_dump` method
102 when dumping the database structure to a sql file. Fixes #5547.
103
104 *kennyj*
105
4544d2b @danmcclain Moves column dump specific code to a module included in AbstractAdapter
danmcclain authored
106 * PostgreSQL inet and cidr types are converted to `IPAddr` objects.
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
107
4544d2b @danmcclain Moves column dump specific code to a module included in AbstractAdapter
danmcclain authored
108 *Dan McClain*
109
110 * PostgreSQL array type support. Any datatype can be used to create an
111 array column, with full migration and schema dumper support.
112
113 To declare an array column, use the following syntax:
114
115 create_table :table_with_arrays do |t|
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
116 t.integer :int_array, array: true
4544d2b @danmcclain Moves column dump specific code to a module included in AbstractAdapter
danmcclain authored
117 # integer[]
f4a9d7d remove unnecessary entry and make minor edits to AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
118 t.integer :int_array, array: true, length: 2
4544d2b @danmcclain Moves column dump specific code to a module included in AbstractAdapter
danmcclain authored
119 # smallint[]
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
120 t.string :string_array, array: true, length: 30
4544d2b @danmcclain Moves column dump specific code to a module included in AbstractAdapter
danmcclain authored
121 # char varying(30)[]
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
122 end
4544d2b @danmcclain Moves column dump specific code to a module included in AbstractAdapter
danmcclain authored
123
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
124 This respects any other migration detail (limits, defaults, etc).
254a324 @fxn ActiveRecord -> Active Record
fxn authored
125 Active Record will serialize and deserialize the array columns on
4544d2b @danmcclain Moves column dump specific code to a module included in AbstractAdapter
danmcclain authored
126 their way to and from the database.
127
128 One thing to note: PostgreSQL does not enforce any limits on the
129 number of elements, and any array can be multi-dimensional. Any
130 array that is multi-dimensional must be rectangular (each sub array
131 must have the same number of elements as its siblings).
132
133 If the `pg_array_parser` gem is available, it will be used when
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
134 parsing PostgreSQL's array representation.
4544d2b @danmcclain Moves column dump specific code to a module included in AbstractAdapter
danmcclain authored
135
136 *Dan McClain*
137
4f107da @ernie Raise MissingAttributeError on query methods
ernie authored
138 * Attribute predicate methods, such as `article.title?`, will now raise
139 `ActiveModel::MissingAttributeError` if the attribute being queried for
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
140 truthiness was not read from the database, instead of just returning `false`.
4f107da @ernie Raise MissingAttributeError on query methods
ernie authored
141
142 *Ernie Miller*
143
aaa33e6 @carlosantoniodasilva Improve latest AR and AP changelog entries
carlosantoniodasilva authored
144 * `ActiveRecord::SchemaDumper` uses Ruby 1.9 style hash, which means that the
145 schema.rb file will be generated using this new syntax from now on.
146
147 *Konstantin Shabanov*
b485b8a @etehtsea Dump schema using new style hash
etehtsea authored
148
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
149 * Map interval with precision to string datatype in PostgreSQL. Fixes #7518.
150
151 *Yves Senn*
f415475 @carlosantoniodasilva Add changelog entry for #7545: map interval with precision to string
carlosantoniodasilva authored
152
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
153 * Fix eagerly loading associations without primary keys. Fixes #4976.
154
155 *Kelley Reynolds*
d8fbfee @carlosantoniodasilva Add Changelog entry for #4976: fix eager load associations without pk…
carlosantoniodasilva authored
156
db8460c @sikachu Update Active Record CHANGELOG for #7419
sikachu authored
157 * Rails now raise an exception when you're trying to run a migration that has an invalid
158 file name. Only lower case letters, numbers, and '_' are allowed in migration's file name.
159 Please see #7419 for more details.
160
161 *Jan Bernacki*
162
46873ae @al2o3cr refactor store_accessor
al2o3cr authored
163 * Fix bug when calling `store_accessor` multiple times.
ddaeaef @rafaelfranca Add CHANGELOG entry for #7532 [ci skip]
rafaelfranca authored
164 Fixes #7532.
165
166 *Matt Jones*
167
168 * Fix store attributes that show the changes incorrectly.
169 Fixes #7532.
170
171 *Matt Jones*
172
c7d752f @elliterate Fix pluck when columns/tables are reserved words.
elliterate authored
173 * Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
174
175 *Ian Lesperance*
176
65ce6fb improve AR CHANGELOG [ci skip]
Francesco Rodriguez authored
177 * Allow JSON columns to be created in PostgreSQL and properly encoded/decoded.
3b516b5 @guedes ActiveRecord support to PostgreSQL 9.2 JSON type
guedes authored
178 to/from database.
179
180 *Dickson S. Guedes*
181
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
182 * Fix time column type casting for invalid time string values to correctly return `nil`.
acf583a @adzap Update changelog with time column type casting fix
adzap authored
183
184 *Adam Meehan*
185
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
186 * Allow to pass Symbol or Proc into `:limit` option of #accepts_nested_attributes_for.
ff8f759 @Mik-die changelog #7449
Mik-die authored
187
188 *Mikhail Dieterle*
189
0ffe190 @sikachu Extract ActiveRecord::SessionStore from Rails
sikachu authored
190 * ActiveRecord::SessionStore has been extracted from Active Record as `activerecord-session_store`
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
191 gem. Please read the `README.md` file on the gem for the usage.
192
193 *Prem Sichanugrist*
0ffe190 @sikachu Extract ActiveRecord::SessionStore from Rails
sikachu authored
194
ff0d9b9 @Pliny reset_counters() was crashing when there were multiple belongs_to ass…
Pliny authored
195 * Fix `reset_counters` when there are multiple `belongs_to` association with the
196 same foreign key and one of them have a counter cache.
197 Fixes #5200.
198
199 *Dave Desrochers*
200
57bef99 @kennyj Use instance_accessor: false instead of instance_writer.
kennyj authored
201 * `serialized_attributes` and `_attr_readonly` become class method only. Instance reader methods are deprecated.
202
203 *kennyj*
204
55d943c @rafaelfranca Add CHANGELOG entry for #6986
rafaelfranca authored
205 * Round usec when comparing timestamp attributes in the dirty tracking.
206 Fixes #6975.
207
208 *kennyj*
209
c9c5566 @brainopia Use inversed parent for first and last child of has_many association
brainopia authored
210 * Use inversed parent for first and last child of has_many association.
211
212 *Ravil Bayramgalin*
213
53ca22f @aripollak Fix occasional microsecond conversion inaccuracy
aripollak authored
214 * Fix Column.microseconds and Column.fast_string_to_date to avoid converting
215 timestamp seconds to a float, since it occasionally results in inaccuracies
216 with microsecond-precision times. Fixes #7352.
217
218 *Ari Pollak*
219
dd64f0a @carlosantoniodasilva Move changelog entry to the top [ci skip]
carlosantoniodasilva authored
220 * Raise `ArgumentError` if list of attributes to change is empty in `update_all`.
221
222 *Roman Shatsov*
223
a4801a7 @daveyeu Restore state on create when ActiveRecord::RecordInvalid is raised
daveyeu authored
224 * Fix AR#create to return an unsaved record when AR::RecordInvalid is
225 raised. Fixes #3217.
226
227 *Dave Yeu*
228
65ce6fb improve AR CHANGELOG [ci skip]
Francesco Rodriguez authored
229 * Fixed table name prefix that is generated in engines for namespaced models.
230
21b5b6a @morgoth Added changelog entry for table name prefix fix [ci skip]
morgoth authored
231 *Wojciech Wnętrzak*
232
65ce6fb improve AR CHANGELOG [ci skip]
Francesco Rodriguez authored
233 * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`.
e7e8656 @rafaelfranca Update changelog
rafaelfranca authored
234 Fixes #4772.
235
236 *Seamus Abshere*
237
bf2df6e @jonleighton Allow Relation#merge to take a proc.
jonleighton authored
238 * Allow Relation#merge to take a proc.
239
240 This was requested by DHH to allow creating of one's own custom
241 association macros.
242
243 For example:
244
245 module Commentable
246 def has_many_comments(extra)
247 has_many :comments, -> { where(:foo).merge(extra) }
248 end
249 end
250
251 class Post < ActiveRecord::Base
252 extend Commentable
253 has_many_comments -> { where(:bar) }
254 end
255
256 *Jon Leighton*
257
65ce6fb improve AR CHANGELOG [ci skip]
Francesco Rodriguez authored
258 * Add CollectionProxy#scope.
0e1cafc @jonleighton Add CollectionProxy#scope
jonleighton authored
259
260 This can be used to get a Relation from an association.
261
262 Previously we had a #scoped method, but we're deprecating that for
263 AR::Base, so it doesn't make sense to have it here.
264
265 This was requested by DHH, to facilitate code like this:
266
267 Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do
268 @topics = @project.topics.scope
269 @todolists = @project.todolists.scope
270 @attachments = @project.attachments.scope
271 @documents = @project.documents.scope
272 end
273
274 *Jon Leighton*
275
65ce6fb improve AR CHANGELOG [ci skip]
Francesco Rodriguez authored
276 * Add `Relation#load`.
437851e @jonleighton Add `Relation#load`
jonleighton authored
277
278 This method explicitly loads the records and then returns `self`.
279
280 Rather than deciding between "do I want an array or a relation?",
281 most people are actually asking themselves "do I want to eager load
282 or lazy load?" Therefore, this method provides a way to explicitly
283 eager-load without having to switch from a `Relation` to an array.
284
285 Example:
286
287 @posts = Post.where(published: true).load
288
289 *Jon Leighton*
290
0a6833b @jonleighton reinstate changelog that seems to have been accidentally deleted o_O
jonleighton authored
291 * `Model.all` now returns an `ActiveRecord::Relation`, rather than an
65ce6fb improve AR CHANGELOG [ci skip]
Francesco Rodriguez authored
292 array of records. Use `Relation#to_a` if you really want an array.
0a6833b @jonleighton reinstate changelog that seems to have been accidentally deleted o_O
jonleighton authored
293
294 In some specific cases, this may cause breakage when upgrading.
295 However in most cases the `ActiveRecord::Relation` will just act as a
296 lazy-loaded array and there will be no problems.
297
298 Note that calling `Model.all` with options (e.g.
299 `Model.all(conditions: '...')` was already deprecated, but it will
300 still return an array in order to make the transition easier.
301
302 `Model.scoped` is deprecated in favour of `Model.all`.
303
304 `Relation#all` still returns an array, but is deprecated (since it
305 would serve no purpose if we made it return a `Relation`).
306
307 *Jon Leighton*
308
4efebde @jonleighton Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql.
jonleighton authored
309 * `:finder_sql` and `:counter_sql` options on collection associations
310 are deprecated. Please transition to using scopes.
311
312 *Jon Leighton*
313
314 * `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
315 associations are deprecated. Please transition to using `has_many
65ce6fb improve AR CHANGELOG [ci skip]
Francesco Rodriguez authored
316 :through`.
4efebde @jonleighton Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql.
jonleighton authored
317
318 *Jon Leighton*
319
e243a8a @josevalim Update changelog for migration generator change
josevalim authored
320 * The migration generator now creates a join table with (commented) indexes every time
321 the migration name contains the word `join_table`:
322
2470501 @josevalim Use attributes instead of table names in migration example
josevalim authored
323 rails g migration create_join_table_for_artists_and_musics artist_id:index music_id
e243a8a @josevalim Update changelog for migration generator change
josevalim authored
324
325 *Aleksey Magusev*
326
17d2115 @lexmag Add changelog entry for references statements
lexmag authored
327 * Add `add_reference` and `remove_reference` schema statements. Aliases, `add_belongs_to`
328 and `remove_belongs_to` are acceptable. References are reversible.
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
329
48fe382 @carlosantoniodasilva Update release notes with AR::Relation#inspect change [ci skip]
carlosantoniodasilva authored
330 Examples:
17d2115 @lexmag Add changelog entry for references statements
lexmag authored
331
332 # Create a user_id column
333 add_reference(:products, :user)
48fe382 @carlosantoniodasilva Update release notes with AR::Relation#inspect change [ci skip]
carlosantoniodasilva authored
334 # Create a supplier_id, supplier_type columns and appropriate index
17d2115 @lexmag Add changelog entry for references statements
lexmag authored
335 add_reference(:products, :supplier, polymorphic: true, index: true)
336 # Remove polymorphic reference
337 remove_reference(:products, :supplier, polymorphic: true)
338
339 *Aleksey Magusev*
340
ab72040 @carlosantoniodasilva Update AR and AP changelogs [ci skip]
carlosantoniodasilva authored
341 * Add `:default` and `:null` options to `column_exists?`.
342
343 column_exists?(:testings, :taggable_id, :integer, null: false)
344 column_exists?(:testings, :taggable_type, :string, default: 'Photo')
345
346 *Aleksey Magusev*
347
07314e6 @jonleighton Show the records in Relation#inspect
jonleighton authored
348 * `ActiveRecord::Relation#inspect` now makes it clear that you are
349 dealing with a `Relation` object rather than an array:.
ab72040 @carlosantoniodasilva Update AR and AP changelogs [ci skip]
carlosantoniodasilva authored
350
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
351 User.where(age: 30).inspect
c046a29 @ayrton Update activerecord/CHANGELOG.md
ayrton authored
352 # => <ActiveRecord::Relation [#<User ...>, #<User ...>, ...]>
05c7e0a @bcardarella Remove ActiveRelation#inspect
bcardarella authored
353
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
354 User.where(age: 30).to_a.inspect
c046a29 @ayrton Update activerecord/CHANGELOG.md
ayrton authored
355 # => [#<User ...>, #<User ...>]
07314e6 @jonleighton Show the records in Relation#inspect
jonleighton authored
356
7d0053e @dmathieu Limit the number of records in Relation#inspect
dmathieu authored
357 The number of records displayed will be limited to 10.
358
359 *Brian Cardarella, Jon Leighton & Damien Mathieu*
05c7e0a @bcardarella Remove ActiveRelation#inspect
bcardarella authored
360
aafa00f @rafaelfranca Unify the collation API for the database adpters
rafaelfranca authored
361 * Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
8fe458a @kennyj Added an entry about fda24312d3 in the CHANGELOG.
kennyj authored
362 Example:
363
c046a29 @ayrton Update activerecord/CHANGELOG.md
ayrton authored
364 development:
365 adapter: postgresql
366 host: localhost
367 database: rails_development
368 username: foo
369 password: bar
370 encoding: UTF8
371 collation: ja_JP.UTF8
372 ctype: ja_JP.UTF8
8fe458a @kennyj Added an entry about fda24312d3 in the CHANGELOG.
kennyj authored
373
374 *kennyj*
375
9feda92 AR has a subclass of AM:PresenceValidator.
Brent Wheeldon & Nick Monje authored
376 * Changed validates_presence_of on an association so that children objects
377 do not validate as being present if they are marked for destruction. This
378 prevents you from saving the parent successfully and thus putting the parent
379 in an invalid state.
380
381 *Nick Monje & Brent Wheeldon*
382
359592b @flexoid exists?(false) returns false
flexoid authored
383 * `FinderMethods#exists?` now returns `false` with the `false` argument.
384
385 *Egor Lynko*
386
6657ec9 @tonywok Allow precision option for postgresql datetimes
tonywok authored
387 * Added support for specifying the precision of a timestamp in the postgresql
388 adapter. So, instead of having to incorrectly specify the precision using the
389 `:limit` option, you may use `:precision`, as intended. For example, in a migration:
390
391 def change
392 create_table :foobars do |t|
393 t.timestamps :precision => 0
394 end
395 end
396
397 *Tony Schneider*
398
215d41d @carlosantoniodasilva Update 4.0 Release Notes with changelogs [ci skip]
carlosantoniodasilva authored
399 * Allow `ActiveRecord::Relation#pluck` to accept multiple columns. Returns an
9298d60 @carlosantoniodasilva Fix changelog typo [ci skip]
carlosantoniodasilva authored
400 array of arrays containing the typecasted values:
e5cd300 @carlosantoniodasilva Add changelog entry and guide updates for pluck with multiple columns
carlosantoniodasilva authored
401
402 Person.pluck(:id, :name)
403 # SELECT people.id, people.name FROM people
404 # [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]
405
406 *Jeroen van Ingen & Carlos Antonio da Silva*
407
4649294 @pixeltrix Improve the derivation of HABTM assocation join table names
pixeltrix authored
408 * Improve the derivation of HABTM join table name to take account of nesting.
409 It now takes the table names of the two models, sorts them lexically and
410 then joins them, stripping any common prefix from the second table name.
411
412 Some examples:
413
414 Top level models (Category <=> Product)
415 Old: categories_products
416 New: categories_products
417
418 Top level models with a global table_name_prefix (Category <=> Product)
419 Old: site_categories_products
420 New: site_categories_products
421
422 Nested models in a module without a table_name_prefix method (Admin::Category <=> Admin::Product)
423 Old: categories_products
424 New: categories_products
425
426 Nested models in a module with a table_name_prefix method (Admin::Category <=> Admin::Product)
427 Old: categories_products
428 New: admin_categories_products
429
430 Nested models in a parent model (Catalog::Category <=> Catalog::Product)
431 Old: categories_products
432 New: catalog_categories_products
433
434 Nested models in different parent models (Catalog::Category <=> Content::Page)
435 Old: categories_pages
436 New: catalog_categories_content_pages
437
438 *Andrew White*
439
215d41d @carlosantoniodasilva Update 4.0 Release Notes with changelogs [ci skip]
carlosantoniodasilva authored
440 * Move HABTM validity checks to `ActiveRecord::Reflection`. One side effect of
4649294 @pixeltrix Improve the derivation of HABTM assocation join table names
pixeltrix authored
441 this is to move when the exceptions are raised from the point of declaration
442 to when the association is built. This is consistant with other association
443 validity checks.
444
445 *Andrew White*
446
8593964 @carlosantoniodasilva Refactor and use class_attribute
carlosantoniodasilva authored
447 * Added `stored_attributes` hash which contains the attributes stored using
215d41d @carlosantoniodasilva Update 4.0 Release Notes with changelogs [ci skip]
carlosantoniodasilva authored
448 `ActiveRecord::Store`. This allows you to retrieve the list of attributes
8593964 @carlosantoniodasilva Refactor and use class_attribute
carlosantoniodasilva authored
449 you've defined.
757f723 @tilsammans Remember the stored attributes in a config attribute.
tilsammans authored
450
8593964 @carlosantoniodasilva Refactor and use class_attribute
carlosantoniodasilva authored
451 class User < ActiveRecord::Base
452 store :settings, accessors: [:color, :homepage]
453 end
454
455 User.stored_attributes[:settings] # [:color, :homepage]
456
457 *Joost Baaij & Carlos Antonio da Silva*
757f723 @tilsammans Remember the stored attributes in a config attribute.
tilsammans authored
458
052e415 @kennyj Change minimum (default) log level in PostgreSQL to warning.
kennyj authored
459 * PostgreSQL default log level is now 'warning', to bypass the noisy notice
460 messages. You can change the log level using the `min_messages` option
461 available in your config/database.yml.
462
463 *kennyj*
464
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
465 * Add uuid datatype support to PostgreSQL adapter.
466
467 *Konstantin Shabanov*
508834c @rafaelfranca Add CHANGELOG entry to the uuid datatype support to PostgreSQL adpter
rafaelfranca authored
468
03f2249 @josevalim Use . instead of :: for class methods, add CHANGELOG entries
josevalim authored
469 * Added `ActiveRecord::Migration.check_pending!` that raises an error if
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
470 migrations are pending.
471
472 *Richard Schneeman*
03f2249 @josevalim Use . instead of :: for class methods, add CHANGELOG entries
josevalim authored
473
4faaa81 @marcandre + ActiveRecord::Base#destroy!
marcandre authored
474 * Added `#destroy!` which acts like `#destroy` but will raise an
475 `ActiveRecord::RecordNotDestroyed` exception instead of returning `false`.
476
477 *Marc-André Lafortune*
478
f9cb645 @carlosantoniodasilva Yield only one argument instead of splatting.
carlosantoniodasilva authored
479 * Allow blocks for `count` with `ActiveRecord::Relation`, to work similar as
480 `Array#count`:
481
c51fb02 @carlosantoniodasilva Fix changelog example for count method with block [ci skip]
carlosantoniodasilva authored
482 Person.where("age > 26").count { |person| person.gender == 'female' }
f9cb645 @carlosantoniodasilva Yield only one argument instead of splatting.
carlosantoniodasilva authored
483
484 *Chris Finne & Carlos Antonio da Silva*
485
39f0698 Add support for CollectionAssociation#delete by Fixnum or String
Francesco Rodriguez authored
486 * Added support to `CollectionAssociation#delete` for passing `fixnum`
487 or `string` values as record ids. This finds the records responding
488 to the `id` and executes delete on them.
489
490 class Person < ActiveRecord::Base
491 has_many :pets
492 end
493
494 person.pets.delete("1") # => [#<Pet id: 1>]
495 person.pets.delete(2, 3) # => [#<Pet id: 2>, #<Pet id: 3>]
496
497 *Francesco Rodriguez*
498
103ce30 @jonleighton add changelogs about deprecated stuff [ci skip]
jonleighton authored
499 * Deprecated most of the 'dynamic finder' methods. All dynamic methods
500 except for `find_by_...` and `find_by_...!` are deprecated. Here's
501 how you can rewrite the code:
502
503 * `find_all_by_...` can be rewritten using `where(...)`
504 * `find_last_by_...` can be rewritten using `where(...).last`
505 * `scoped_by_...` can be rewritten using `where(...)`
506 * `find_or_initialize_by_...` can be rewritten using
507 `where(...).first_or_initialize`
508 * `find_or_create_by_...` can be rewritten using
1ae68ea @jonleighton fix typo [ci skip]
jonleighton authored
509 `where(...).first_or_create`
103ce30 @jonleighton add changelogs about deprecated stuff [ci skip]
jonleighton authored
510 * `find_or_create_by_...!` can be rewritten using
511 `where(...).first_or_create!`
512
513 The implementation of the deprecated dynamic finders has been moved
17bb324 @jonleighton Renaming active_record_deprecated_finders to activerecord-deprecated_…
jonleighton authored
514 to the `activerecord-deprecated_finders` gem. See below for details.
103ce30 @jonleighton add changelogs about deprecated stuff [ci skip]
jonleighton authored
515
516 *Jon Leighton*
517
518 * Deprecated the old-style hash based finder API. This means that
519 methods which previously accepted "finder options" no longer do. For
520 example this:
521
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
522 Post.find(:all, conditions: { comments_count: 10 }, limit: 5)
103ce30 @jonleighton add changelogs about deprecated stuff [ci skip]
jonleighton authored
523
524 Should be rewritten in the new style which has existed since Rails 3:
525
526 Post.where(comments_count: 10).limit(5)
527
528 Note that as an interim step, it is possible to rewrite the above as:
529
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
530 Post.all.merge(where: { comments_count: 10 }, limit: 5)
103ce30 @jonleighton add changelogs about deprecated stuff [ci skip]
jonleighton authored
531
532 This could save you a lot of work if there is a lot of old-style
533 finder usage in your application.
534
3205c76 @jonleighton Changelog and doc updates for the previous changes.
jonleighton authored
535 `Relation#merge` now accepts a hash of
103ce30 @jonleighton add changelogs about deprecated stuff [ci skip]
jonleighton authored
536 options, but they must be identical to the names of the equivalent
537 finder method. These are mostly identical to the old-style finder
538 option names, except in the following cases:
539
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
540 * `:conditions` becomes `:where`.
541 * `:include` becomes `:includes`.
542 * `:extend` becomes `:extending`.
103ce30 @jonleighton add changelogs about deprecated stuff [ci skip]
jonleighton authored
543
544 The code to implement the deprecated features has been moved out to
17bb324 @jonleighton Renaming active_record_deprecated_finders to activerecord-deprecated_…
jonleighton authored
545 the `activerecord-deprecated_finders` gem. This gem is a dependency
103ce30 @jonleighton add changelogs about deprecated stuff [ci skip]
jonleighton authored
546 of Active Record in Rails 4.0. It will no longer be a dependency
547 from Rails 4.1, but if your app relies on the deprecated features
548 then you can add it to your own Gemfile. It will be maintained by
549 the Rails core team until Rails 5.0 is released.
550
551 *Jon Leighton*
552
a8b370f @iGEL Don't destroy readonly models
iGEL authored
553 * It's not possible anymore to destroy a model marked as read only.
554
555 *Johannes Barre*
556
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
557 * Added ability to ActiveRecord::Relation#from to accept other ActiveRecord::Relation objects.
64872d1 @RStankov Relation#from to accept other Relation objects
RStankov authored
558
559 Record.from(subquery)
560 Record.from(subquery, :a)
561
562 *Radoslav Stankov*
563
3c0bf04 @Antiarchitect Custom coders support for ActiveRecord::Store. JSON, YAML, Marshal ca…
Antiarchitect authored
564 * Added custom coders support for ActiveRecord::Store. Now you can set
565 your custom coder like this:
566
567 store :settings, accessors: [ :color, :homepage ], coder: JSON
568
569 *Andrey Voronkov*
776af48 @tenderlove PostgreSQL hstore types are automatically deserialized from the datab…
tenderlove authored
570
2054a17 @mipearson Changelog entry regarding mysql(2) STRICT_ALL_TABLES
mipearson authored
571 * `mysql` and `mysql2` connections will set `SQL_MODE=STRICT_ALL_TABLES` by
572 default to avoid silent data loss. This can be disabled by specifying
573 `strict: false` in your `database.yml`.
574
575 *Michael Pearson*
576
66b9e4c @mhfs Adding note about `first` and `take` to the changelog
mhfs authored
577 * Added default order to `first` to assure consistent results among
578 diferent database engines. Introduced `take` as a replacement to
579 the old behavior of `first`.
580
581 *Marcelo Silveira*
582
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
583 * Added an `:index` option to automatically create indexes for references
ca0af82 @joshuap Automatically create indexes for references/belongs_to statements in …
joshuap authored
584 and belongs_to statements in migrations.
585
586 The `references` and `belongs_to` methods now support an `index`
587 option that receives either a boolean value or an options hash
588 that is identical to options available to the add_index method:
589
590 create_table :messages do |t|
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
591 t.references :person, index: true
ca0af82 @joshuap Automatically create indexes for references/belongs_to statements in …
joshuap authored
592 end
593
594 Is the same as:
595
596 create_table :messages do |t|
597 t.references :person
598 end
599 add_index :messages, :person_id
600
601 Generators have also been updated to use the new syntax.
602
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
603 *Joshua Wood*
ca0af82 @joshuap Automatically create indexes for references/belongs_to statements in …
joshuap authored
604
8c2c605 @jonleighton Add bang versions of relation query methods.
jonleighton authored
605 * Added bang methods for mutating `ActiveRecord::Relation` objects.
606 For example, while `foo.where(:bar)` will return a new object
607 leaving `foo` unchanged, `foo.where!(:bar)` will mutate the foo
608 object
609
610 *Jon Leighton*
611
13b3c77 @jonleighton Add Relation#find_by and Relation#find_by!
jonleighton authored
612 * Added `#find_by` and `#find_by!` to mirror the functionality
613 provided by dynamic finders in a way that allows dynamic input more
614 easily:
615
616 Post.find_by name: 'Spartacus', rating: 4
617 Post.find_by "published_at < ?", 2.weeks.ago
618 Post.find_by! name: 'Spartacus'
619
620 *Jon Leighton*
621
bb2e2d8 @guilleiguaran CHANGELOG entry for AR#slice
guilleiguaran authored
622 * Added ActiveRecord::Base#slice to return a hash of the given methods with
623 their names as keys and returned values as values.
624
625 *Guillermo Iguaran*
626
0a12a5f @jonleighton Deprecate eager-evaluated scopes.
jonleighton authored
627 * Deprecate eager-evaluated scopes.
628
629 Don't use this:
630
631 scope :red, where(color: 'red')
632 default_scope where(color: 'red')
633
634 Use this:
635
636 scope :red, -> { where(color: 'red') }
637 default_scope { where(color: 'red') }
638
639 The former has numerous issues. It is a common newbie gotcha to do
640 the following:
641
642 scope :recent, where(published_at: Time.now - 2.weeks)
643
644 Or a more subtle variant:
645
646 scope :recent, -> { where(published_at: Time.now - 2.weeks) }
647 scope :recent_red, recent.where(color: 'red')
648
649 Eager scopes are also very complex to implement within Active
650 Record, and there are still bugs. For example, the following does
651 not do what you expect:
652
653 scope :remove_conditions, except(:where)
654 where(...).remove_conditions # => still has conditions
655
656 *Jon Leighton*
657
dde3058 @carlosantoniodasilva Expand changelog and upgrading rails guide with IdentityMap info
carlosantoniodasilva authored
658 * Remove IdentityMap
659
660 IdentityMap has never graduated to be an "enabled-by-default" feature, due
661 to some inconsistencies with associations, as described in this commit:
662
663 https://github.com/rails/rails/commit/302c912bf6bcd0fa200d964ec2dc4a44abe328a6
664
665 Hence the removal from the codebase, until such issues are fixed.
666
667 *Carlos Antonio da Silva*
a8dd21d @carlosantoniodasilva Remove IdentityMap
carlosantoniodasilva authored
668
46c1217 @kennyj Add entry for schema cache dump to CHANGELOG.md.
kennyj authored
669 * Added the schema cache dump feature.
670
671 `Schema cache dump` feature was implemetend. This feature can dump/load internal state of `SchemaCache` instance
672 because we want to boot rails more quickly when we have many models.
673
674 Usage notes:
675
676 1) execute rake task.
677 RAILS_ENV=production bundle exec rake db:schema:cache:dump
678 => generate db/schema_cache.dump
679
79dc922 @kennyj Change AR's CHANGELOG, because it is related to e35c67ae0f920011a2440…
kennyj authored
680 2) add config.active_record.use_schema_cache_dump = true in config/production.rb. BTW, true is default.
46c1217 @kennyj Add entry for schema cache dump to CHANGELOG.md.
kennyj authored
681
682 3) boot rails.
683 RAILS_ENV=production bundle exec rails server
aa9b647 @kennyj Update CHANGELOG to fix wrong extension.
kennyj authored
684 => use db/schema_cache.dump
46c1217 @kennyj Add entry for schema cache dump to CHANGELOG.md.
kennyj authored
685
686 4) If you remove clear dumped cache, execute rake task.
687 RAILS_ENV=production bundle exec rake db:schema:cache:clear
688 => remove db/schema_cache.dump
689
690 *kennyj*
691
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
692 * Added support for partial indices to PostgreSQL adapter.
d70e023 @mhfs Added where option to add_index to support postgresql partial indices
mhfs authored
693
694 The `add_index` method now supports a `where` option that receives a
695 string with the partial index criteria.
696
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
697 add_index(:accounts, :code, where: 'active')
d70e023 @mhfs Added where option to add_index to support postgresql partial indices
mhfs authored
698
8781b26 @rafaelfranca Sync CHANGELOGs [ci skip]
rafaelfranca authored
699 Generates
d70e023 @mhfs Added where option to add_index to support postgresql partial indices
mhfs authored
700
8781b26 @rafaelfranca Sync CHANGELOGs [ci skip]
rafaelfranca authored
701 CREATE INDEX index_accounts_on_code ON accounts(code) WHERE active
d70e023 @mhfs Added where option to add_index to support postgresql partial indices
mhfs authored
702
703 *Marcelo Silveira*
704
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
705 * Implemented ActiveRecord::Relation#none method.
8270e4a @xuanxu Added `none` query method to return zero records.
xuanxu authored
706
707 The `none` method returns a chainable relation with zero records
708 (an instance of the NullRelation class).
709
710 Any subsequent condition chained to the returned relation will continue
711 generating an empty relation and will not fire any query to the database.
712
713 *Juanjo Bazán*
714
715 * Added the `ActiveRecord::NullRelation` class implementing the null
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
716 object pattern for the Relation class.
8270e4a @xuanxu Added `none` query method to return zero records.
xuanxu authored
717
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
718 *Juanjo Bazán*
719
720 * Added new `dependent: :restrict_with_error` option. This will add
5ad7998 @jonleighton Remove the dependent_restrict_raises option.
jonleighton authored
721 an error to the model, rather than raising an exception.
336ff8a @hindenbug has_many/has_one, :dependent => :restrict, deprecation added.
hindenbug authored
722
5ad7998 @jonleighton Remove the dependent_restrict_raises option.
jonleighton authored
723 The `:restrict` option is renamed to `:restrict_with_exception` to
724 make this distinction explicit.
336ff8a @hindenbug has_many/has_one, :dependent => :restrict, deprecation added.
hindenbug authored
725
5ad7998 @jonleighton Remove the dependent_restrict_raises option.
jonleighton authored
726 *Manoj Kumar & Jon Leighton*
336ff8a @hindenbug has_many/has_one, :dependent => :restrict, deprecation added.
hindenbug authored
727
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
728 * Added `create_join_table` migration helper to create HABTM join tables.
080bd83 @rafaelfranca Add `create_join_table` migration helper to create HABTM join tables
rafaelfranca authored
729
730 create_join_table :products, :categories
731 # =>
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
732 # create_table :categories_products, id: false do |td|
733 # td.integer :product_id, null: false
734 # td.integer :category_id, null: false
080bd83 @rafaelfranca Add `create_join_table` migration helper to create HABTM join tables
rafaelfranca authored
735 # end
736
737 *Rafael Mendonça França*
738
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
739 * The primary key is always initialized in the @attributes hash to `nil` (unless
080bd83 @rafaelfranca Add `create_join_table` migration helper to create HABTM join tables
rafaelfranca authored
740 another value has been specified).
522c0fd @tenderlove The primary key is always initialized in the @attributes hash to nil …
tenderlove authored
741
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
742 *Aaron Paterson*
743
a2dab46 @jonleighton Deprecate inferred JOINs with includes + SQL snippets.
jonleighton authored
744 * In previous releases, the following would generate a single query with
745 an `OUTER JOIN comments`, rather than two separate queries:
746
747 Post.includes(:comments)
748 .where("comments.name = 'foo'")
749
750 This behaviour relies on matching SQL string, which is an inherently
751 flawed idea unless we write an SQL parser, which we do not wish to
752 do.
753
8c0c083 @jonleighton Make it more explicit that the feature is deprecated, not removed.
jonleighton authored
754 Therefore, it is now deprecated.
755
756 To avoid deprecation warnings and for future compatibility, you must
757 explicitly state which tables you reference, when using SQL snippets:
a2dab46 @jonleighton Deprecate inferred JOINs with includes + SQL snippets.
jonleighton authored
758
759 Post.includes(:comments)
760 .where("comments.name = 'foo'")
761 .references(:comments)
762
763 Note that you do not need to explicitly specify references in the
764 following cases, as they can be automatically inferred:
765
766 Post.where(comments: { name: 'foo' })
767 Post.where('comments.name' => 'foo')
768 Post.order('comments.name')
769
770 You also do not need to worry about this unless you are doing eager
771 loading. Basically, don't worry unless you see a deprecation warning
772 or (in future releases) an SQL error due to a missing JOIN.
773
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
774 *Jon Leighton*
a2dab46 @jonleighton Deprecate inferred JOINs with includes + SQL snippets.
jonleighton authored
775
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
776 * Support for the `schema_info` table has been dropped. Please
f82e244 @tenderlove dropping support for `schema_info`.
tenderlove authored
777 switch to `schema_migrations`.
778
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
779 *Aaron Patterson*
780
781 * Connections *must* be closed at the end of a thread. If not, your
6769293 @tenderlove connections must be checked in at the end of a thread
tenderlove authored
782 connection pool can fill and an exception will be raised.
783
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
784 *Aaron Patterson*
785
00318e9 @jonleighton Add some doc for ActiveRecord::Model
jonleighton authored
786 * Added the `ActiveRecord::Model` module which can be included in a
787 class as an alternative to inheriting from `ActiveRecord::Base`:
788
789 class Post
790 include ActiveRecord::Model
791 end
792
793 Please note:
794
795 * Up until now it has been safe to assume that all AR models are
796 descendants of `ActiveRecord::Base`. This is no longer a safe
797 assumption, but it may transpire that there are areas of the
798 code which still make this assumption. So there may be
799 'teething difficulties' with this feature. (But please do try it
800 and report bugs.)
801
802 * Plugins & libraries etc that add methods to `ActiveRecord::Base`
803 will not be compatible with `ActiveRecord::Model`. Those libraries
804 should add to `ActiveRecord::Model` instead (which is included in
805 `Base`), or better still, avoid monkey-patching AR and instead
806 provide a module that users can include where they need it.
807
808 * To minimise the risk of conflicts with other code, it is
809 advisable to include `ActiveRecord::Model` early in your class
810 definition.
811
812 *Jon Leighton*
813
96838b5 @tenderlove can create hstore records via AR API
tenderlove authored
814 * PostgreSQL hstore records can be created.
815
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
816 *Aaron Patterson*
817
776af48 @tenderlove PostgreSQL hstore types are automatically deserialized from the datab…
tenderlove authored
818 * PostgreSQL hstore types are automatically deserialized from the database.
819
0aaf87c improve AR/CHANGELOG [ci skip]
Francesco Rodriguez authored
820 *Aaron Patterson*
821
810a50d @fxn CHANGELOGs are now per branch
fxn authored
822 Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activerecord/CHANGELOG.md) for previous changes.
Something went wrong with that request. Please try again.