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.
- checksums.yaml +6 -6
- data/CHANGELOG.md +317 -336
- data/README.rdoc +3 -3
- data/examples/performance.rb +20 -1
- data/lib/active_record/aggregations.rb +1 -1
- data/lib/active_record/associations/alias_tracker.rb +3 -6
- data/lib/active_record/associations/association.rb +3 -42
- data/lib/active_record/associations/association_scope.rb +3 -15
- data/lib/active_record/associations/builder/association.rb +6 -4
- data/lib/active_record/associations/builder/belongs_to.rb +3 -3
- data/lib/active_record/associations/builder/collection_association.rb +2 -2
- data/lib/active_record/associations/builder/has_many.rb +4 -4
- data/lib/active_record/associations/builder/has_one.rb +5 -6
- data/lib/active_record/associations/builder/singular_association.rb +3 -16
- data/lib/active_record/associations/collection_association.rb +64 -31
- data/lib/active_record/associations/collection_proxy.rb +2 -37
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +1 -0
- data/lib/active_record/associations/has_many_association.rb +5 -1
- data/lib/active_record/associations/has_many_through_association.rb +28 -9
- data/lib/active_record/associations/has_one_association.rb +15 -13
- data/lib/active_record/associations/join_dependency.rb +2 -2
- data/lib/active_record/associations/preloader.rb +14 -10
- data/lib/active_record/associations/through_association.rb +7 -3
- data/lib/active_record/associations.rb +92 -76
- data/lib/active_record/attribute_assignment.rb +221 -0
- data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +32 -0
- data/lib/active_record/attribute_methods/dirty.rb +21 -11
- data/lib/active_record/attribute_methods/primary_key.rb +62 -25
- data/lib/active_record/attribute_methods/read.rb +73 -83
- data/lib/active_record/attribute_methods/serialization.rb +102 -0
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +23 -17
- data/lib/active_record/attribute_methods/write.rb +31 -6
- data/lib/active_record/attribute_methods.rb +231 -30
- data/lib/active_record/autosave_association.rb +43 -22
- data/lib/active_record/base.rb +227 -1708
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +150 -148
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +85 -29
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +6 -33
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +10 -2
- data/lib/active_record/connection_adapters/abstract/quoting.rb +15 -6
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +37 -26
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +48 -19
- data/lib/active_record/connection_adapters/abstract_adapter.rb +77 -42
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +674 -0
- data/lib/active_record/connection_adapters/column.rb +37 -11
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +129 -581
- data/lib/active_record/connection_adapters/mysql_adapter.rb +137 -696
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +184 -86
- data/lib/active_record/connection_adapters/schema_cache.rb +50 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +2 -6
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +55 -32
- data/lib/active_record/counter_cache.rb +9 -4
- data/lib/active_record/dynamic_finder_match.rb +12 -0
- data/lib/active_record/dynamic_matchers.rb +84 -0
- data/lib/active_record/errors.rb +11 -1
- data/lib/active_record/explain.rb +85 -0
- data/lib/active_record/explain_subscriber.rb +25 -0
- data/lib/active_record/fixtures/file.rb +65 -0
- data/lib/active_record/fixtures.rb +56 -85
- data/lib/active_record/identity_map.rb +3 -4
- data/lib/active_record/inheritance.rb +174 -0
- data/lib/active_record/integration.rb +49 -0
- data/lib/active_record/locking/optimistic.rb +30 -25
- data/lib/active_record/locking/pessimistic.rb +23 -1
- data/lib/active_record/log_subscriber.rb +3 -3
- data/lib/active_record/migration/command_recorder.rb +8 -8
- data/lib/active_record/migration.rb +68 -35
- data/lib/active_record/model_schema.rb +366 -0
- data/lib/active_record/nested_attributes.rb +3 -2
- data/lib/active_record/persistence.rb +57 -11
- data/lib/active_record/querying.rb +58 -0
- data/lib/active_record/railtie.rb +31 -29
- data/lib/active_record/railties/controller_runtime.rb +3 -1
- data/lib/active_record/railties/databases.rake +191 -110
- data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
- data/lib/active_record/readonly_attributes.rb +26 -0
- data/lib/active_record/reflection.rb +7 -15
- data/lib/active_record/relation/batches.rb +5 -2
- data/lib/active_record/relation/calculations.rb +47 -15
- data/lib/active_record/relation/delegation.rb +49 -0
- data/lib/active_record/relation/finder_methods.rb +9 -7
- data/lib/active_record/relation/predicate_builder.rb +18 -7
- data/lib/active_record/relation/query_methods.rb +75 -9
- data/lib/active_record/relation/spawn_methods.rb +11 -2
- data/lib/active_record/relation.rb +78 -32
- data/lib/active_record/result.rb +1 -1
- data/lib/active_record/sanitization.rb +194 -0
- data/lib/active_record/schema_dumper.rb +12 -5
- data/lib/active_record/scoping/default.rb +142 -0
- data/lib/active_record/scoping/named.rb +202 -0
- data/lib/active_record/scoping.rb +152 -0
- data/lib/active_record/serialization.rb +1 -43
- data/lib/active_record/serializers/xml_serializer.rb +4 -45
- data/lib/active_record/session_store.rb +17 -15
- data/lib/active_record/store.rb +52 -0
- data/lib/active_record/test_case.rb +11 -7
- data/lib/active_record/timestamp.rb +17 -3
- data/lib/active_record/transactions.rb +27 -6
- data/lib/active_record/translation.rb +22 -0
- data/lib/active_record/validations/associated.rb +5 -4
- data/lib/active_record/validations/uniqueness.rb +7 -7
- data/lib/active_record/validations.rb +1 -1
- data/lib/active_record/version.rb +2 -2
- data/lib/active_record.rb +38 -3
- data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb +12 -3
- data/lib/rails/generators/active_record/model/model_generator.rb +9 -1
- data/lib/rails/generators/active_record/model/templates/migration.rb +3 -5
- data/lib/rails/generators/active_record/model/templates/model.rb +5 -0
- data/lib/rails/generators/active_record/session_migration/templates/migration.rb +1 -5
- metadata +30 -10
- data/lib/active_record/named_scope.rb +0 -200
data/CHANGELOG.md
CHANGED
|
@@ -1,525 +1,506 @@
|
|
|
1
|
-
## Rails 3.
|
|
1
|
+
## Rails 3.2.12 (unreleased) ##
|
|
2
2
|
|
|
3
|
-
*
|
|
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
|
-
|
|
7
|
+
Example:
|
|
6
8
|
|
|
7
|
-
*
|
|
9
|
+
App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
*Dylan Smith*
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
## Rails 3.2.11 (Jan 8, 2013) ##
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
* Fix querying with an empty hash *Damien Mathieu* [CVE-2013-0155]
|
|
14
16
|
|
|
15
|
-
|
|
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
|
-
|
|
19
|
+
* CVE-2012-5664 options hashes should only be extracted if there are extra
|
|
20
|
+
parameters
|
|
20
21
|
|
|
21
|
-
## Rails 3.
|
|
22
|
+
## Rails 3.2.9 (Nov 12, 2012) ##
|
|
22
23
|
|
|
23
|
-
* Fix
|
|
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
|
-
*
|
|
27
|
+
*Carlos Antonio da Silva*
|
|
26
28
|
|
|
27
|
-
*
|
|
29
|
+
* Fix bug when Column is trying to type cast boolean values to integer.
|
|
30
|
+
Fixes #8067.
|
|
28
31
|
|
|
29
|
-
*
|
|
30
|
-
Thanks to Ben Murphy for reporting this! CVE-2012-2661
|
|
32
|
+
*Rafael Mendonça França*
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
* Fix bug where `rake db:test:prepare` tries to load the structure.sql into development database.
|
|
35
|
+
Fixes #8032.
|
|
33
36
|
|
|
34
|
-
*
|
|
37
|
+
*Grace Liu + Rafael Mendonça França*
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
* Fixed support for `DATABASE_URL` environment variable for rake db tasks. *Grace Liu*
|
|
37
40
|
|
|
38
|
-
*
|
|
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
|
-
*
|
|
43
|
+
*Henrik Nyh*
|
|
42
44
|
|
|
43
|
-
*
|
|
44
|
-
where the calls are chained. *GH #3890*
|
|
45
|
+
* Decode URI encoded attributes on database connection URLs.
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
*Shawn Veader*
|
|
47
48
|
|
|
48
|
-
|
|
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
|
-
*
|
|
51
|
-
tables. *GH 3678*
|
|
52
|
+
*Christian Seiler*
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
* Synchronize around deleting from the reserved connections hash.
|
|
55
|
+
Fixes #7955
|
|
54
56
|
|
|
55
|
-
*
|
|
57
|
+
* PostgreSQL adapter correctly fetches default values when using
|
|
58
|
+
multiple schemas and domains in a db. Fixes #7914
|
|
56
59
|
|
|
57
|
-
*
|
|
60
|
+
*Arturo Pie*
|
|
58
61
|
|
|
59
|
-
|
|
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
|
-
*
|
|
62
|
-
to the query. *GH 3672*
|
|
66
|
+
*Ernie Miller*
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
* The postgres adapter now supports tables with capital letters.
|
|
69
|
+
Fix #5920
|
|
65
70
|
|
|
66
|
-
*
|
|
71
|
+
*Yves Senn*
|
|
67
72
|
|
|
68
|
-
*
|
|
73
|
+
* `CollectionAssociation#count` returns `0` without querying if the
|
|
74
|
+
parent record is not persisted.
|
|
69
75
|
|
|
70
|
-
|
|
76
|
+
Before:
|
|
71
77
|
|
|
72
|
-
|
|
78
|
+
person.pets.count
|
|
79
|
+
# SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
|
|
80
|
+
# => 0
|
|
73
81
|
|
|
74
|
-
|
|
75
|
-
*GH #3232*
|
|
82
|
+
After:
|
|
76
83
|
|
|
77
|
-
|
|
84
|
+
person.pets.count
|
|
85
|
+
# fires without sql query
|
|
86
|
+
# => 0
|
|
78
87
|
|
|
79
|
-
*
|
|
80
|
-
were not being stripped from the schema names after the first.
|
|
88
|
+
*Francesco Rodriguez*
|
|
81
89
|
|
|
82
|
-
|
|
90
|
+
* Fix `reset_counters` crashing on `has_many :through` associations.
|
|
91
|
+
Fix #7822.
|
|
83
92
|
|
|
84
|
-
*
|
|
93
|
+
*lulalala*
|
|
85
94
|
|
|
86
|
-
|
|
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
|
-
*
|
|
99
|
+
*jrochkind*
|
|
89
100
|
|
|
90
|
-
|
|
101
|
+
* Rename field_changed? to _field_changed? so that users can create a field named field
|
|
91
102
|
|
|
92
|
-
*
|
|
103
|
+
*Akira Matsuda*, backported by *Steve Klabnik*
|
|
93
104
|
|
|
94
|
-
|
|
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
|
-
*
|
|
109
|
+
*Ernie Miller*
|
|
97
110
|
|
|
98
|
-
|
|
111
|
+
* Explain only normal CRUD sql (select / update / insert / delete).
|
|
112
|
+
Fix problem that explains unexplainable sql. Closes #7544 #6458.
|
|
99
113
|
|
|
100
|
-
*
|
|
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
|
-
|
|
116
|
+
* Backport test coverage to ensure that PostgreSQL auto-reconnect functionality
|
|
117
|
+
remains healthy.
|
|
106
118
|
|
|
107
|
-
*
|
|
108
|
-
record should also be removed from the through association's target.
|
|
119
|
+
*Steve Jorgensen*
|
|
109
120
|
|
|
110
|
-
|
|
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
|
-
*
|
|
125
|
+
*kennyj*
|
|
113
126
|
|
|
114
|
-
|
|
127
|
+
* Fix ConnectionAdapters::Column.type_cast_code integer conversion,
|
|
128
|
+
to always convert values to integer calling #to_i. Fixes #7509.
|
|
115
129
|
|
|
116
|
-
*
|
|
130
|
+
*Thiago Pradi*
|
|
117
131
|
|
|
118
|
-
|
|
132
|
+
* Fix time column type casting for invalid time string values to correctly return nil.
|
|
119
133
|
|
|
120
|
-
*
|
|
121
|
-
*Kenny J*
|
|
134
|
+
*Adam Meehan*
|
|
122
135
|
|
|
123
|
-
|
|
136
|
+
* Fix `becomes` when using a configured `inheritance_column`.
|
|
124
137
|
|
|
125
|
-
*
|
|
126
|
-
but unknown. Fixes #3207.
|
|
138
|
+
*Yves Senn*
|
|
127
139
|
|
|
128
|
-
|
|
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
|
-
*
|
|
144
|
+
*Dave Desrochers*
|
|
131
145
|
|
|
132
|
-
|
|
146
|
+
* Round usec when comparing timestamp attributes in the dirty tracking.
|
|
147
|
+
Fixes #6975.
|
|
133
148
|
|
|
134
|
-
*
|
|
149
|
+
*kennyj*
|
|
135
150
|
|
|
136
|
-
|
|
151
|
+
* Use inversed parent for first and last child of has_many association.
|
|
137
152
|
|
|
138
|
-
*
|
|
139
|
-
\#2923.
|
|
153
|
+
*Ravil Bayramgalin*
|
|
140
154
|
|
|
141
|
-
|
|
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
|
-
*
|
|
159
|
+
*Ari Pollak*
|
|
144
160
|
|
|
145
|
-
|
|
161
|
+
* Fix `increment!`, `decrement!`, `toggle!` that was skipping callbacks.
|
|
162
|
+
Fixes #7306.
|
|
146
163
|
|
|
147
|
-
*
|
|
148
|
-
Fixes #3020.
|
|
164
|
+
*Rafael Mendonça França*
|
|
149
165
|
|
|
150
|
-
|
|
166
|
+
* Fix AR#create to return an unsaved record when AR::RecordInvalid is
|
|
167
|
+
raised. Fixes #3217.
|
|
151
168
|
|
|
152
|
-
*
|
|
169
|
+
*Dave Yeu*
|
|
153
170
|
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
*
|
|
174
|
+
*kennyj*
|
|
159
175
|
|
|
160
|
-
*
|
|
161
|
-
|
|
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
|
-
*
|
|
165
|
-
default scoped model in a nested through association. (GH #2834.) *Jon Leighton*
|
|
179
|
+
*Jeremy Walker*
|
|
166
180
|
|
|
167
|
-
*
|
|
168
|
-
|
|
181
|
+
* Remove prepared statement from system query in postgresql adapter.
|
|
182
|
+
Fix #5872.
|
|
169
183
|
|
|
170
|
-
*
|
|
184
|
+
*Ivan Evtuhovich*
|
|
171
185
|
|
|
172
|
-
*
|
|
173
|
-
|
|
186
|
+
* Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`
|
|
187
|
+
Fixes #4772.
|
|
174
188
|
|
|
175
|
-
*
|
|
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
|
-
|
|
181
|
-
GH #2731
|
|
192
|
+
## Rails 3.2.8 (Aug 9, 2012) ##
|
|
182
193
|
|
|
183
|
-
*
|
|
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
|
-
|
|
198
|
+
*Rafael Mendonça França*
|
|
186
199
|
|
|
187
|
-
*
|
|
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
|
-
|
|
202
|
+
* Reverted the deprecation of `composed_of`. *Rafael Mendonça França*
|
|
192
203
|
|
|
193
|
-
*
|
|
204
|
+
* Reverted the deprecation of `*_sql` association options. They will
|
|
205
|
+
be deprecated in 4.0 instead. *Jon Leighton*
|
|
194
206
|
|
|
195
|
-
*
|
|
196
|
-
|
|
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
|
-
|
|
199
|
-
Paul Battley for reporting.
|
|
212
|
+
*Xavier Noria*
|
|
200
213
|
|
|
201
|
-
|
|
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
|
-
*
|
|
218
|
+
*Rafael Mendonça França*
|
|
204
219
|
|
|
205
|
-
|
|
206
|
-
After: def build_association(*options, &block)
|
|
220
|
+
## Rails 3.2.7 (Jul 26, 2012) ##
|
|
207
221
|
|
|
208
|
-
|
|
209
|
-
|
|
222
|
+
* `:finder_sql` and `:counter_sql` options on collection associations
|
|
223
|
+
are deprecated. Please transition to using scopes.
|
|
210
224
|
|
|
211
|
-
|
|
225
|
+
*Jon Leighton*
|
|
212
226
|
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
221
|
-
self.pluralize_table_names = false
|
|
222
|
-
end
|
|
237
|
+
*Steve Klabnik*
|
|
223
238
|
|
|
224
|
-
|
|
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
|
-
*
|
|
243
|
+
*Steve Klabnik*
|
|
227
244
|
|
|
228
|
-
|
|
229
|
-
has_one :account
|
|
230
|
-
end
|
|
245
|
+
## Rails 3.2.6 (Jun 12, 2012) ##
|
|
231
246
|
|
|
232
|
-
|
|
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
|
-
|
|
251
|
+
CVE-2012-2695
|
|
235
252
|
|
|
236
|
-
*
|
|
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
|
-
*
|
|
261
|
+
*Jon Leighton*
|
|
239
262
|
|
|
240
|
-
|
|
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
|
-
|
|
245
|
-
|
|
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
|
-
|
|
268
|
+
*Andrew White*
|
|
250
269
|
|
|
251
|
-
assign_attributes() with similar API was also added and attributes=(params, guard) was deprecated.
|
|
252
270
|
|
|
253
|
-
|
|
271
|
+
## Rails 3.2.4 (May 31, 2012) ##
|
|
254
272
|
|
|
255
|
-
|
|
273
|
+
* Perf fix: Don't load the records when doing assoc.delete_all.
|
|
274
|
+
GH #6289. *Jon Leighton*
|
|
256
275
|
|
|
257
|
-
*
|
|
258
|
-
|
|
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
|
-
|
|
261
|
-
default_scope lambda { ... }
|
|
262
|
-
default_scope method(:foo)
|
|
280
|
+
* Datetime attributes are forced to be changed. GH #3965
|
|
263
281
|
|
|
264
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
273
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
296
|
+
* Update ActiveRecord::AttributeMethods#attribute_present? to return false for empty strings. *Jacobkg*
|
|
292
297
|
|
|
293
|
-
*
|
|
294
|
-
after the rack body has been flushed.
|
|
298
|
+
* Fix associations when using per class databases. *larskanis*
|
|
295
299
|
|
|
296
|
-
*
|
|
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
|
-
|
|
302
|
+
* Fix mysql to use proper text types. Fixes #3931. *kennyj*
|
|
302
303
|
|
|
303
|
-
|
|
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
|
-
|
|
307
|
+
## Rails 3.2.2 (March 1, 2012) ##
|
|
310
308
|
|
|
311
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
314
|
+
* The threshold for auto EXPLAIN is ignored if there's no logger. *fxn*
|
|
322
315
|
|
|
323
|
-
*
|
|
324
|
-
|
|
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
|
-
|
|
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
|
-
|
|
323
|
+
## Rails 3.2.0 (January 20, 2012) ##
|
|
334
324
|
|
|
335
|
-
*
|
|
336
|
-
|
|
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
|
-
|
|
339
|
-
has_many :taggings
|
|
340
|
-
has_many :tags, :through => :taggings
|
|
341
|
-
end
|
|
329
|
+
Before:
|
|
342
330
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
|
|
349
|
-
has_many :taggings
|
|
350
|
-
has_many :posts, :through => :taggings
|
|
351
|
-
end
|
|
340
|
+
After:
|
|
352
341
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
342
|
+
class Order < ActiveRecord::Base
|
|
343
|
+
def cancel!
|
|
344
|
+
with_lock do
|
|
345
|
+
# ... cancelling logic
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
end
|
|
356
349
|
|
|
357
|
-
*
|
|
350
|
+
*Olek Janiszewski*
|
|
358
351
|
|
|
359
|
-
*
|
|
360
|
-
|
|
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
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
not (necessarily) 'get rid of the associated records'.
|
|
359
|
+
Example:
|
|
360
|
+
rake db:migrate SCOPE=blog
|
|
370
361
|
|
|
371
|
-
|
|
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
|
-
|
|
375
|
-
|
|
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
|
-
|
|
379
|
-
|
|
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
|
-
|
|
370
|
+
* Implements automatic EXPLAIN logging for slow queries.
|
|
383
371
|
|
|
384
|
-
|
|
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
|
-
|
|
377
|
+
As of this writing there's support for SQLite, MySQL (mysql2 adapter), and
|
|
378
|
+
PostgreSQL.
|
|
387
379
|
|
|
388
|
-
|
|
380
|
+
*fxn*
|
|
389
381
|
|
|
390
|
-
|
|
391
|
-
t.string :company_name
|
|
392
|
-
t.change :birthdate, :datetime
|
|
393
|
-
end
|
|
382
|
+
* Implemented ActiveRecord::Relation#pluck method
|
|
394
383
|
|
|
395
|
-
|
|
384
|
+
Method returns Array of column value from table under ActiveRecord model
|
|
396
385
|
|
|
397
|
-
|
|
386
|
+
Client.pluck(:id)
|
|
398
387
|
|
|
399
|
-
*
|
|
400
|
-
documented as deprecated behaviour since April 2006. Please use has_many :through instead.
|
|
401
|
-
*Jon Leighton*
|
|
388
|
+
*Bogdan Gusiev*
|
|
402
389
|
|
|
403
|
-
*
|
|
390
|
+
* Automatic closure of connections in threads is deprecated. For example
|
|
391
|
+
the following code is deprecated:
|
|
404
392
|
|
|
405
|
-
|
|
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
|
-
|
|
410
|
-
|
|
395
|
+
It should be changed to close the database connection at the end of
|
|
396
|
+
the thread:
|
|
411
397
|
|
|
412
|
-
|
|
398
|
+
Thread.new {
|
|
399
|
+
Post.find(1)
|
|
400
|
+
Post.connection.close
|
|
401
|
+
}.join
|
|
413
402
|
|
|
414
|
-
|
|
403
|
+
Only people who spawn threads in their application code need to worry
|
|
404
|
+
about this change.
|
|
415
405
|
|
|
416
|
-
|
|
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
|
-
|
|
414
|
+
Use an assignment method instead. For example, instead of `set_table_name`, use `self.table_name=`:
|
|
419
415
|
|
|
420
|
-
|
|
421
|
-
|
|
416
|
+
class Project < ActiveRecord::Base
|
|
417
|
+
self.table_name = "project"
|
|
418
|
+
end
|
|
422
419
|
|
|
423
|
-
|
|
420
|
+
Or define your own `self.table_name` method:
|
|
424
421
|
|
|
425
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
434
|
-
class User < ActiveRecord::Base
|
|
435
|
-
has_secure_password
|
|
436
|
-
end
|
|
437
|
+
* Implemented ActiveRecord::Relation#explain. *fxn*
|
|
437
438
|
|
|
438
|
-
|
|
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
|
-
|
|
443
|
+
Client.select('DISTINCT name')
|
|
451
444
|
|
|
452
|
-
|
|
445
|
+
After:
|
|
453
446
|
|
|
454
|
-
|
|
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
|
-
|
|
449
|
+
This also allows you to revert the unqueness in a relation:
|
|
465
450
|
|
|
466
|
-
|
|
467
|
-
object. *#2989 state:resolved*
|
|
451
|
+
Client.select(:name).uniq.uniq(false)
|
|
468
452
|
|
|
469
|
-
*
|
|
470
|
-
to closer match normal Ruby dup and clone semantics.
|
|
453
|
+
*Jon Leighton*
|
|
471
454
|
|
|
472
|
-
*
|
|
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
|
-
*
|
|
476
|
-
|
|
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
|
-
|
|
481
|
-
|
|
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
|
-
|
|
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
|
-
|
|
494
|
-
|
|
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
|
-
*
|
|
499
|
-
|
|
500
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
508
|
-
of a single after_save. *fxn*
|
|
487
|
+
*Jeremy Kemper*
|
|
509
488
|
|
|
510
|
-
*
|
|
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
|
-
|
|
493
|
+
User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson")
|
|
513
494
|
|
|
514
|
-
|
|
495
|
+
*Andrés Mejía*
|
|
515
496
|
|
|
516
|
-
|
|
497
|
+
* Fix nested attributes bug where _destroy parameter is taken into account
|
|
498
|
+
during :reject_if => :all_blank (fixes #2937)
|
|
517
499
|
|
|
518
|
-
|
|
519
|
-
like this:
|
|
500
|
+
*Aaron Christy*
|
|
520
501
|
|
|
521
|
-
|
|
502
|
+
* Add ActiveSupport::Cache::NullStore for use in development and testing.
|
|
522
503
|
|
|
523
|
-
*
|
|
504
|
+
*Brian Durand*
|
|
524
505
|
|
|
525
|
-
Please check [3-
|
|
506
|
+
Please check [3-1-stable](https://github.com/rails/rails/blob/3-1-stable/activerecord/CHANGELOG.md) for previous changes.
|