Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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