activerecord 3.1.12 → 3.2.22.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +804 -338
  3. data/README.rdoc +3 -3
  4. data/examples/performance.rb +20 -1
  5. data/lib/active_record/aggregations.rb +1 -1
  6. data/lib/active_record/associations/alias_tracker.rb +3 -6
  7. data/lib/active_record/associations/association.rb +13 -45
  8. data/lib/active_record/associations/association_scope.rb +3 -15
  9. data/lib/active_record/associations/belongs_to_association.rb +1 -1
  10. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +2 -1
  11. data/lib/active_record/associations/builder/association.rb +6 -4
  12. data/lib/active_record/associations/builder/belongs_to.rb +7 -4
  13. data/lib/active_record/associations/builder/collection_association.rb +2 -2
  14. data/lib/active_record/associations/builder/has_many.rb +4 -4
  15. data/lib/active_record/associations/builder/has_one.rb +5 -6
  16. data/lib/active_record/associations/builder/singular_association.rb +3 -16
  17. data/lib/active_record/associations/collection_association.rb +65 -32
  18. data/lib/active_record/associations/collection_proxy.rb +8 -41
  19. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +1 -0
  20. data/lib/active_record/associations/has_many_association.rb +11 -7
  21. data/lib/active_record/associations/has_many_through_association.rb +19 -9
  22. data/lib/active_record/associations/has_one_association.rb +23 -13
  23. data/lib/active_record/associations/join_dependency/join_association.rb +6 -1
  24. data/lib/active_record/associations/join_dependency.rb +3 -3
  25. data/lib/active_record/associations/preloader/through_association.rb +3 -3
  26. data/lib/active_record/associations/preloader.rb +14 -10
  27. data/lib/active_record/associations/through_association.rb +8 -4
  28. data/lib/active_record/associations.rb +92 -76
  29. data/lib/active_record/attribute_assignment.rb +221 -0
  30. data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +32 -0
  31. data/lib/active_record/attribute_methods/dirty.rb +21 -11
  32. data/lib/active_record/attribute_methods/primary_key.rb +62 -25
  33. data/lib/active_record/attribute_methods/read.rb +73 -83
  34. data/lib/active_record/attribute_methods/serialization.rb +120 -0
  35. data/lib/active_record/attribute_methods/time_zone_conversion.rb +12 -14
  36. data/lib/active_record/attribute_methods/write.rb +32 -6
  37. data/lib/active_record/attribute_methods.rb +231 -30
  38. data/lib/active_record/autosave_association.rb +44 -26
  39. data/lib/active_record/base.rb +227 -1708
  40. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +150 -148
  41. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +85 -29
  42. data/lib/active_record/connection_adapters/abstract/database_statements.rb +7 -34
  43. data/lib/active_record/connection_adapters/abstract/query_cache.rb +10 -2
  44. data/lib/active_record/connection_adapters/abstract/quoting.rb +7 -4
  45. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +39 -28
  46. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +48 -19
  47. data/lib/active_record/connection_adapters/abstract_adapter.rb +77 -42
  48. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +676 -0
  49. data/lib/active_record/connection_adapters/column.rb +37 -11
  50. data/lib/active_record/connection_adapters/mysql2_adapter.rb +133 -581
  51. data/lib/active_record/connection_adapters/mysql_adapter.rb +136 -693
  52. data/lib/active_record/connection_adapters/postgresql_adapter.rb +209 -97
  53. data/lib/active_record/connection_adapters/schema_cache.rb +69 -0
  54. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +2 -6
  55. data/lib/active_record/connection_adapters/sqlite_adapter.rb +62 -35
  56. data/lib/active_record/counter_cache.rb +9 -4
  57. data/lib/active_record/dynamic_finder_match.rb +12 -0
  58. data/lib/active_record/dynamic_matchers.rb +84 -0
  59. data/lib/active_record/errors.rb +11 -1
  60. data/lib/active_record/explain.rb +86 -0
  61. data/lib/active_record/explain_subscriber.rb +25 -0
  62. data/lib/active_record/fixtures/file.rb +65 -0
  63. data/lib/active_record/fixtures.rb +57 -86
  64. data/lib/active_record/identity_map.rb +3 -4
  65. data/lib/active_record/inheritance.rb +174 -0
  66. data/lib/active_record/integration.rb +60 -0
  67. data/lib/active_record/locking/optimistic.rb +33 -26
  68. data/lib/active_record/locking/pessimistic.rb +23 -1
  69. data/lib/active_record/log_subscriber.rb +8 -4
  70. data/lib/active_record/migration/command_recorder.rb +8 -8
  71. data/lib/active_record/migration.rb +68 -35
  72. data/lib/active_record/model_schema.rb +368 -0
  73. data/lib/active_record/nested_attributes.rb +60 -24
  74. data/lib/active_record/persistence.rb +57 -11
  75. data/lib/active_record/query_cache.rb +6 -6
  76. data/lib/active_record/querying.rb +58 -0
  77. data/lib/active_record/railtie.rb +37 -29
  78. data/lib/active_record/railties/controller_runtime.rb +3 -1
  79. data/lib/active_record/railties/databases.rake +213 -117
  80. data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
  81. data/lib/active_record/readonly_attributes.rb +26 -0
  82. data/lib/active_record/reflection.rb +7 -15
  83. data/lib/active_record/relation/batches.rb +7 -4
  84. data/lib/active_record/relation/calculations.rb +55 -16
  85. data/lib/active_record/relation/delegation.rb +49 -0
  86. data/lib/active_record/relation/finder_methods.rb +16 -11
  87. data/lib/active_record/relation/predicate_builder.rb +8 -6
  88. data/lib/active_record/relation/query_methods.rb +75 -9
  89. data/lib/active_record/relation/spawn_methods.rb +48 -7
  90. data/lib/active_record/relation.rb +78 -32
  91. data/lib/active_record/result.rb +10 -4
  92. data/lib/active_record/sanitization.rb +194 -0
  93. data/lib/active_record/schema_dumper.rb +12 -5
  94. data/lib/active_record/scoping/default.rb +142 -0
  95. data/lib/active_record/scoping/named.rb +200 -0
  96. data/lib/active_record/scoping.rb +152 -0
  97. data/lib/active_record/serialization.rb +1 -43
  98. data/lib/active_record/serializers/xml_serializer.rb +4 -45
  99. data/lib/active_record/session_store.rb +18 -16
  100. data/lib/active_record/store.rb +52 -0
  101. data/lib/active_record/test_case.rb +11 -7
  102. data/lib/active_record/timestamp.rb +17 -3
  103. data/lib/active_record/transactions.rb +27 -6
  104. data/lib/active_record/translation.rb +22 -0
  105. data/lib/active_record/validations/associated.rb +5 -4
  106. data/lib/active_record/validations/uniqueness.rb +8 -8
  107. data/lib/active_record/validations.rb +1 -1
  108. data/lib/active_record/version.rb +3 -3
  109. data/lib/active_record.rb +38 -3
  110. data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -1
  111. data/lib/rails/generators/active_record/migration/templates/migration.rb +12 -3
  112. data/lib/rails/generators/active_record/model/model_generator.rb +9 -1
  113. data/lib/rails/generators/active_record/model/templates/migration.rb +3 -5
  114. data/lib/rails/generators/active_record/model/templates/model.rb +5 -0
  115. data/lib/rails/generators/active_record/session_migration/templates/migration.rb +1 -5
  116. metadata +49 -28
  117. data/lib/active_record/named_scope.rb +0 -200
data/CHANGELOG.md CHANGED
@@ -1,548 +1,1014 @@
1
- ## unreleased ##
1
+ ## Rails 3.2.22 (Jun 16, 2015) ##
2
2
 
3
- * Reverted 921a296a3390192a71abeec6d9a035cc6d1865c8, 'Quote numeric values
4
- compared to string columns.' This caused several regressions.
3
+ * No changes.
5
4
 
6
- *Steve Klabnik*
7
5
 
8
- ## Rails 3.1.11 (Feb 11, 2011) ##
6
+ ## Rails 3.2.19 (Jul 2, 2014) ##
9
7
 
10
- * Quote numeric values being compared to non-numeric columns. Otherwise,
11
- in some database, the string column values will be coerced to a numeric
12
- allowing 0, 0.0 or false to match any string starting with a non-digit.
8
+ * Fix SQL Injection Vulnerability in 'bitstring' quoting.
13
9
 
14
- Example:
10
+ Fixes CVE-2014-3482.
15
11
 
16
- App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
12
+ *Rafael Mendonça França*
17
13
 
18
- *Dylan Smith*
19
14
 
20
- ## Rails 3.1.10 (Jan 8, 2013) ##
15
+ ## Rails 3.2.18 (May 6, 2014) ##
21
16
 
22
- * Fix querying with an empty hash *Damien Mathieu* [CVE-2013-0155]
17
+ * No changes.
23
18
 
24
- ## Rails 3.1.9 (Jan 2, 2013) ##
25
19
 
26
- * CVE-2012-5664 ensure that options are never taken from the first parameter
20
+ ## Rails 3.2.17 (Feb 18, 2014) ##
27
21
 
28
- ## Rails 3.1.8 (Aug 9, 2012) ##
22
+ * No changes.
29
23
 
30
- * No changes.
31
24
 
32
- ## Rails 3.1.7 (Jul 26, 2012) ##
25
+ ## Rails 3.2.16 (Dec 3, 2013) ##
33
26
 
34
- * No changes.
27
+ * No changes.
35
28
 
36
- ## Rails 3.1.6 (Jun 12, 2012) ##
37
29
 
38
- * protect against the nesting of hashes changing the
39
- table context in the next call to build_from_hash. This fix
40
- covers this case as well.
30
+ ## Rails 3.2.15 (Oct 16, 2013) ##
41
31
 
42
- CVE-2012-2695
32
+ * When calling the method .find_or_initialize_by_* from a collection_proxy
33
+ it should set the inverse_of relation even when the entry was found on the db.
43
34
 
44
- ## Rails 3.1.5 (May 31, 2012) ##
35
+ *arthurnn*
45
36
 
46
- * Fix type_to_sql with text and limit on mysql/mysql2. Fix GH #3931.
37
+ * Callbacks on has_many should access the in memory parent if a inverse_of is set.
47
38
 
48
- * only log an error if there is a logger. fixes #5226
39
+ *arthurnn*
49
40
 
50
- * fix activerecord query_method regression with offset into Fixnum
41
+ * Fix `FinderMethods#last` unscoped primary key.
51
42
 
52
- * predicate builder should not recurse for determining where columns.
53
- Thanks to Ben Murphy for reporting this! CVE-2012-2661
43
+ Fixes #11917.
54
44
 
55
- ## Rails 3.1.4 (unreleased) ##
45
+ *Eugene Kalenkovich*
56
46
 
57
- * Fix a custom primary key regression *GH 3987*
47
+ * Load fixtures from linked folders.
58
48
 
59
- *Jon Leighton*
49
+ *Kassio Borges*
60
50
 
61
- * Perf fix (second try): don't load records for `has many :dependent =>
62
- :delete_all` *GH 3672*
51
+ * When using optimistic locking, `update` was not passing the column to `quote_value`
52
+ to allow the connection adapter to properly determine how to quote the value. This was
53
+ affecting certain databases that use specific colmn types.
63
54
 
64
- *Jon Leighton*
55
+ Fixes: #6763
65
56
 
66
- * Fix accessing `proxy_association` method from an association extension
67
- where the calls are chained. *GH #3890*
57
+ *Alfred Wong*
68
58
 
69
- (E.g. `post.comments.where(bla).my_proxy_method`)
70
59
 
71
- *Jon Leighton*
60
+ ## Rails 3.2.14 (Jul 22, 2013) ##
72
61
 
73
- * Perf fix: MySQL primary key lookup was still slow for very large
74
- tables. *GH 3678*
62
+ * Fix merge error when Equality LHS is non-attribute.
63
+ Backport of #7380.
75
64
 
76
- *Kenny J*
65
+ *Karmes Alexander*
77
66
 
78
- * Perf fix: If a table has no primary key, don't repeatedly ask the database for it.
67
+ * Do not re-create destroyed association when saving the parent object.
79
68
 
80
- *Julius de Bruijn*
69
+ Fixes #11450.
81
70
 
82
- ## Rails 3.1.3 (unreleased) ##
71
+ *Paul Nikitochkin*
83
72
 
84
- * Perf fix: If we're deleting all records in an association, don't add a IN(..) clause
85
- to the query. *GH 3672*
73
+ * Do not shallow the original exception in `exec_cache` on PostgreSQL adapter.
86
74
 
87
- *Jon Leighton*
75
+ Fixes #11260.
88
76
 
89
- * Fix bug with referencing other mysql databases in set_table_name. *GH 3690*
77
+ *Rafael Mendonça França*
90
78
 
91
- * Fix performance bug with mysql databases on a server with lots of other databses. *GH 3678*
79
+ * Fix `ActiveRecord::Store` incorrectly tracking changes of its attributes.
80
+ Fixes #10373.
92
81
 
93
- *Christos Zisopoulos and Kenny J*
82
+ *Janko Marohnić*
94
83
 
95
- ## Rails 3.1.2 (unreleased) ##
84
+ * Fix a bug that prevented the use of the default STI inheritance column
85
+ (ActiveRecord::Base.inheritance_column = 'some_column'.)
96
86
 
97
- * Fix problem with prepared statements and PostgreSQL when multiple schemas are used.
98
- *GH #3232*
87
+ *chapmajs + Takehiro Adachi*
99
88
 
100
- *Juan M. Cuello*
89
+ * Fix mysql2 adapter raises the correct exception when executing a query on a
90
+ closed connection.
101
91
 
102
- * Fix bug with PostgreSQLAdapter#indexes. When the search path has multiple schemas, spaces
103
- were not being stripped from the schema names after the first.
92
+ *Yves Senn*
104
93
 
105
- *Sean Kirby*
94
+ * Fixes bug where `Company.new.contract_ids` would incorrectly load
95
+ all non-associated contracts.
106
96
 
107
- * Preserve SELECT columns on the COUNT for finder_sql when possible. *GH 3503*
97
+ Example:
108
98
 
109
- *Justin Mazzi*
99
+ company = Company.new # Company has many :contracts
110
100
 
111
- * Reset prepared statement cache when schema changes impact statement results. *GH 3335*
101
+ # before
102
+ company.contract_ids # => SELECT ... WHERE `contracts`.`company_id` IS NULL
112
103
 
113
- *Aaron Patterson*
104
+ # after
105
+ company.contract_ids # => []
114
106
 
115
- * Postgres: Do not attempt to deallocate a statement if the connection is no longer active.
107
+ *Jared Armstrong*
116
108
 
117
- *Ian Leitch*
109
+ * Fix the `:primary_key` option for `has_many` associations.
110
+ Fixes #10693.
118
111
 
119
- * Prevent QueryCache leaking database connections. *GH 3243*
112
+ *Yves Senn*
120
113
 
121
- *Mark J. Titorenko*
114
+ * fixes bug introduced by #3329. Now, when autosaving associations,
115
+ deletions happen before inserts and saves. This prevents a 'duplicate
116
+ unique value' database error that would occur if a record being created had
117
+ the same value on a unique indexed field as that of a record being destroyed.
122
118
 
123
- * Fix bug where building the conditions of a nested through association could potentially
124
- modify the conditions of the through and/or source association. If you have experienced
125
- bugs with conditions appearing in the wrong queries when using nested through associations,
126
- this probably solves your problems. *GH #3271*
119
+ Backport of #10417
127
120
 
128
- *Jon Leighton*
121
+ *Johnny Holton*
129
122
 
130
- * If a record is removed from a has_many :through, all of the join records relating to that
131
- record should also be removed from the through association's target.
123
+ * Fix that under some conditions, Active Record could produce invalid SQL of the sort:
124
+ "SELECT DISTINCT DISTINCT".
132
125
 
133
- *Jon Leighton*
126
+ Backport of #6792.
134
127
 
135
- * Fix adding multiple instances of the same record to a has_many :through. *GH #3425*
128
+ *Ben Woosley*
136
129
 
137
- *Jon Leighton*
130
+ * Require `ActiveRecord::Base` in railtie hooks for rake_tasks, console and runner to
131
+ avoid circular constant loading issues.
138
132
 
139
- * Fix creating records in a through association with a polymorphic source type. *GH #3247*
133
+ Backport #7695.
140
134
 
141
- *Jon Leighton*
135
+ Fixes #7683 and #882
142
136
 
143
- * MySQL: use the information_schema than the describe command when we look for a primary key. *GH #3440*
144
- *Kenny J*
137
+ *Ben Holley*
145
138
 
146
- ## Rails 3.1.1 (October 7, 2011) ##
139
+ * Maintain context for joins within ActiveRecord::Relation merges.
140
+ Backport #10164.
147
141
 
148
- * Raise an exception if the primary key of a model in an association is needed
149
- but unknown. Fixes #3207.
142
+ *Neeraj Singh + Andrew Horner*
150
143
 
151
- *Jon Leighton*
144
+ * Make sure the `EXPLAIN` command is never triggered by a `select_db` call.
152
145
 
153
- * Add deprecation for the preload_associations method. Fixes #3022.
146
+ *Daniel Schierbeck*
154
147
 
155
- *Jon Leighton*
148
+ * Revert changes on `pluck` that was ignoring the select clause when the relation already
149
+ has one. This caused a regression since it changed the behavior in a stable release.
156
150
 
157
- * Don't require a DB connection when loading a model that uses set_primary_key. GH #2807.
151
+ Fixes #9777.
158
152
 
159
- *Jon Leighton*
153
+ *Rafael Mendonça França*
160
154
 
161
- * Fix using select() with a habtm association, e.g. Person.friends.select(:name). GH #3030 and
162
- \#2923.
155
+ * Confirm a record has not already been destroyed before decrementing counter cache.
163
156
 
164
- *Hendy Tanata*
157
+ *Ben Tucker*
165
158
 
166
- * Fix belongs_to polymorphic with custom primary key on target. GH #3104.
159
+ * Default values for PostgreSQL bigint types now get parsed and dumped to the
160
+ schema correctly.
161
+ Backport #10098.
167
162
 
168
- *Jon Leighton*
163
+ *Erik Peterson*
169
164
 
170
- * CollectionProxy#replace should change the DB records rather than just mutating the array.
171
- Fixes #3020.
165
+ * Removed warning when `auto_explain_threshold_in_seconds` is set and the
166
+ connection adapter doesn't support explain.
167
+ This is causing a regression since the Active Record Railtie is trying to
168
+ connect to the development database in the application boot.
172
169
 
173
- *Jon Leighton*
170
+ *Rafael Mendonça França*
174
171
 
175
- * LRU cache in mysql and sqlite are now per-process caches.
172
+ * Do not reset `inheritance_column` when it's set explicitly.
173
+ Backport of #5327.
176
174
 
177
- * lib/active_record/connection_adapters/mysql_adapter.rb: LRU cache
178
- keys are per process id.
179
- * lib/active_record/connection_adapters/sqlite_adapter.rb: ditto
175
+ *kennyj + Fred Wu*
180
176
 
181
- *Aaron Patterson*
177
+ * Fix a problem wrong exception is occured
178
+ when raising no translatable exception in PostgreSQL.
182
179
 
183
- * Database adapters use a statement pool for limiting the number of open
184
- prepared statments on the database. The limit defaults to 1000, but can
185
- be adjusted in your database config by changing 'statement_limit'.
180
+ *kennyj*
186
181
 
187
- * Fix clash between using 'preload', 'joins' or 'eager_load' in a default scope and including the
188
- default scoped model in a nested through association. (GH #2834.) *Jon Leighton*
182
+ * Resets the postgres search path in the structure.sql after the structure
183
+ is dumped in order to find schema_migrations table when multiples schemas
184
+ are used.
185
+ Fixes #9796.
189
186
 
190
- * Ensure we are not comparing a string with a symbol in HasManyAssociation#inverse_updates_counter_cache?.
191
- Fixes GH #2755, where a counter cache could be decremented twice as far as it was supposed to be.
187
+ *Juan M. Cuello + Dembskiy Alexander*
192
188
 
193
- *Jon Leighton*
189
+ * Reload the association target if it's stale. `@stale_state` should be nil
190
+ when a model isn't saved.
191
+ Fixes #7526.
194
192
 
195
- * Don't send any queries to the database when the foreign key of a belongs_to is nil. Fixes
196
- GH #2828. *Georg Friedrich*
193
+ *Larry Lv*
197
194
 
198
- * Fixed find_in_batches method to not include order from default_scope. See GH #2832 *Arun Agrawal*
195
+ * Don't read CSV files during execution of `db:fixtures:load`. CSV support for
196
+ fixtures was removed some time ago but the task was still loading them, even
197
+ though later the code was looking for the related yaml file instead.
199
198
 
200
- * Don't compute table name for abstract classes. Fixes problem with setting the primary key
201
- in an abstract class. See GH #2791. *Akira Matsuda*
199
+ *kennyj*
202
200
 
203
- * Psych errors with poor yaml formatting are proxied. Fixes GH #2645 and
204
- GH #2731
205
201
 
206
- * Use the LIMIT word with the methods #last and #first. Fixes GH #2783 *Damien Mathieu*
202
+ ## Rails 3.2.13 (Mar 18, 2013) ##
207
203
 
208
- ## Rails 3.1.0 (August 30, 2011) ##
204
+ * Chaining multiple preloaded scopes will correctly preload all the scopes
205
+ at the same time.
209
206
 
210
- * Add a proxy_association method to association proxies, which can be called by association
211
- extensions to access information about the association. This replaces proxy_owner etc with
212
- proxy_association.owner.
207
+ *Chris Geihsler*
213
208
 
214
- *Jon Leighton*
209
+ * Reverted 921a296a3390192a71abeec6d9a035cc6d1865c8, 'Quote numeric values
210
+ compared to string columns.' This caused several regressions.
211
+
212
+ *Steve Klabnik*
215
213
 
216
- * Active Record's dynamic finder will now show a deprecation warning if you passing in less number of arguments than what you call in method signature. This behavior will raise ArgumentError in the next version of Rails *Prem Sichanugrist*
214
+ * Fix overriding of attributes by `default_scope` on `ActiveRecord::Base#dup`.
217
215
 
218
- * Deprecated the AssociationCollection constant. CollectionProxy is now the appropriate constant
219
- to use, though be warned that this is not really a public API.
216
+ *Hiroshige UMINO*
220
217
 
221
- This should solve upgrade problems with the will_paginate plugin (and perhaps others). Thanks
222
- Paul Battley for reporting.
218
+ * Fix issue with overriding Active Record reader methods with a composed object
219
+ and using that attribute as the scope of a `uniqueness_of` validation.
220
+ Backport #7072.
223
221
 
224
- *Jon Leighton*
222
+ *Peter Brown*
225
223
 
226
- * ActiveRecord::MacroReflection::AssociationReflection#build_record has a new method signature.
224
+ * Sqlite now preserves custom primary keys when copying or altering tables.
225
+ Fixes #9367.
226
+ Backport #2312.
227
227
 
228
- Before: def build_association(*options)
229
- After: def build_association(*options, &block)
228
+ *Sean Scally + Yves Senn*
230
229
 
231
- Users who are redefining this method to extend functionality should ensure that the block is
232
- passed through to ActiveRecord::Base#new.
230
+ * Preloading `has_many :through` associations with conditions won't
231
+ cache the `:through` association. This will prevent invalid
232
+ subsets to be cached.
233
+ Fixes #8423.
234
+ Backport #9252.
233
235
 
234
- This change is necessary to fix https://github.com/rails/rails/issues/1842.
236
+ Example:
235
237
 
236
- A deprecation warning and workaround has been added to 3.1, but authors will need to update
237
- their code for it to work correctly in 3.2.
238
+ class User
239
+ has_many :posts
240
+ has_many :recent_comments, -> { where('created_at > ?', 1.week.ago) }, :through => :posts
241
+ end
238
242
 
239
- *Jon Leighton*
243
+ a_user = User.includes(:recent_comments).first
240
244
 
241
- * AR#pluralize_table_names can be used to singularize/pluralize table name of an individual model:
245
+ # this is preloaded
246
+ a_user.recent_comments
242
247
 
243
- class User < ActiveRecord::Base
244
- self.pluralize_table_names = false
248
+ # fetching the recent_comments through the posts association won't preload it.
249
+ a_user.posts
250
+
251
+ *Yves Senn*
252
+
253
+ * Fix handling of dirty time zone aware attributes
254
+
255
+ Previously, when `time_zone_aware_attributes` were enabled, after
256
+ changing a datetime or timestamp attribute and then changing it back
257
+ to the original value, `changed_attributes` still tracked the
258
+ attribute as changed. This caused `[attribute]_changed?` and
259
+ `changed?` methods to return true incorrectly.
260
+
261
+ Example:
262
+
263
+ in_time_zone 'Paris' do
264
+ order = Order.new
265
+ original_time = Time.local(2012, 10, 10)
266
+ order.shipped_at = original_time
267
+ order.save
268
+ order.changed? # => false
269
+
270
+ # changing value
271
+ order.shipped_at = Time.local(2013, 1, 1)
272
+ order.changed? # => true
273
+
274
+ # reverting to original value
275
+ order.shipped_at = original_time
276
+ order.changed? # => false, used to return true
245
277
  end
246
278
 
247
- Previously this could only be set globally for all models through ActiveRecord::Base.pluralize_table_names. *Guillermo Iguaran*
279
+ Backport of #9073
280
+ Fixes #8898
281
+
282
+ *Lilibeth De La Cruz*
283
+
284
+ * Fix counter cache columns not updated when replacing `has_many :through`
285
+ associations.
286
+ Backport #8400.
287
+ Fix #7630.
288
+
289
+ *Matthew Robertson*
290
+
291
+ * Don't update `column_defaults` when calling destructive methods on column with default value.
292
+ Backport c517602.
293
+ Fix #6115.
294
+
295
+ *Piotr Sarnacki + Aleksey Magusev + Alan Daud*
296
+
297
+ * When `#count` is used in conjunction with `#uniq` we perform `count(:distinct => true)`.
298
+ Fix #6865.
299
+
300
+ Example:
301
+
302
+ relation.uniq.count # => SELECT COUNT(DISTINCT *)
303
+
304
+ *Yves Senn + Kaspar Schiess*
305
+
306
+ * Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
307
+ Backport #7536.
308
+ Fix #8968.
309
+
310
+ *Ian Lesperance + Yves Senn + Kaspar Schiess*
311
+
312
+ * Don't run explain on slow queries for database adapters that don't support it.
313
+ Backport #6197.
314
+
315
+ *Blake Smith*
316
+
317
+ * Revert round usec when comparing timestamp attributes in the dirty tracking.
318
+ Fixes #8460.
319
+
320
+ *Andrew White*
321
+
322
+ * Revert creation of through association models when using `collection=[]`
323
+ on a `has_many :through` association from an unsaved model.
324
+ Fix #7661, #8269.
325
+
326
+ *Ernie Miller*
327
+
328
+ * Fix undefined method `to_i` when calling `new` on a scope that uses an
329
+ Array; Fix FloatDomainError when setting integer column to NaN.
330
+ Fixes #8718, #8734, #8757.
331
+
332
+ *Jason Stirk + Tristan Harward*
333
+
334
+ * Serialized attributes can be serialized in integer columns.
335
+ Fix #8575.
336
+
337
+ *Rafael Mendonça França*
248
338
 
249
- * Add block setting of attributes to singular associations:
339
+ * Keep index names when using `alter_table` with sqlite3.
340
+ Fix #3489.
341
+ Backport #8522.
342
+
343
+ *Yves Senn*
344
+
345
+ * Recognize migrations placed in directories containing numbers and 'rb'.
346
+ Fix #8492.
347
+ Backport of #8500.
348
+
349
+ *Yves Senn*
350
+
351
+ * Add `ActiveRecord::Base.cache_timestamp_format` class attribute to control
352
+ the format of the timestamp value in the cache key.
353
+ This allows users to improve the precision of the cache key.
354
+ Fixes #8195.
355
+
356
+ *Rafael Mendonça França*
357
+
358
+ * Add `:nsec` date format. This can be used to improve the precision of cache key.
359
+ Please note that this format only works with Ruby 1.9, Ruby 1.8 will ignore it completely.
360
+
361
+ *Jamie Gaskins*
362
+
363
+ * Unscope `update_column(s)` query to ignore default scope.
364
+
365
+ When applying `default_scope` to a class with a where clause, using
366
+ `update_column(s)` could generate a query that would not properly update
367
+ the record due to the where clause from the `default_scope` being applied
368
+ to the update query.
250
369
 
251
370
  class User < ActiveRecord::Base
252
- has_one :account
371
+ default_scope where(active: true)
253
372
  end
254
373
 
255
- user.build_account{ |a| a.credit_limit => 100.0 }
374
+ user = User.first
375
+ user.active = false
376
+ user.save!
256
377
 
257
- The block is called after the instance has been initialized. *Andrew White*
378
+ user.update_column(:active, true) # => false
258
379
 
259
- * Add ActiveRecord::Base.attribute_names to return a list of attribute names. This will return an empty array if the model is abstract or table does not exists. *Prem Sichanugrist*
380
+ In this situation we want to skip the default_scope clause and just
381
+ update the record based on the primary key. With this change:
260
382
 
261
- * CSV Fixtures are deprecated and support will be removed in Rails 3.2.0
383
+ user.update_column(:active, true) # => true
262
384
 
263
- * AR#new, AR#create, AR#create!, AR#update_attributes and AR#update_attributes! all accept a second hash as option that allows you
264
- to specify which role to consider when assigning attributes. This is built on top of ActiveModel's
265
- new mass assignment capabilities:
385
+ Backport of #8436 fix.
266
386
 
267
- class Post < ActiveRecord::Base
268
- attr_accessible :title
269
- attr_accessible :title, :published_at, :as => :admin
270
- end
387
+ *Carlos Antonio da Silva*
271
388
 
272
- Post.new(params[:post], :as => :admin)
389
+ * Fix performance problem with primary_key method in PostgreSQL adapter when having many schemas.
390
+ Uses pg_constraint table instead of pg_depend table which has many records in general.
391
+ Fix #8414
273
392
 
274
- assign_attributes() with similar API was also added and attributes=(params, guard) was deprecated.
393
+ *kennyj*
275
394
 
276
- Please note that this changes the method signatures for AR#new, AR#create, AR#create!, AR#update_attributes and AR#update_attributes!. If you have overwritten these methods you should update them accordingly.
395
+ * Do not instantiate intermediate Active Record objects when eager loading.
396
+ These records caused `after_find` to run more than expected.
397
+ Fix #3313
398
+ Backport of #8403
277
399
 
278
- *Josh Kalderimis*
400
+ *Yves Senn*
279
401
 
280
- * default_scope can take a block, lambda, or any other object which responds to `call` for lazy
281
- evaluation:
402
+ * Fix `pluck` to work with joins. Backport of #4942.
282
403
 
283
- default_scope { ... }
284
- default_scope lambda { ... }
285
- default_scope method(:foo)
404
+ *Carlos Antonio da Silva*
286
405
 
287
- This feature was originally implemented by Tim Morgan, but was then removed in favour of
288
- defining a 'default_scope' class method, but has now been added back in by Jon Leighton.
289
- The relevant lighthouse ticket is #1812.
406
+ * Fix a problem with `translate_exception` method in a non English environment.
407
+ Backport of #6397.
290
408
 
291
- * Default scopes are now evaluated at the latest possible moment, to avoid problems where
292
- scopes would be created which would implicitly contain the default scope, which would then
293
- be impossible to get rid of via Model.unscoped.
409
+ *kennyj*
294
410
 
295
- Note that this means that if you are inspecting the internal structure of an
296
- ActiveRecord::Relation, it will *not* contain the default scope, though the resulting
297
- query will do. You can get a relation containing the default scope by calling
298
- ActiveRecord#with_default_scope, though this is not part of the public API.
411
+ * Fix dirty attribute checks for TimeZoneConversion with nil and blank
412
+ datetime attributes. Setting a nil datetime to a blank string should not
413
+ result in a change being flagged.
414
+ Fixes #8310.
415
+ Backport of #8311.
299
416
 
300
- *Jon Leighton*
417
+ *Alisdair McDiarmid*
301
418
 
302
- * If you wish to merge default scopes in special ways, it is recommended to define your default
303
- scope as a class method and use the standard techniques for sharing code (inheritance, mixins,
304
- etc.):
419
+ * Prevent mass assignment to the type column of polymorphic associations when using `build`.
420
+ Fixes #8265.
421
+ Backport of #8291.
305
422
 
306
- class Post < ActiveRecord::Base
307
- def self.default_scope
308
- where(:published => true).where(:hidden => false)
309
- end
423
+ *Yves Senn*
424
+
425
+ * When running migrations on Postgresql, the `:limit` option for `binary` and `text` columns is
426
+ silently dropped.
427
+ Previously, these migrations caused sql exceptions, because Postgresql doesn't support limits
428
+ on these types.
429
+
430
+ *Victor Costan*
431
+
432
+ * `#pluck` can be used on a relation with `select` clause.
433
+ Fixes #7551.
434
+ Backport of #8176.
435
+
436
+ Example:
437
+
438
+ Topic.select([:approved, :id]).order(:id).pluck(:id)
439
+
440
+ *Yves Senn*
441
+
442
+ * Use `nil?` instead of `blank?` to check whether dynamic finder with a bang
443
+ should raise RecordNotFound.
444
+ Fixes #7238.
445
+
446
+ *Nikita Afanasenko*
447
+
448
+ * Fix deleting from a HABTM join table upon destroying an object of a model
449
+ with optimistic locking enabled.
450
+ Fixes #5332.
451
+
452
+ *Nick Rogers*
453
+
454
+ * Use query cache/uncache when using ENV["DATABASE_URL"].
455
+ Fixes #6951.
456
+ Backport of #8074.
457
+
458
+ *kennyj*
459
+
460
+ * Do not create useless database transaction when building `has_one` association.
461
+
462
+ Example:
463
+
464
+ User.has_one :profile
465
+ User.new.build_profile
466
+
467
+ Backport of #8154.
468
+
469
+ *Bogdan Gusiev*
470
+
471
+ * `AR::Base#attributes_before_type_cast` now returns unserialized values for serialized attributes.
472
+
473
+ *Nikita Afanasenko*
474
+
475
+ * Fix issue that raises `NameError` when overriding the `accepts_nested_attributes` in child classes.
476
+
477
+ Before:
478
+
479
+ class Shared::Person < ActiveRecord::Base
480
+ has_one :address
481
+
482
+ accepts_nested_attributes :address, :reject_if => :all_blank
310
483
  end
311
484
 
312
- *Jon Leighton*
485
+ class Person < Shared::Person
486
+ accepts_nested_attributes :address
487
+ end
488
+
489
+ Person
490
+ #=> NameError: method `address_attributes=' not defined in Person
491
+
492
+ After:
493
+
494
+ Person
495
+ #=> Person(id: integer, ...)
496
+
497
+ Fixes #8131.
313
498
 
314
- * PostgreSQL adapter only supports PostgreSQL version 8.2 and higher.
499
+ *Gabriel Sobrinho, Ricardo Henrique*
315
500
 
316
- * ConnectionManagement middleware is changed to clean up the connection pool
317
- after the rack body has been flushed.
318
501
 
319
- * Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks.
320
- It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of
321
- the updated_at column. It should not be called on new records.
502
+ ## Rails 3.2.12 (Feb 11, 2013) ##
503
+
504
+ * Quote numeric values being compared to non-numeric columns. Otherwise,
505
+ in some database, the string column values will be coerced to a numeric
506
+ allowing 0, 0.0 or false to match any string starting with a non-digit.
507
+
322
508
  Example:
323
509
 
324
- User.first.update_column(:name, "sebastian") # => true
510
+ App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
325
511
 
326
- *Sebastian Martinez*
512
+ *Dylan Smith*
327
513
 
328
- * Associations with a :through option can now use *any* association as the
329
- through or source association, including other associations which have a
330
- :through option and has_and_belongs_to_many associations
331
514
 
332
- *Jon Leighton*
515
+ ## Rails 3.2.11 (Jan 8, 2013) ##
333
516
 
334
- * The configuration for the current database connection is now accessible via
335
- ActiveRecord::Base.connection_config. *fxn*
517
+ * Fix querying with an empty hash *Damien Mathieu* [CVE-2013-0155]
336
518
 
337
- * limits and offsets are removed from COUNT queries unless both are supplied.
338
- For example:
339
519
 
340
- People.limit(1).count # => 'SELECT COUNT(*) FROM people'
341
- People.offset(1).count # => 'SELECT COUNT(*) FROM people'
342
- People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1'
520
+ ## Rails 3.2.10 (Jan 2, 2013) ##
343
521
 
344
- *lighthouse #6262*
522
+ * CVE-2012-5664 options hashes should only be extracted if there are extra
523
+ parameters
345
524
 
346
- * ActiveRecord::Associations::AssociationProxy has been split. There is now an Association class
347
- (and subclasses) which are responsible for operating on associations, and then a separate,
348
- thin wrapper called CollectionProxy, which proxies collection associations.
349
525
 
350
- This prevents namespace pollution, separates concerns, and will allow further refactorings.
526
+ ## Rails 3.2.9 (Nov 12, 2012) ##
351
527
 
352
- Singular associations (has_one, belongs_to) no longer have a proxy at all. They simply return
353
- the associated record or nil. This means that you should not use undocumented methods such
354
- as bob.mother.create - use bob.create_mother instead.
528
+ * Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
355
529
 
356
- *Jon Leighton*
530
+ *Alexis Bernard*
531
+
532
+ * Fix issue with collection associations calling first(n)/last(n) and attempting
533
+ to set the inverse association when `:inverse_of` was used. Fixes #8087.
534
+
535
+ *Carlos Antonio da Silva*
536
+
537
+ * Fix bug when Column is trying to type cast boolean values to integer.
538
+ Fixes #8067.
539
+
540
+ *Rafael Mendonça França*
541
+
542
+ * Fix bug where `rake db:test:prepare` tries to load the structure.sql into development database.
543
+ Fixes #8032.
544
+
545
+ *Grace Liu + Rafael Mendonça França*
546
+
547
+ * Fixed support for `DATABASE_URL` environment variable for rake db tasks. *Grace Liu*
548
+
549
+ * Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
550
+
551
+ *Henrik Nyh*
552
+
553
+ * Decode URI encoded attributes on database connection URLs.
554
+
555
+ *Shawn Veader*
556
+
557
+ * Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
558
+ and the dup'ed object shared the same errors.
559
+
560
+ *Christian Seiler*
561
+
562
+ * Synchronize around deleting from the reserved connections hash.
563
+ Fixes #7955
564
+
565
+ * PostgreSQL adapter correctly fetches default values when using
566
+ multiple schemas and domains in a db. Fixes #7914
567
+
568
+ *Arturo Pie*
357
569
 
358
- * Make has_many :through associations work correctly when you build a record and then save it. This
359
- requires you to set the :inverse_of option on the source reflection on the join model, like so:
570
+ * Fix deprecation notice when loading a collection association that
571
+ selects columns from other tables, if a new record was previously
572
+ built using that association.
360
573
 
361
- class Post < ActiveRecord::Base
362
- has_many :taggings
363
- has_many :tags, :through => :taggings
364
- end
574
+ *Ernie Miller*
365
575
 
366
- class Tagging < ActiveRecord::Base
367
- belongs_to :post
368
- belongs_to :tag, :inverse_of => :tagging # :inverse_of must be set!
369
- end
576
+ * The postgres adapter now supports tables with capital letters.
577
+ Fix #5920
370
578
 
371
- class Tag < ActiveRecord::Base
372
- has_many :taggings
373
- has_many :posts, :through => :taggings
374
- end
579
+ *Yves Senn*
375
580
 
376
- post = Post.first
377
- tag = post.tags.build :name => "ruby"
378
- tag.save # will save a Taggable linking to the post
581
+ * `CollectionAssociation#count` returns `0` without querying if the
582
+ parent record is not persisted.
583
+
584
+ Before:
585
+
586
+ person.pets.count
587
+ # SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
588
+ # => 0
589
+
590
+ After:
591
+
592
+ person.pets.count
593
+ # fires without sql query
594
+ # => 0
595
+
596
+ *Francesco Rodriguez*
597
+
598
+ * Fix `reset_counters` crashing on `has_many :through` associations.
599
+ Fix #7822.
600
+
601
+ *lulalala*
602
+
603
+ * ConnectionPool recognizes checkout_timeout spec key as taking
604
+ precedence over legacy wait_timeout spec key, can be used to avoid
605
+ conflict with mysql2 use of wait_timeout. Closes #7684.
606
+
607
+ *jrochkind*
608
+
609
+ * Rename field_changed? to _field_changed? so that users can create a field named field
610
+
611
+ *Akira Matsuda*, backported by *Steve Klabnik*
612
+
613
+ * Fix creation of through association models when using `collection=[]`
614
+ on a `has_many :through` association from an unsaved model.
615
+ Fix #7661.
616
+
617
+ *Ernie Miller*
618
+
619
+ * Explain only normal CRUD sql (select / update / insert / delete).
620
+ Fix problem that explains unexplainable sql. Closes #7544 #6458.
621
+
622
+ *kennyj*
623
+
624
+ * Backport test coverage to ensure that PostgreSQL auto-reconnect functionality
625
+ remains healthy.
626
+
627
+ *Steve Jorgensen*
628
+
629
+ * Use config['encoding'] instead of config['charset'] when executing
630
+ databases.rake in the mysql/mysql2. A correct option for a database.yml
631
+ is 'encoding'.
632
+
633
+ *kennyj*
634
+
635
+ * Fix ConnectionAdapters::Column.type_cast_code integer conversion,
636
+ to always convert values to integer calling #to_i. Fixes #7509.
637
+
638
+ *Thiago Pradi*
639
+
640
+ * Fix time column type casting for invalid time string values to correctly return nil.
641
+
642
+ *Adam Meehan*
643
+
644
+ * Fix `becomes` when using a configured `inheritance_column`.
645
+
646
+ *Yves Senn*
647
+
648
+ * Fix `reset_counters` when there are multiple `belongs_to` association with the
649
+ same foreign key and one of them have a counter cache.
650
+ Fixes #5200.
651
+
652
+ *Dave Desrochers*
653
+
654
+ * Round usec when comparing timestamp attributes in the dirty tracking.
655
+ Fixes #6975.
656
+
657
+ *kennyj*
658
+
659
+ * Use inversed parent for first and last child of has_many association.
660
+
661
+ *Ravil Bayramgalin*
662
+
663
+ * Fix Column.microseconds and Column.fast_string_to_date to avoid converting
664
+ timestamp seconds to a float, since it occasionally results in inaccuracies
665
+ with microsecond-precision times. Fixes #7352.
666
+
667
+ *Ari Pollak*
668
+
669
+ * Fix `increment!`, `decrement!`, `toggle!` that was skipping callbacks.
670
+ Fixes #7306.
671
+
672
+ *Rafael Mendonça França*
673
+
674
+ * Fix AR#create to return an unsaved record when AR::RecordInvalid is
675
+ raised. Fixes #3217.
676
+
677
+ *Dave Yeu*
678
+
679
+ * Remove unnecessary transaction when assigning has_one associations with a nil or equal value.
680
+ Fix #7191.
681
+
682
+ *kennyj*
683
+
684
+ * Allow store to work with an empty column.
685
+ Fix #4840.
686
+
687
+ *Jeremy Walker*
688
+
689
+ * Remove prepared statement from system query in postgresql adapter.
690
+ Fix #5872.
691
+
692
+ *Ivan Evtuhovich*
693
+
694
+ * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`
695
+ Fixes #4772.
696
+
697
+ *Seamus Abshere*
698
+
699
+
700
+ ## Rails 3.2.8 (Aug 9, 2012) ##
701
+
702
+ * Do not consider the numeric attribute as changed if the old value is zero and the new value
703
+ is not a string.
704
+ Fixes #7237.
705
+
706
+ *Rafael Mendonça França*
707
+
708
+ * Removes the deprecation of `update_attribute`. *fxn*
709
+
710
+ * Reverted the deprecation of `composed_of`. *Rafael Mendonça França*
711
+
712
+ * Reverted the deprecation of `*_sql` association options. They will
713
+ be deprecated in 4.0 instead. *Jon Leighton*
714
+
715
+ * Do not eager load AR session store. ActiveRecord::SessionStore depends on the abstract store
716
+ in Action Pack. Eager loading this class would break client code that eager loads Active Record
717
+ standalone.
718
+ Fixes #7160
719
+
720
+ *Xavier Noria*
721
+
722
+ * Do not set RAILS_ENV to "development" when using `db:test:prepare` and related rake tasks.
723
+ This was causing the truncation of the development database data when using RSpec.
724
+ Fixes #7175.
725
+
726
+ *Rafael Mendonça França*
727
+
728
+ ## Rails 3.2.7 (Jul 26, 2012) ##
729
+
730
+ * `:finder_sql` and `:counter_sql` options on collection associations
731
+ are deprecated. Please transition to using scopes.
379
732
 
380
733
  *Jon Leighton*
381
734
 
382
- * Support the :dependent option on has_many :through associations. For historical and practical
383
- reasons, :delete_all is the default deletion strategy employed by association.delete(*records),
384
- despite the fact that the default strategy is :nullify for regular has_many. Also, this only
385
- works at all if the source reflection is a belongs_to. For other situations, you should directly
386
- modify the through association.
735
+ * `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
736
+ associations are deprecated. Please transition to using `has_many
737
+ :through`
387
738
 
388
739
  *Jon Leighton*
389
740
 
390
- * Changed the behaviour of association.destroy for has_and_belongs_to_many and has_many :through.
391
- From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link',
392
- not (necessarily) 'get rid of the associated records'.
741
+ * `composed_of` has been deprecated. You'll have to write your own accessor
742
+ and mutator methods if you'd like to use value objects to represent some
743
+ portion of your models.
744
+
745
+ *Steve Klabnik*
746
+
747
+ * `update_attribute` has been deprecated. Use `update_column` if
748
+ you want to bypass mass-assignment protection, validations, callbacks,
749
+ and touching of updated_at. Otherwise please use `update_attributes`.
393
750
 
394
- Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It
395
- would not delete any records in the join table. Now, it deletes the records in the join table.
751
+ *Steve Klabnik*
396
752
 
397
- Previously, has_many_through.destroy(*records) would destroy the records themselves, and the
398
- records in the join table. [Note: This has not always been the case; previous version of Rails
399
- only deleted the records themselves.] Now, it destroys only the records in the join table.
753
+ ## Rails 3.2.6 (Jun 12, 2012) ##
400
754
 
401
- Note that this change is backwards-incompatible to an extent, but there is unfortunately no
402
- way to 'deprecate' it before changing it. The change is being made in order to have
403
- consistency as to the meaning of 'destroy' or 'delete' across the different types of associations.
755
+ * protect against the nesting of hashes changing the
756
+ table context in the next call to build_from_hash. This fix
757
+ covers this case as well.
404
758
 
405
- If you wish to destroy the records themselves, you can do records.association.each(&:destroy)
759
+ CVE-2012-2695
760
+
761
+ * Revert earlier 'perf fix' (see 3.2.4 changelog / GH #6289). This
762
+ change introduced a regression (GH #6609). assoc.clear and
763
+ assoc.delete_all have loaded the association before doing the delete
764
+ since at least Rails 2.3. Doing the delete without loading the
765
+ records means that the `before_remove` and `after_remove` callbacks do
766
+ not get invoked. Therefore, this change was less a fix a more an
767
+ optimisation, which should only have gone into master.
406
768
 
407
769
  *Jon Leighton*
408
770
 
409
- * Add :bulk => true option to change_table to make all the schema changes defined in change_table block using a single ALTER statement. *Pratik Naik*
771
+ ## Rails 3.2.5 (Jun 1, 2012) ##
410
772
 
411
- Example:
773
+ * Restore behavior of Active Record 3.2.3 scopes.
774
+ A series of commits relating to preloading and scopes caused a regression.
412
775
 
413
- change_table(:users, :bulk => true) do |t|
414
- t.string :company_name
415
- t.change :birthdate, :datetime
416
- end
776
+ *Andrew White*
417
777
 
418
- This will now result in:
419
778
 
420
- ALTER TABLE `users` ADD COLUMN `company_name` varchar(255), CHANGE `updated_at` `updated_at` datetime DEFAULT NULL
779
+ ## Rails 3.2.4 (May 31, 2012) ##
421
780
 
422
- * Removed support for accessing attributes on a has_and_belongs_to_many join table. This has been
423
- documented as deprecated behaviour since April 2006. Please use has_many :through instead.
424
- *Jon Leighton*
781
+ * Perf fix: Don't load the records when doing assoc.delete_all.
782
+ GH #6289. *Jon Leighton*
425
783
 
426
- * Added a create_association! method for has_one and belongs_to associations. *Jon Leighton*
784
+ * Association preloading shouldn't be affected by the current scoping.
785
+ This could cause infinite recursion and potentially other problems.
786
+ See GH #5667. *Jon Leighton*
427
787
 
428
- * Migration files generated from model and constructive migration generators
429
- (for example, add_name_to_users) use the reversible migration's `change`
430
- method instead of the ordinary `up` and `down` methods. *Prem Sichanugrist*
788
+ * Datetime attributes are forced to be changed. GH #3965
431
789
 
432
- * Removed support for interpolating string SQL conditions on associations. Instead, you should
433
- use a proc, like so:
790
+ * Fix attribute casting. GH #5549
434
791
 
435
- Before:
792
+ * Fix #5667. Preloading should ignore scoping.
436
793
 
437
- has_many :things, :conditions => 'foo = #{bar}'
794
+ * Predicate builder should not recurse for determining where columns.
795
+ Thanks to Ben Murphy for reporting this! CVE-2012-2661
438
796
 
439
- After:
440
797
 
441
- has_many :things, :conditions => proc { "foo = #{bar}" }
798
+ ## Rails 3.2.3 (March 30, 2012) ##
442
799
 
443
- Inside the proc, 'self' is the object which is the owner of the association, unless you are
444
- eager loading the association, in which case 'self' is the class which the association is within.
800
+ * Added find_or_create_by_{attribute}! dynamic method. *Andrew White*
445
801
 
446
- You can have any "normal" conditions inside the proc, so the following will work too:
802
+ * Whitelist all attribute assignment by default. Change the default for newly generated applications to whitelist all attribute assignment. Also update the generated model classes so users are reminded of the importance of attr_accessible. *NZKoz*
447
803
 
448
- has_many :things, :conditions => proc { ["foo = ?", bar] }
804
+ * Update ActiveRecord::AttributeMethods#attribute_present? to return false for empty strings. *Jacobkg*
449
805
 
450
- Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call
451
- 'record' to get the record being inserted or deleted. This is now passed as an argument to
452
- the proc.
806
+ * Fix associations when using per class databases. *larskanis*
453
807
 
454
- * Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting [DHH]. Example:
808
+ * Revert setting NOT NULL constraints in add_timestamps *fxn*
455
809
 
456
- # Schema: User(name:string, password_digest:string, password_salt:string)
457
- class User < ActiveRecord::Base
458
- has_secure_password
459
- end
810
+ * Fix mysql to use proper text types. Fixes #3931. *kennyj*
460
811
 
461
- user = User.new(:name => "david", :password => "", :password_confirmation => "nomatch")
462
- user.save # => false, password required
463
- user.password = "mUc3m00RsqyRe"
464
- user.save # => false, confirmation doesn't match
465
- user.password_confirmation = "mUc3m00RsqyRe"
466
- user.save # => true
467
- user.authenticate("notright") # => false
468
- user.authenticate("mUc3m00RsqyRe") # => user
469
- User.find_by_name("david").try(:authenticate, "notright") # => nil
470
- User.find_by_name("david").try(:authenticate, "mUc3m00RsqyRe") # => user
812
+ * Fix #5069 - Protect foreign key from mass assignment through association builder. *byroot*
471
813
 
472
814
 
473
- * When a model is generated add_index is added by default for belongs_to or references columns
815
+ ## Rails 3.2.2 (March 1, 2012) ##
474
816
 
475
- rails g model post user:belongs_to will generate the following:
817
+ * No changes.
476
818
 
477
- class CreatePosts < ActiveRecord::Migration
478
- def change
479
- create_table :posts do |t|
480
- t.belongs_to :user
481
- t.timestamps
482
- end
483
- add_index :posts, :user_id
484
- end
485
- end
486
819
 
487
- *Santiago Pastorino*
820
+ ## Rails 3.2.1 (January 26, 2012) ##
488
821
 
489
- * Setting the id of a belongs_to object will update the reference to the
490
- object. *#2989 state:resolved*
822
+ * The threshold for auto EXPLAIN is ignored if there's no logger. *fxn*
491
823
 
492
- * ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed
493
- to closer match normal Ruby dup and clone semantics.
824
+ * Call `to_s` on the value passed to `table_name=`, in particular symbols
825
+ are supported (regression). *Sergey Nartimov*
494
826
 
495
- * Calling ActiveRecord::Base#clone will result in a shallow copy of the record,
496
- including copying the frozen state. No callbacks will be called.
827
+ * Fix possible race condition when two threads try to define attribute
828
+ methods for the same class. *Jon Leighton*
497
829
 
498
- * Calling ActiveRecord::Base#dup will duplicate the record, including calling
499
- after initialize hooks. Frozen state will not be copied, and all associations
500
- will be cleared. A duped record will return true for new_record?, have a nil
501
- id field, and is saveable.
502
830
 
503
- * Migrations can be defined as reversible, meaning that the migration system
504
- will figure out how to reverse your migration. To use reversible migrations,
505
- just define the "change" method. For example:
831
+ ## Rails 3.2.0 (January 20, 2012) ##
506
832
 
507
- class MyMigration < ActiveRecord::Migration
508
- def change
509
- create_table(:horses) do
510
- t.column :content, :text
511
- t.column :remind_at, :datetime
833
+ * Added a `with_lock` method to ActiveRecord objects, which starts
834
+ a transaction, locks the object (pessimistically) and yields to the block.
835
+ The method takes one (optional) parameter and passes it to `lock!`.
836
+
837
+ Before:
838
+
839
+ class Order < ActiveRecord::Base
840
+ def cancel!
841
+ transaction do
842
+ lock!
843
+ # ... cancelling logic
512
844
  end
513
845
  end
514
846
  end
515
847
 
516
- Some things cannot be automatically reversed for you. If you know how to
517
- reverse those things, you should define 'up' and 'down' in your migration. If
518
- you define something in `change` that cannot be reversed, an
519
- IrreversibleMigration exception will be raised when going down.
848
+ After:
520
849
 
521
- * Migrations should use instance methods rather than class methods:
522
- class FooMigration < ActiveRecord::Migration
523
- def up
524
- ...
850
+ class Order < ActiveRecord::Base
851
+ def cancel!
852
+ with_lock do
853
+ # ... cancelling logic
854
+ end
525
855
  end
526
856
  end
527
857
 
528
- *Aaron Patterson*
858
+ *Olek Janiszewski*
859
+
860
+ * 'on' and 'ON' boolean columns values are type casted to true
861
+ *Santiago Pastorino*
862
+
863
+ * Added ability to run migrations only for given scope, which allows
864
+ to run migrations only from one engine (for example to revert changes
865
+ from engine that you want to remove).
866
+
867
+ Example:
868
+ rake db:migrate SCOPE=blog
869
+
870
+ *Piotr Sarnacki*
871
+
872
+ * Migrations copied from engines are now scoped with engine's name,
873
+ for example 01_create_posts.blog.rb. *Piotr Sarnacki*
874
+
875
+ * Implements `AR::Base.silence_auto_explain`. This method allows the user to
876
+ selectively disable automatic EXPLAINs within a block. *fxn*
877
+
878
+ * Implements automatic EXPLAIN logging for slow queries.
879
+
880
+ A new configuration parameter `config.active_record.auto_explain_threshold_in_seconds`
881
+ determines what's to be considered a slow query. Setting that to `nil` disables
882
+ this feature. Defaults are 0.5 in development mode, and `nil` in test and production
883
+ modes.
884
+
885
+ As of this writing there's support for SQLite, MySQL (mysql2 adapter), and
886
+ PostgreSQL.
887
+
888
+ *fxn*
889
+
890
+ * Implemented ActiveRecord::Relation#pluck method
891
+
892
+ Method returns Array of column value from table under ActiveRecord model
893
+
894
+ Client.pluck(:id)
895
+
896
+ *Bogdan Gusiev*
897
+
898
+ * Automatic closure of connections in threads is deprecated. For example
899
+ the following code is deprecated:
900
+
901
+ Thread.new { Post.find(1) }.join
902
+
903
+ It should be changed to close the database connection at the end of
904
+ the thread:
905
+
906
+ Thread.new {
907
+ Post.find(1)
908
+ Post.connection.close
909
+ }.join
910
+
911
+ Only people who spawn threads in their application code need to worry
912
+ about this change.
913
+
914
+ * Deprecated:
915
+
916
+ * `set_table_name`
917
+ * `set_inheritance_column`
918
+ * `set_sequence_name`
919
+ * `set_primary_key`
920
+ * `set_locking_column`
921
+
922
+ Use an assignment method instead. For example, instead of `set_table_name`, use `self.table_name=`:
923
+
924
+ class Project < ActiveRecord::Base
925
+ self.table_name = "project"
926
+ end
927
+
928
+ Or define your own `self.table_name` method:
929
+
930
+ class Post < ActiveRecord::Base
931
+ def self.table_name
932
+ "special_" + super
933
+ end
934
+ end
935
+ Post.table_name # => "special_posts"
936
+
937
+ *Jon Leighton*
938
+
939
+ * Generated association methods are created within a separate module to allow overriding and
940
+ composition using `super`. For a class named `MyModel`, the module is named
941
+ `MyModel::GeneratedFeatureMethods`. It is included into the model class immediately after
942
+ the `generated_attributes_methods` module defined in ActiveModel, so association methods
943
+ override attribute methods of the same name. *Josh Susser*
944
+
945
+ * Implemented ActiveRecord::Relation#explain. *fxn*
946
+
947
+ * Add ActiveRecord::Relation#uniq for generating unique queries.
948
+
949
+ Before:
950
+
951
+ Client.select('DISTINCT name')
952
+
953
+ After:
954
+
955
+ Client.select(:name).uniq
956
+
957
+ This also allows you to revert the unqueness in a relation:
958
+
959
+ Client.select(:name).uniq.uniq(false)
960
+
961
+ *Jon Leighton*
962
+
963
+ * Support index sort order in sqlite, mysql and postgres adapters. *Vlad Jebelev*
964
+
965
+ * Allow the :class_name option for associations to take a symbol (:Client) in addition to
966
+ a string ('Client').
967
+
968
+ This is to avoid confusing newbies, and to be consistent with the fact that other options
969
+ like :foreign_key already allow a symbol or a string.
970
+
971
+ *Jon Leighton*
972
+
973
+ * In development mode the db:drop task also drops the test database. For symmetry with
974
+ the db:create task. *Dmitriy Kiriyenko*
975
+
976
+ * Added ActiveRecord::Base.store for declaring simple single-column key/value stores *DHH*
977
+
978
+ class User < ActiveRecord::Base
979
+ store :settings, accessors: [ :color, :homepage ]
980
+ end
981
+
982
+ u = User.new(color: 'black', homepage: '37signals.com')
983
+ u.color # Accessor stored attribute
984
+ u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor
985
+
986
+
987
+ * MySQL: case-insensitive uniqueness validation avoids calling LOWER when
988
+ the column already uses a case-insensitive collation. Fixes #561.
989
+
990
+ *Joseph Palermo*
991
+
992
+ * Transactional fixtures enlist all active database connections. You can test
993
+ models on different connections without disabling transactional fixtures.
529
994
 
530
- * has_one maintains the association with separate after_create/after_update instead
531
- of a single after_save. *fxn*
995
+ *Jeremy Kemper*
532
996
 
533
- * The following code:
997
+ * Add first_or_create, first_or_create!, first_or_initialize methods to Active Record. This is a
998
+ better approach over the old find_or_create_by dynamic methods because it's clearer which
999
+ arguments are used to find the record and which are used to create it:
534
1000
 
535
- Model.limit(10).scoping { Model.count }
1001
+ User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson")
536
1002
 
537
- now generates the following SQL:
1003
+ *Andrés Mejía*
538
1004
 
539
- SELECT COUNT(*) FROM models LIMIT 10
1005
+ * Fix nested attributes bug where _destroy parameter is taken into account
1006
+ during :reject_if => :all_blank (fixes #2937)
540
1007
 
541
- This may not return what you want. Instead, you may with to do something
542
- like this:
1008
+ *Aaron Christy*
543
1009
 
544
- Model.limit(10).scoping { Model.all.size }
1010
+ * Add ActiveSupport::Cache::NullStore for use in development and testing.
545
1011
 
546
- *Aaron Patterson*
1012
+ *Brian Durand*
547
1013
 
548
- Please check [3-0-stable](https://github.com/rails/rails/blob/3-0-stable/activerecord/CHANGELOG) for previous changes.
1014
+ Please check [3-1-stable](https://github.com/rails/rails/blob/3-1-stable/activerecord/CHANGELOG.md) for previous changes.