activerecord 3.1.9 → 3.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. checksums.yaml +6 -6
  2. data/CHANGELOG.md +317 -336
  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 +3 -42
  8. data/lib/active_record/associations/association_scope.rb +3 -15
  9. data/lib/active_record/associations/builder/association.rb +6 -4
  10. data/lib/active_record/associations/builder/belongs_to.rb +3 -3
  11. data/lib/active_record/associations/builder/collection_association.rb +2 -2
  12. data/lib/active_record/associations/builder/has_many.rb +4 -4
  13. data/lib/active_record/associations/builder/has_one.rb +5 -6
  14. data/lib/active_record/associations/builder/singular_association.rb +3 -16
  15. data/lib/active_record/associations/collection_association.rb +64 -31
  16. data/lib/active_record/associations/collection_proxy.rb +2 -37
  17. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +1 -0
  18. data/lib/active_record/associations/has_many_association.rb +5 -1
  19. data/lib/active_record/associations/has_many_through_association.rb +28 -9
  20. data/lib/active_record/associations/has_one_association.rb +15 -13
  21. data/lib/active_record/associations/join_dependency.rb +2 -2
  22. data/lib/active_record/associations/preloader.rb +14 -10
  23. data/lib/active_record/associations/through_association.rb +7 -3
  24. data/lib/active_record/associations.rb +92 -76
  25. data/lib/active_record/attribute_assignment.rb +221 -0
  26. data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +32 -0
  27. data/lib/active_record/attribute_methods/dirty.rb +21 -11
  28. data/lib/active_record/attribute_methods/primary_key.rb +62 -25
  29. data/lib/active_record/attribute_methods/read.rb +73 -83
  30. data/lib/active_record/attribute_methods/serialization.rb +102 -0
  31. data/lib/active_record/attribute_methods/time_zone_conversion.rb +23 -17
  32. data/lib/active_record/attribute_methods/write.rb +31 -6
  33. data/lib/active_record/attribute_methods.rb +231 -30
  34. data/lib/active_record/autosave_association.rb +43 -22
  35. data/lib/active_record/base.rb +227 -1708
  36. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +150 -148
  37. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +85 -29
  38. data/lib/active_record/connection_adapters/abstract/database_statements.rb +6 -33
  39. data/lib/active_record/connection_adapters/abstract/query_cache.rb +10 -2
  40. data/lib/active_record/connection_adapters/abstract/quoting.rb +15 -6
  41. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +37 -26
  42. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +48 -19
  43. data/lib/active_record/connection_adapters/abstract_adapter.rb +77 -42
  44. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +674 -0
  45. data/lib/active_record/connection_adapters/column.rb +37 -11
  46. data/lib/active_record/connection_adapters/mysql2_adapter.rb +129 -581
  47. data/lib/active_record/connection_adapters/mysql_adapter.rb +137 -696
  48. data/lib/active_record/connection_adapters/postgresql_adapter.rb +184 -86
  49. data/lib/active_record/connection_adapters/schema_cache.rb +50 -0
  50. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +2 -6
  51. data/lib/active_record/connection_adapters/sqlite_adapter.rb +55 -32
  52. data/lib/active_record/counter_cache.rb +9 -4
  53. data/lib/active_record/dynamic_finder_match.rb +12 -0
  54. data/lib/active_record/dynamic_matchers.rb +84 -0
  55. data/lib/active_record/errors.rb +11 -1
  56. data/lib/active_record/explain.rb +85 -0
  57. data/lib/active_record/explain_subscriber.rb +25 -0
  58. data/lib/active_record/fixtures/file.rb +65 -0
  59. data/lib/active_record/fixtures.rb +56 -85
  60. data/lib/active_record/identity_map.rb +3 -4
  61. data/lib/active_record/inheritance.rb +174 -0
  62. data/lib/active_record/integration.rb +49 -0
  63. data/lib/active_record/locking/optimistic.rb +30 -25
  64. data/lib/active_record/locking/pessimistic.rb +23 -1
  65. data/lib/active_record/log_subscriber.rb +3 -3
  66. data/lib/active_record/migration/command_recorder.rb +8 -8
  67. data/lib/active_record/migration.rb +68 -35
  68. data/lib/active_record/model_schema.rb +366 -0
  69. data/lib/active_record/nested_attributes.rb +3 -2
  70. data/lib/active_record/persistence.rb +57 -11
  71. data/lib/active_record/querying.rb +58 -0
  72. data/lib/active_record/railtie.rb +31 -29
  73. data/lib/active_record/railties/controller_runtime.rb +3 -1
  74. data/lib/active_record/railties/databases.rake +191 -110
  75. data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
  76. data/lib/active_record/readonly_attributes.rb +26 -0
  77. data/lib/active_record/reflection.rb +7 -15
  78. data/lib/active_record/relation/batches.rb +5 -2
  79. data/lib/active_record/relation/calculations.rb +47 -15
  80. data/lib/active_record/relation/delegation.rb +49 -0
  81. data/lib/active_record/relation/finder_methods.rb +9 -7
  82. data/lib/active_record/relation/predicate_builder.rb +18 -7
  83. data/lib/active_record/relation/query_methods.rb +75 -9
  84. data/lib/active_record/relation/spawn_methods.rb +11 -2
  85. data/lib/active_record/relation.rb +78 -32
  86. data/lib/active_record/result.rb +1 -1
  87. data/lib/active_record/sanitization.rb +194 -0
  88. data/lib/active_record/schema_dumper.rb +12 -5
  89. data/lib/active_record/scoping/default.rb +142 -0
  90. data/lib/active_record/scoping/named.rb +202 -0
  91. data/lib/active_record/scoping.rb +152 -0
  92. data/lib/active_record/serialization.rb +1 -43
  93. data/lib/active_record/serializers/xml_serializer.rb +4 -45
  94. data/lib/active_record/session_store.rb +17 -15
  95. data/lib/active_record/store.rb +52 -0
  96. data/lib/active_record/test_case.rb +11 -7
  97. data/lib/active_record/timestamp.rb +17 -3
  98. data/lib/active_record/transactions.rb +27 -6
  99. data/lib/active_record/translation.rb +22 -0
  100. data/lib/active_record/validations/associated.rb +5 -4
  101. data/lib/active_record/validations/uniqueness.rb +7 -7
  102. data/lib/active_record/validations.rb +1 -1
  103. data/lib/active_record/version.rb +2 -2
  104. data/lib/active_record.rb +38 -3
  105. data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -1
  106. data/lib/rails/generators/active_record/migration/templates/migration.rb +12 -3
  107. data/lib/rails/generators/active_record/model/model_generator.rb +9 -1
  108. data/lib/rails/generators/active_record/model/templates/migration.rb +3 -5
  109. data/lib/rails/generators/active_record/model/templates/model.rb +5 -0
  110. data/lib/rails/generators/active_record/session_migration/templates/migration.rb +1 -5
  111. metadata +30 -10
  112. data/lib/active_record/named_scope.rb +0 -200
data/CHANGELOG.md CHANGED
@@ -1,525 +1,506 @@
1
- ## Rails 3.1.9
1
+ ## Rails 3.2.12 (unreleased) ##
2
2
 
3
- * CVE-2012-5664 ensure that options are never taken from the first parameter
3
+ * Quote numeric values being compared to non-numeric columns. Otherwise,
4
+ in some database, the string column values will be coerced to a numeric
5
+ allowing 0, 0.0 or false to match any string starting with a non-digit.
4
6
 
5
- ## Rails 3.1.8 (Aug 9, 2012)
7
+ Example:
6
8
 
7
- * No changes.
9
+ App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
8
10
 
9
- ## Rails 3.1.7 (Jul 26, 2012)
11
+ *Dylan Smith*
10
12
 
11
- * No changes.
13
+ ## Rails 3.2.11 (Jan 8, 2013) ##
12
14
 
13
- ## Rails 3.1.6 (Jun 12, 2012)
15
+ * Fix querying with an empty hash *Damien Mathieu* [CVE-2013-0155]
14
16
 
15
- * protect against the nesting of hashes changing the
16
- table context in the next call to build_from_hash. This fix
17
- covers this case as well.
17
+ ## Rails 3.2.10 ##
18
18
 
19
- CVE-2012-2695
19
+ * CVE-2012-5664 options hashes should only be extracted if there are extra
20
+ parameters
20
21
 
21
- ## Rails 3.1.5 (May 31, 2012) ##
22
+ ## Rails 3.2.9 (Nov 12, 2012) ##
22
23
 
23
- * Fix type_to_sql with text and limit on mysql/mysql2. Fix GH #3931.
24
+ * Fix issue with collection associations calling first(n)/last(n) and attempting
25
+ to set the inverse association when `:inverse_of` was used. Fixes #8087.
24
26
 
25
- * only log an error if there is a logger. fixes #5226
27
+ *Carlos Antonio da Silva*
26
28
 
27
- * fix activerecord query_method regression with offset into Fixnum
29
+ * Fix bug when Column is trying to type cast boolean values to integer.
30
+ Fixes #8067.
28
31
 
29
- * predicate builder should not recurse for determining where columns.
30
- Thanks to Ben Murphy for reporting this! CVE-2012-2661
32
+ *Rafael Mendonça França*
31
33
 
32
- ## Rails 3.1.4 (unreleased) ##
34
+ * Fix bug where `rake db:test:prepare` tries to load the structure.sql into development database.
35
+ Fixes #8032.
33
36
 
34
- * Fix a custom primary key regression *GH 3987*
37
+ *Grace Liu + Rafael Mendonça França*
35
38
 
36
- *Jon Leighton*
39
+ * Fixed support for `DATABASE_URL` environment variable for rake db tasks. *Grace Liu*
37
40
 
38
- * Perf fix (second try): don't load records for `has many :dependent =>
39
- :delete_all` *GH 3672*
41
+ * Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
40
42
 
41
- *Jon Leighton*
43
+ *Henrik Nyh*
42
44
 
43
- * Fix accessing `proxy_association` method from an association extension
44
- where the calls are chained. *GH #3890*
45
+ * Decode URI encoded attributes on database connection URLs.
45
46
 
46
- (E.g. `post.comments.where(bla).my_proxy_method`)
47
+ *Shawn Veader*
47
48
 
48
- *Jon Leighton*
49
+ * Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
50
+ and the dup'ed object shared the same errors.
49
51
 
50
- * Perf fix: MySQL primary key lookup was still slow for very large
51
- tables. *GH 3678*
52
+ *Christian Seiler*
52
53
 
53
- *Kenny J*
54
+ * Synchronize around deleting from the reserved connections hash.
55
+ Fixes #7955
54
56
 
55
- * Perf fix: If a table has no primary key, don't repeatedly ask the database for it.
57
+ * PostgreSQL adapter correctly fetches default values when using
58
+ multiple schemas and domains in a db. Fixes #7914
56
59
 
57
- *Julius de Bruijn*
60
+ *Arturo Pie*
58
61
 
59
- ## Rails 3.1.3 (unreleased) ##
62
+ * Fix deprecation notice when loading a collection association that
63
+ selects columns from other tables, if a new record was previously
64
+ built using that association.
60
65
 
61
- * Perf fix: If we're deleting all records in an association, don't add a IN(..) clause
62
- to the query. *GH 3672*
66
+ *Ernie Miller*
63
67
 
64
- *Jon Leighton*
68
+ * The postgres adapter now supports tables with capital letters.
69
+ Fix #5920
65
70
 
66
- * Fix bug with referencing other mysql databases in set_table_name. *GH 3690*
71
+ *Yves Senn*
67
72
 
68
- * Fix performance bug with mysql databases on a server with lots of other databses. *GH 3678*
73
+ * `CollectionAssociation#count` returns `0` without querying if the
74
+ parent record is not persisted.
69
75
 
70
- *Christos Zisopoulos and Kenny J*
76
+ Before:
71
77
 
72
- ## Rails 3.1.2 (unreleased) ##
78
+ person.pets.count
79
+ # SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
80
+ # => 0
73
81
 
74
- * Fix problem with prepared statements and PostgreSQL when multiple schemas are used.
75
- *GH #3232*
82
+ After:
76
83
 
77
- *Juan M. Cuello*
84
+ person.pets.count
85
+ # fires without sql query
86
+ # => 0
78
87
 
79
- * Fix bug with PostgreSQLAdapter#indexes. When the search path has multiple schemas, spaces
80
- were not being stripped from the schema names after the first.
88
+ *Francesco Rodriguez*
81
89
 
82
- *Sean Kirby*
90
+ * Fix `reset_counters` crashing on `has_many :through` associations.
91
+ Fix #7822.
83
92
 
84
- * Preserve SELECT columns on the COUNT for finder_sql when possible. *GH 3503*
93
+ *lulalala*
85
94
 
86
- *Justin Mazzi*
95
+ * ConnectionPool recognizes checkout_timeout spec key as taking
96
+ precedence over legacy wait_timeout spec key, can be used to avoid
97
+ conflict with mysql2 use of wait_timeout. Closes #7684.
87
98
 
88
- * Reset prepared statement cache when schema changes impact statement results. *GH 3335*
99
+ *jrochkind*
89
100
 
90
- *Aaron Patterson*
101
+ * Rename field_changed? to _field_changed? so that users can create a field named field
91
102
 
92
- * Postgres: Do not attempt to deallocate a statement if the connection is no longer active.
103
+ *Akira Matsuda*, backported by *Steve Klabnik*
93
104
 
94
- *Ian Leitch*
105
+ * Fix creation of through association models when using `collection=[]`
106
+ on a `has_many :through` association from an unsaved model.
107
+ Fix #7661.
95
108
 
96
- * Prevent QueryCache leaking database connections. *GH 3243*
109
+ *Ernie Miller*
97
110
 
98
- *Mark J. Titorenko*
111
+ * Explain only normal CRUD sql (select / update / insert / delete).
112
+ Fix problem that explains unexplainable sql. Closes #7544 #6458.
99
113
 
100
- * Fix bug where building the conditions of a nested through association could potentially
101
- modify the conditions of the through and/or source association. If you have experienced
102
- bugs with conditions appearing in the wrong queries when using nested through associations,
103
- this probably solves your problems. *GH #3271*
114
+ *kennyj*
104
115
 
105
- *Jon Leighton*
116
+ * Backport test coverage to ensure that PostgreSQL auto-reconnect functionality
117
+ remains healthy.
106
118
 
107
- * If a record is removed from a has_many :through, all of the join records relating to that
108
- record should also be removed from the through association's target.
119
+ *Steve Jorgensen*
109
120
 
110
- *Jon Leighton*
121
+ * Use config['encoding'] instead of config['charset'] when executing
122
+ databases.rake in the mysql/mysql2. A correct option for a database.yml
123
+ is 'encoding'.
111
124
 
112
- * Fix adding multiple instances of the same record to a has_many :through. *GH #3425*
125
+ *kennyj*
113
126
 
114
- *Jon Leighton*
127
+ * Fix ConnectionAdapters::Column.type_cast_code integer conversion,
128
+ to always convert values to integer calling #to_i. Fixes #7509.
115
129
 
116
- * Fix creating records in a through association with a polymorphic source type. *GH #3247*
130
+ *Thiago Pradi*
117
131
 
118
- *Jon Leighton*
132
+ * Fix time column type casting for invalid time string values to correctly return nil.
119
133
 
120
- * MySQL: use the information_schema than the describe command when we look for a primary key. *GH #3440*
121
- *Kenny J*
134
+ *Adam Meehan*
122
135
 
123
- ## Rails 3.1.1 (October 7, 2011) ##
136
+ * Fix `becomes` when using a configured `inheritance_column`.
124
137
 
125
- * Raise an exception if the primary key of a model in an association is needed
126
- but unknown. Fixes #3207.
138
+ *Yves Senn*
127
139
 
128
- *Jon Leighton*
140
+ * Fix `reset_counters` when there are multiple `belongs_to` association with the
141
+ same foreign key and one of them have a counter cache.
142
+ Fixes #5200.
129
143
 
130
- * Add deprecation for the preload_associations method. Fixes #3022.
144
+ *Dave Desrochers*
131
145
 
132
- *Jon Leighton*
146
+ * Round usec when comparing timestamp attributes in the dirty tracking.
147
+ Fixes #6975.
133
148
 
134
- * Don't require a DB connection when loading a model that uses set_primary_key. GH #2807.
149
+ *kennyj*
135
150
 
136
- *Jon Leighton*
151
+ * Use inversed parent for first and last child of has_many association.
137
152
 
138
- * Fix using select() with a habtm association, e.g. Person.friends.select(:name). GH #3030 and
139
- \#2923.
153
+ *Ravil Bayramgalin*
140
154
 
141
- *Hendy Tanata*
155
+ * Fix Column.microseconds and Column.fast_string_to_date to avoid converting
156
+ timestamp seconds to a float, since it occasionally results in inaccuracies
157
+ with microsecond-precision times. Fixes #7352.
142
158
 
143
- * Fix belongs_to polymorphic with custom primary key on target. GH #3104.
159
+ *Ari Pollak*
144
160
 
145
- *Jon Leighton*
161
+ * Fix `increment!`, `decrement!`, `toggle!` that was skipping callbacks.
162
+ Fixes #7306.
146
163
 
147
- * CollectionProxy#replace should change the DB records rather than just mutating the array.
148
- Fixes #3020.
164
+ *Rafael Mendonça França*
149
165
 
150
- *Jon Leighton*
166
+ * Fix AR#create to return an unsaved record when AR::RecordInvalid is
167
+ raised. Fixes #3217.
151
168
 
152
- * LRU cache in mysql and sqlite are now per-process caches.
169
+ *Dave Yeu*
153
170
 
154
- * lib/active_record/connection_adapters/mysql_adapter.rb: LRU cache
155
- keys are per process id.
156
- * lib/active_record/connection_adapters/sqlite_adapter.rb: ditto
171
+ * Remove unnecessary transaction when assigning has_one associations with a nil or equal value.
172
+ Fix #7191.
157
173
 
158
- *Aaron Patterson*
174
+ *kennyj*
159
175
 
160
- * Database adapters use a statement pool for limiting the number of open
161
- prepared statments on the database. The limit defaults to 1000, but can
162
- be adjusted in your database config by changing 'statement_limit'.
176
+ * Allow store to work with an empty column.
177
+ Fix #4840.
163
178
 
164
- * Fix clash between using 'preload', 'joins' or 'eager_load' in a default scope and including the
165
- default scoped model in a nested through association. (GH #2834.) *Jon Leighton*
179
+ *Jeremy Walker*
166
180
 
167
- * Ensure we are not comparing a string with a symbol in HasManyAssociation#inverse_updates_counter_cache?.
168
- Fixes GH #2755, where a counter cache could be decremented twice as far as it was supposed to be.
181
+ * Remove prepared statement from system query in postgresql adapter.
182
+ Fix #5872.
169
183
 
170
- *Jon Leighton*
184
+ *Ivan Evtuhovich*
171
185
 
172
- * Don't send any queries to the database when the foreign key of a belongs_to is nil. Fixes
173
- GH #2828. *Georg Friedrich*
186
+ * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`
187
+ Fixes #4772.
174
188
 
175
- * Fixed find_in_batches method to not include order from default_scope. See GH #2832 *Arun Agrawal*
189
+ *Seamus Abshere*
176
190
 
177
- * Don't compute table name for abstract classes. Fixes problem with setting the primary key
178
- in an abstract class. See GH #2791. *Akira Matsuda*
179
191
 
180
- * Psych errors with poor yaml formatting are proxied. Fixes GH #2645 and
181
- GH #2731
192
+ ## Rails 3.2.8 (Aug 9, 2012) ##
182
193
 
183
- * Use the LIMIT word with the methods #last and #first. Fixes GH #2783 *Damien Mathieu*
194
+ * Do not consider the numeric attribute as changed if the old value is zero and the new value
195
+ is not a string.
196
+ Fixes #7237.
184
197
 
185
- ## Rails 3.1.0 (August 30, 2011) ##
198
+ *Rafael Mendonça França*
186
199
 
187
- * Add a proxy_association method to association proxies, which can be called by association
188
- extensions to access information about the association. This replaces proxy_owner etc with
189
- proxy_association.owner.
200
+ * Removes the deprecation of `update_attribute`. *fxn*
190
201
 
191
- *Jon Leighton*
202
+ * Reverted the deprecation of `composed_of`. *Rafael Mendonça França*
192
203
 
193
- * 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*
204
+ * Reverted the deprecation of `*_sql` association options. They will
205
+ be deprecated in 4.0 instead. *Jon Leighton*
194
206
 
195
- * Deprecated the AssociationCollection constant. CollectionProxy is now the appropriate constant
196
- to use, though be warned that this is not really a public API.
207
+ * Do not eager load AR session store. ActiveRecord::SessionStore depends on the abstract store
208
+ in Action Pack. Eager loading this class would break client code that eager loads Active Record
209
+ standalone.
210
+ Fixes #7160
197
211
 
198
- This should solve upgrade problems with the will_paginate plugin (and perhaps others). Thanks
199
- Paul Battley for reporting.
212
+ *Xavier Noria*
200
213
 
201
- *Jon Leighton*
214
+ * Do not set RAILS_ENV to "development" when using `db:test:prepare` and related rake tasks.
215
+ This was causing the truncation of the development database data when using RSpec.
216
+ Fixes #7175.
202
217
 
203
- * ActiveRecord::MacroReflection::AssociationReflection#build_record has a new method signature.
218
+ *Rafael Mendonça França*
204
219
 
205
- Before: def build_association(*options)
206
- After: def build_association(*options, &block)
220
+ ## Rails 3.2.7 (Jul 26, 2012) ##
207
221
 
208
- Users who are redefining this method to extend functionality should ensure that the block is
209
- passed through to ActiveRecord::Base#new.
222
+ * `:finder_sql` and `:counter_sql` options on collection associations
223
+ are deprecated. Please transition to using scopes.
210
224
 
211
- This change is necessary to fix https://github.com/rails/rails/issues/1842.
225
+ *Jon Leighton*
212
226
 
213
- A deprecation warning and workaround has been added to 3.1, but authors will need to update
214
- their code for it to work correctly in 3.2.
227
+ * `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
228
+ associations are deprecated. Please transition to using `has_many
229
+ :through`
215
230
 
216
231
  *Jon Leighton*
217
232
 
218
- * AR#pluralize_table_names can be used to singularize/pluralize table name of an individual model:
233
+ * `composed_of` has been deprecated. You'll have to write your own accessor
234
+ and mutator methods if you'd like to use value objects to represent some
235
+ portion of your models.
219
236
 
220
- class User < ActiveRecord::Base
221
- self.pluralize_table_names = false
222
- end
237
+ *Steve Klabnik*
223
238
 
224
- Previously this could only be set globally for all models through ActiveRecord::Base.pluralize_table_names. *Guillermo Iguaran*
239
+ * `update_attribute` has been deprecated. Use `update_column` if
240
+ you want to bypass mass-assignment protection, validations, callbacks,
241
+ and touching of updated_at. Otherwise please use `update_attributes`.
225
242
 
226
- * Add block setting of attributes to singular associations:
243
+ *Steve Klabnik*
227
244
 
228
- class User < ActiveRecord::Base
229
- has_one :account
230
- end
245
+ ## Rails 3.2.6 (Jun 12, 2012) ##
231
246
 
232
- user.build_account{ |a| a.credit_limit => 100.0 }
247
+ * protect against the nesting of hashes changing the
248
+ table context in the next call to build_from_hash. This fix
249
+ covers this case as well.
233
250
 
234
- The block is called after the instance has been initialized. *Andrew White*
251
+ CVE-2012-2695
235
252
 
236
- * 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*
253
+ * Revert earlier 'perf fix' (see 3.2.4 changelog / GH #6289). This
254
+ change introduced a regression (GH #6609). assoc.clear and
255
+ assoc.delete_all have loaded the association before doing the delete
256
+ since at least Rails 2.3. Doing the delete without loading the
257
+ records means that the `before_remove` and `after_remove` callbacks do
258
+ not get invoked. Therefore, this change was less a fix a more an
259
+ optimisation, which should only have gone into master.
237
260
 
238
- * CSV Fixtures are deprecated and support will be removed in Rails 3.2.0
261
+ *Jon Leighton*
239
262
 
240
- * AR#new, AR#create, AR#create!, AR#update_attributes and AR#update_attributes! all accept a second hash as option that allows you
241
- to specify which role to consider when assigning attributes. This is built on top of ActiveModel's
242
- new mass assignment capabilities:
263
+ ## Rails 3.2.5 (Jun 1, 2012) ##
243
264
 
244
- class Post < ActiveRecord::Base
245
- attr_accessible :title
246
- attr_accessible :title, :published_at, :as => :admin
247
- end
265
+ * Restore behavior of Active Record 3.2.3 scopes.
266
+ A series of commits relating to preloading and scopes caused a regression.
248
267
 
249
- Post.new(params[:post], :as => :admin)
268
+ *Andrew White*
250
269
 
251
- assign_attributes() with similar API was also added and attributes=(params, guard) was deprecated.
252
270
 
253
- 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.
271
+ ## Rails 3.2.4 (May 31, 2012) ##
254
272
 
255
- *Josh Kalderimis*
273
+ * Perf fix: Don't load the records when doing assoc.delete_all.
274
+ GH #6289. *Jon Leighton*
256
275
 
257
- * default_scope can take a block, lambda, or any other object which responds to `call` for lazy
258
- evaluation:
276
+ * Association preloading shouldn't be affected by the current scoping.
277
+ This could cause infinite recursion and potentially other problems.
278
+ See GH #5667. *Jon Leighton*
259
279
 
260
- default_scope { ... }
261
- default_scope lambda { ... }
262
- default_scope method(:foo)
280
+ * Datetime attributes are forced to be changed. GH #3965
263
281
 
264
- This feature was originally implemented by Tim Morgan, but was then removed in favour of
265
- defining a 'default_scope' class method, but has now been added back in by Jon Leighton.
266
- The relevant lighthouse ticket is #1812.
282
+ * Fix attribute casting. GH #5549
267
283
 
268
- * Default scopes are now evaluated at the latest possible moment, to avoid problems where
269
- scopes would be created which would implicitly contain the default scope, which would then
270
- be impossible to get rid of via Model.unscoped.
284
+ * Fix #5667. Preloading should ignore scoping.
271
285
 
272
- Note that this means that if you are inspecting the internal structure of an
273
- ActiveRecord::Relation, it will *not* contain the default scope, though the resulting
274
- query will do. You can get a relation containing the default scope by calling
275
- ActiveRecord#with_default_scope, though this is not part of the public API.
286
+ * Predicate builder should not recurse for determining where columns.
287
+ Thanks to Ben Murphy for reporting this! CVE-2012-2661
276
288
 
277
- *Jon Leighton*
278
289
 
279
- * If you wish to merge default scopes in special ways, it is recommended to define your default
280
- scope as a class method and use the standard techniques for sharing code (inheritance, mixins,
281
- etc.):
290
+ ## Rails 3.2.3 (March 30, 2012) ##
282
291
 
283
- class Post < ActiveRecord::Base
284
- def self.default_scope
285
- where(:published => true).where(:hidden => false)
286
- end
287
- end
292
+ * Added find_or_create_by_{attribute}! dynamic method. *Andrew White*
288
293
 
289
- *Jon Leighton*
294
+ * 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*
290
295
 
291
- * PostgreSQL adapter only supports PostgreSQL version 8.2 and higher.
296
+ * Update ActiveRecord::AttributeMethods#attribute_present? to return false for empty strings. *Jacobkg*
292
297
 
293
- * ConnectionManagement middleware is changed to clean up the connection pool
294
- after the rack body has been flushed.
298
+ * Fix associations when using per class databases. *larskanis*
295
299
 
296
- * Added an update_column method on ActiveRecord. This new method updates a given attribute on an object, skipping validations and callbacks.
297
- It is recommended to use #update_attribute unless you are sure you do not want to execute any callback, including the modification of
298
- the updated_at column. It should not be called on new records.
299
- Example:
300
+ * Revert setting NOT NULL constraints in add_timestamps *fxn*
300
301
 
301
- User.first.update_column(:name, "sebastian") # => true
302
+ * Fix mysql to use proper text types. Fixes #3931. *kennyj*
302
303
 
303
- *Sebastian Martinez*
304
+ * Fix #5069 - Protect foreign key from mass assignment through association builder. *byroot*
304
305
 
305
- * Associations with a :through option can now use *any* association as the
306
- through or source association, including other associations which have a
307
- :through option and has_and_belongs_to_many associations
308
306
 
309
- *Jon Leighton*
307
+ ## Rails 3.2.2 (March 1, 2012) ##
310
308
 
311
- * The configuration for the current database connection is now accessible via
312
- ActiveRecord::Base.connection_config. *fxn*
309
+ * No changes.
313
310
 
314
- * limits and offsets are removed from COUNT queries unless both are supplied.
315
- For example:
316
311
 
317
- People.limit(1).count # => 'SELECT COUNT(*) FROM people'
318
- People.offset(1).count # => 'SELECT COUNT(*) FROM people'
319
- People.limit(1).offset(1).count # => 'SELECT COUNT(*) FROM people LIMIT 1 OFFSET 1'
312
+ ## Rails 3.2.1 (January 26, 2012) ##
320
313
 
321
- *lighthouse #6262*
314
+ * The threshold for auto EXPLAIN is ignored if there's no logger. *fxn*
322
315
 
323
- * ActiveRecord::Associations::AssociationProxy has been split. There is now an Association class
324
- (and subclasses) which are responsible for operating on associations, and then a separate,
325
- thin wrapper called CollectionProxy, which proxies collection associations.
316
+ * Call `to_s` on the value passed to `table_name=`, in particular symbols
317
+ are supported (regression). *Sergey Nartimov*
326
318
 
327
- This prevents namespace pollution, separates concerns, and will allow further refactorings.
319
+ * Fix possible race condition when two threads try to define attribute
320
+ methods for the same class. *Jon Leighton*
328
321
 
329
- Singular associations (has_one, belongs_to) no longer have a proxy at all. They simply return
330
- the associated record or nil. This means that you should not use undocumented methods such
331
- as bob.mother.create - use bob.create_mother instead.
332
322
 
333
- *Jon Leighton*
323
+ ## Rails 3.2.0 (January 20, 2012) ##
334
324
 
335
- * Make has_many :through associations work correctly when you build a record and then save it. This
336
- requires you to set the :inverse_of option on the source reflection on the join model, like so:
325
+ * Added a `with_lock` method to ActiveRecord objects, which starts
326
+ a transaction, locks the object (pessimistically) and yields to the block.
327
+ The method takes one (optional) parameter and passes it to `lock!`.
337
328
 
338
- class Post < ActiveRecord::Base
339
- has_many :taggings
340
- has_many :tags, :through => :taggings
341
- end
329
+ Before:
342
330
 
343
- class Tagging < ActiveRecord::Base
344
- belongs_to :post
345
- belongs_to :tag, :inverse_of => :tagging # :inverse_of must be set!
346
- end
331
+ class Order < ActiveRecord::Base
332
+ def cancel!
333
+ transaction do
334
+ lock!
335
+ # ... cancelling logic
336
+ end
337
+ end
338
+ end
347
339
 
348
- class Tag < ActiveRecord::Base
349
- has_many :taggings
350
- has_many :posts, :through => :taggings
351
- end
340
+ After:
352
341
 
353
- post = Post.first
354
- tag = post.tags.build :name => "ruby"
355
- tag.save # will save a Taggable linking to the post
342
+ class Order < ActiveRecord::Base
343
+ def cancel!
344
+ with_lock do
345
+ # ... cancelling logic
346
+ end
347
+ end
348
+ end
356
349
 
357
- *Jon Leighton*
350
+ *Olek Janiszewski*
358
351
 
359
- * Support the :dependent option on has_many :through associations. For historical and practical
360
- reasons, :delete_all is the default deletion strategy employed by association.delete(*records),
361
- despite the fact that the default strategy is :nullify for regular has_many. Also, this only
362
- works at all if the source reflection is a belongs_to. For other situations, you should directly
363
- modify the through association.
352
+ * 'on' and 'ON' boolean columns values are type casted to true
353
+ *Santiago Pastorino*
364
354
 
365
- *Jon Leighton*
355
+ * Added ability to run migrations only for given scope, which allows
356
+ to run migrations only from one engine (for example to revert changes
357
+ from engine that you want to remove).
366
358
 
367
- * Changed the behaviour of association.destroy for has_and_belongs_to_many and has_many :through.
368
- From now on, 'destroy' or 'delete' on an association will be taken to mean 'get rid of the link',
369
- not (necessarily) 'get rid of the associated records'.
359
+ Example:
360
+ rake db:migrate SCOPE=blog
370
361
 
371
- Previously, has_and_belongs_to_many.destroy(*records) would destroy the records themselves. It
372
- would not delete any records in the join table. Now, it deletes the records in the join table.
362
+ *Piotr Sarnacki*
373
363
 
374
- Previously, has_many_through.destroy(*records) would destroy the records themselves, and the
375
- records in the join table. [Note: This has not always been the case; previous version of Rails
376
- only deleted the records themselves.] Now, it destroys only the records in the join table.
364
+ * Migrations copied from engines are now scoped with engine's name,
365
+ for example 01_create_posts.blog.rb. *Piotr Sarnacki*
377
366
 
378
- Note that this change is backwards-incompatible to an extent, but there is unfortunately no
379
- way to 'deprecate' it before changing it. The change is being made in order to have
380
- consistency as to the meaning of 'destroy' or 'delete' across the different types of associations.
367
+ * Implements `AR::Base.silence_auto_explain`. This method allows the user to
368
+ selectively disable automatic EXPLAINs within a block. *fxn*
381
369
 
382
- If you wish to destroy the records themselves, you can do records.association.each(&:destroy)
370
+ * Implements automatic EXPLAIN logging for slow queries.
383
371
 
384
- *Jon Leighton*
372
+ A new configuration parameter `config.active_record.auto_explain_threshold_in_seconds`
373
+ determines what's to be considered a slow query. Setting that to `nil` disables
374
+ this feature. Defaults are 0.5 in development mode, and `nil` in test and production
375
+ modes.
385
376
 
386
- * 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*
377
+ As of this writing there's support for SQLite, MySQL (mysql2 adapter), and
378
+ PostgreSQL.
387
379
 
388
- Example:
380
+ *fxn*
389
381
 
390
- change_table(:users, :bulk => true) do |t|
391
- t.string :company_name
392
- t.change :birthdate, :datetime
393
- end
382
+ * Implemented ActiveRecord::Relation#pluck method
394
383
 
395
- This will now result in:
384
+ Method returns Array of column value from table under ActiveRecord model
396
385
 
397
- ALTER TABLE `users` ADD COLUMN `company_name` varchar(255), CHANGE `updated_at` `updated_at` datetime DEFAULT NULL
386
+ Client.pluck(:id)
398
387
 
399
- * Removed support for accessing attributes on a has_and_belongs_to_many join table. This has been
400
- documented as deprecated behaviour since April 2006. Please use has_many :through instead.
401
- *Jon Leighton*
388
+ *Bogdan Gusiev*
402
389
 
403
- * Added a create_association! method for has_one and belongs_to associations. *Jon Leighton*
390
+ * Automatic closure of connections in threads is deprecated. For example
391
+ the following code is deprecated:
404
392
 
405
- * Migration files generated from model and constructive migration generators
406
- (for example, add_name_to_users) use the reversible migration's `change`
407
- method instead of the ordinary `up` and `down` methods. *Prem Sichanugrist*
393
+ Thread.new { Post.find(1) }.join
408
394
 
409
- * Removed support for interpolating string SQL conditions on associations. Instead, you should
410
- use a proc, like so:
395
+ It should be changed to close the database connection at the end of
396
+ the thread:
411
397
 
412
- Before:
398
+ Thread.new {
399
+ Post.find(1)
400
+ Post.connection.close
401
+ }.join
413
402
 
414
- has_many :things, :conditions => 'foo = #{bar}'
403
+ Only people who spawn threads in their application code need to worry
404
+ about this change.
415
405
 
416
- After:
406
+ * Deprecated:
407
+
408
+ * `set_table_name`
409
+ * `set_inheritance_column`
410
+ * `set_sequence_name`
411
+ * `set_primary_key`
412
+ * `set_locking_column`
417
413
 
418
- has_many :things, :conditions => proc { "foo = #{bar}" }
414
+ Use an assignment method instead. For example, instead of `set_table_name`, use `self.table_name=`:
419
415
 
420
- Inside the proc, 'self' is the object which is the owner of the association, unless you are
421
- eager loading the association, in which case 'self' is the class which the association is within.
416
+ class Project < ActiveRecord::Base
417
+ self.table_name = "project"
418
+ end
422
419
 
423
- You can have any "normal" conditions inside the proc, so the following will work too:
420
+ Or define your own `self.table_name` method:
424
421
 
425
- has_many :things, :conditions => proc { ["foo = ?", bar] }
422
+ class Post < ActiveRecord::Base
423
+ def self.table_name
424
+ "special_" + super
425
+ end
426
+ end
427
+ Post.table_name # => "special_posts"
426
428
 
427
- Previously :insert_sql and :delete_sql on has_and_belongs_to_many association allowed you to call
428
- 'record' to get the record being inserted or deleted. This is now passed as an argument to
429
- the proc.
429
+ *Jon Leighton*
430
430
 
431
- * Added ActiveRecord::Base#has_secure_password (via ActiveModel::SecurePassword) to encapsulate dead-simple password usage with BCrypt encryption and salting [DHH]. Example:
431
+ * Generated association methods are created within a separate module to allow overriding and
432
+ composition using `super`. For a class named `MyModel`, the module is named
433
+ `MyModel::GeneratedFeatureMethods`. It is included into the model class immediately after
434
+ the `generated_attributes_methods` module defined in ActiveModel, so association methods
435
+ override attribute methods of the same name. *Josh Susser*
432
436
 
433
- # Schema: User(name:string, password_digest:string, password_salt:string)
434
- class User < ActiveRecord::Base
435
- has_secure_password
436
- end
437
+ * Implemented ActiveRecord::Relation#explain. *fxn*
437
438
 
438
- user = User.new(:name => "david", :password => "", :password_confirmation => "nomatch")
439
- user.save # => false, password required
440
- user.password = "mUc3m00RsqyRe"
441
- user.save # => false, confirmation doesn't match
442
- user.password_confirmation = "mUc3m00RsqyRe"
443
- user.save # => true
444
- user.authenticate("notright") # => false
445
- user.authenticate("mUc3m00RsqyRe") # => user
446
- User.find_by_name("david").try(:authenticate, "notright") # => nil
447
- User.find_by_name("david").try(:authenticate, "mUc3m00RsqyRe") # => user
439
+ * Add ActiveRecord::Relation#uniq for generating unique queries.
448
440
 
441
+ Before:
449
442
 
450
- * When a model is generated add_index is added by default for belongs_to or references columns
443
+ Client.select('DISTINCT name')
451
444
 
452
- rails g model post user:belongs_to will generate the following:
445
+ After:
453
446
 
454
- class CreatePosts < ActiveRecord::Migration
455
- def change
456
- create_table :posts do |t|
457
- t.belongs_to :user
458
- t.timestamps
459
- end
460
- add_index :posts, :user_id
461
- end
462
- end
447
+ Client.select(:name).uniq
463
448
 
464
- *Santiago Pastorino*
449
+ This also allows you to revert the unqueness in a relation:
465
450
 
466
- * Setting the id of a belongs_to object will update the reference to the
467
- object. *#2989 state:resolved*
451
+ Client.select(:name).uniq.uniq(false)
468
452
 
469
- * ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed
470
- to closer match normal Ruby dup and clone semantics.
453
+ *Jon Leighton*
471
454
 
472
- * Calling ActiveRecord::Base#clone will result in a shallow copy of the record,
473
- including copying the frozen state. No callbacks will be called.
455
+ * Support index sort order in sqlite, mysql and postgres adapters. *Vlad Jebelev*
474
456
 
475
- * Calling ActiveRecord::Base#dup will duplicate the record, including calling
476
- after initialize hooks. Frozen state will not be copied, and all associations
477
- will be cleared. A duped record will return true for new_record?, have a nil
478
- id field, and is saveable.
457
+ * Allow the :class_name option for associations to take a symbol (:Client) in addition to
458
+ a string ('Client').
479
459
 
480
- * Migrations can be defined as reversible, meaning that the migration system
481
- will figure out how to reverse your migration. To use reversible migrations,
482
- just define the "change" method. For example:
460
+ This is to avoid confusing newbies, and to be consistent with the fact that other options
461
+ like :foreign_key already allow a symbol or a string.
483
462
 
484
- class MyMigration < ActiveRecord::Migration
485
- def change
486
- create_table(:horses) do
487
- t.column :content, :text
488
- t.column :remind_at, :datetime
489
- end
490
- end
491
- end
463
+ *Jon Leighton*
492
464
 
493
- Some things cannot be automatically reversed for you. If you know how to
494
- reverse those things, you should define 'up' and 'down' in your migration. If
495
- you define something in `change` that cannot be reversed, an
496
- IrreversibleMigration exception will be raised when going down.
465
+ * In development mode the db:drop task also drops the test database. For symmetry with
466
+ the db:create task. *Dmitriy Kiriyenko*
497
467
 
498
- * Migrations should use instance methods rather than class methods:
499
- class FooMigration < ActiveRecord::Migration
500
- def up
501
- ...
502
- end
468
+ * Added ActiveRecord::Base.store for declaring simple single-column key/value stores *DHH*
469
+
470
+ class User < ActiveRecord::Base
471
+ store :settings, accessors: [ :color, :homepage ]
503
472
  end
504
473
 
505
- *Aaron Patterson*
474
+ u = User.new(color: 'black', homepage: '37signals.com')
475
+ u.color # Accessor stored attribute
476
+ u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor
477
+
478
+
479
+ * MySQL: case-insensitive uniqueness validation avoids calling LOWER when
480
+ the column already uses a case-insensitive collation. Fixes #561.
481
+
482
+ *Joseph Palermo*
483
+
484
+ * Transactional fixtures enlist all active database connections. You can test
485
+ models on different connections without disabling transactional fixtures.
506
486
 
507
- * has_one maintains the association with separate after_create/after_update instead
508
- of a single after_save. *fxn*
487
+ *Jeremy Kemper*
509
488
 
510
- * The following code:
489
+ * Add first_or_create, first_or_create!, first_or_initialize methods to Active Record. This is a
490
+ better approach over the old find_or_create_by dynamic methods because it's clearer which
491
+ arguments are used to find the record and which are used to create it:
511
492
 
512
- Model.limit(10).scoping { Model.count }
493
+ User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson")
513
494
 
514
- now generates the following SQL:
495
+ *Andrés Mejía*
515
496
 
516
- SELECT COUNT(*) FROM models LIMIT 10
497
+ * Fix nested attributes bug where _destroy parameter is taken into account
498
+ during :reject_if => :all_blank (fixes #2937)
517
499
 
518
- This may not return what you want. Instead, you may with to do something
519
- like this:
500
+ *Aaron Christy*
520
501
 
521
- Model.limit(10).scoping { Model.all.size }
502
+ * Add ActiveSupport::Cache::NullStore for use in development and testing.
522
503
 
523
- *Aaron Patterson*
504
+ *Brian Durand*
524
505
 
525
- Please check [3-0-stable](https://github.com/rails/rails/blob/3-0-stable/activerecord/CHANGELOG) for previous changes.
506
+ Please check [3-1-stable](https://github.com/rails/rails/blob/3-1-stable/activerecord/CHANGELOG.md) for previous changes.