activerecord 4.0.3 → 4.0.4.rc1

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +412 -0
  3. data/lib/active_record/associations.rb +2 -2
  4. data/lib/active_record/associations/association.rb +7 -2
  5. data/lib/active_record/associations/association_scope.rb +7 -2
  6. data/lib/active_record/associations/builder/belongs_to.rb +9 -3
  7. data/lib/active_record/associations/builder/singular_association.rb +1 -1
  8. data/lib/active_record/associations/collection_association.rb +1 -1
  9. data/lib/active_record/associations/collection_proxy.rb +1 -1
  10. data/lib/active_record/associations/has_many_through_association.rb +1 -1
  11. data/lib/active_record/associations/has_one_association.rb +4 -2
  12. data/lib/active_record/associations/singular_association.rb +1 -1
  13. data/lib/active_record/attribute_methods.rb +32 -15
  14. data/lib/active_record/attribute_methods/serialization.rb +10 -0
  15. data/lib/active_record/autosave_association.rb +8 -2
  16. data/lib/active_record/callbacks.rb +2 -2
  17. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -1
  18. data/lib/active_record/connection_adapters/abstract/database_statements.rb +14 -3
  19. data/lib/active_record/connection_adapters/abstract/quoting.rb +3 -1
  20. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +9 -9
  21. data/lib/active_record/connection_adapters/abstract/transaction.rb +4 -0
  22. data/lib/active_record/connection_adapters/abstract_adapter.rb +7 -0
  23. data/lib/active_record/connection_adapters/column.rb +11 -3
  24. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -1
  25. data/lib/active_record/connection_adapters/mysql_adapter.rb +2 -2
  26. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +3 -2
  27. data/lib/active_record/connection_adapters/postgresql/cast.rb +12 -8
  28. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +2 -2
  29. data/lib/active_record/connection_adapters/postgresql/quoting.rb +1 -1
  30. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +13 -0
  31. data/lib/active_record/connection_adapters/postgresql_adapter.rb +20 -15
  32. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +7 -3
  33. data/lib/active_record/core.rb +17 -9
  34. data/lib/active_record/counter_cache.rb +1 -1
  35. data/lib/active_record/dynamic_matchers.rb +7 -2
  36. data/lib/active_record/inheritance.rb +15 -7
  37. data/lib/active_record/locking/pessimistic.rb +3 -3
  38. data/lib/active_record/migration.rb +10 -6
  39. data/lib/active_record/migration/command_recorder.rb +12 -5
  40. data/lib/active_record/persistence.rb +7 -6
  41. data/lib/active_record/railties/databases.rake +4 -5
  42. data/lib/active_record/relation/batches.rb +2 -5
  43. data/lib/active_record/relation/calculations.rb +3 -1
  44. data/lib/active_record/relation/finder_methods.rb +6 -5
  45. data/lib/active_record/relation/merger.rb +18 -2
  46. data/lib/active_record/relation/query_methods.rb +5 -6
  47. data/lib/active_record/sanitization.rb +6 -3
  48. data/lib/active_record/store.rb +1 -1
  49. data/lib/active_record/tasks/mysql_database_tasks.rb +2 -1
  50. data/lib/active_record/tasks/postgresql_database_tasks.rb +1 -1
  51. data/lib/active_record/timestamp.rb +2 -2
  52. data/lib/active_record/transactions.rb +7 -3
  53. data/lib/active_record/validations/presence.rb +1 -1
  54. data/lib/active_record/validations/uniqueness.rb +13 -5
  55. data/lib/active_record/version.rb +1 -1
  56. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6db6e96ad6545b979c2f76d92bce1f6062e5f3b7
4
- data.tar.gz: d8195989b1dc14af19653ff60158301d1bacb0d9
3
+ metadata.gz: 8d61ddb97baf7a76460c7ccde98f0b6697fef69e
4
+ data.tar.gz: 5231097ee413082d2d8070067b837f5971ef651b
5
5
  SHA512:
6
- metadata.gz: ac29a96f859a590c33dfdcd670342b133a4871f1db0b19c5d3c31b6fe0ca3e54b97aef90995a0b8d32e71028bcdfb1abdeb4b2d3a5ae8af94eeb6c80ab127424
7
- data.tar.gz: 11b902aa9480022875b6e268f7819b5af03e8fa99009d342aa1348924bfaf829f730cd916330c0e5e707c4cd478f841ef56a75093b8c020d829c90d2b60b1381
6
+ metadata.gz: 9383667f82e9d122da7073559dd03af930e0fd890a606536c7d8af5393c810fbc216e5edb9a8dd53c061f4b0725ea83fd54cb730493569ddca222b1322044450
7
+ data.tar.gz: 8f8e3aab398e7d3da678e26934736cef358d9979f6b374800f5524abfc3a0e81053f651aead561ff0d36a030b6fac14252c646fbd882a1940a20a2ff44a54d97
@@ -1,3 +1,415 @@
1
+ ## Rails 4.0.4 ##
2
+
3
+ * Only save has_one associations if record has changes.
4
+ Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
5
+ object did not get saved to the db.
6
+
7
+ *Alan Kennedy*
8
+
9
+ * Fixed STI classes not defining an attribute method if there is a
10
+ conflicting private method defined on its ancestors.
11
+
12
+ Fixes #11569.
13
+
14
+ *Godfrey Chan*
15
+
16
+ * Fix validation on uniqueness of empty association.
17
+
18
+ *Evgeny Li*
19
+
20
+ * Perform necessary deeper encoding when hstore is inside an array.
21
+
22
+ Fixes #11135.
23
+
24
+ *Josh Goodall*, *Genadi Samokovarov*
25
+
26
+ * Properly detect if a connection is still active before using it
27
+ in multi-threaded environments.
28
+
29
+ Fixes #12867.
30
+
31
+ *Kevin Casey*, *Matthew Draper*, *William (B.J.) Snow Orvis*
32
+
33
+ * When inverting add_index use the index name if present instead of
34
+ the columns.
35
+
36
+ If there are two indices with matching columns and one of them is
37
+ explicitly named then reverting the migration adding the named one
38
+ would instead drop the unnamed one.
39
+
40
+ The inversion of add_index will now drop the index by its name if
41
+ it is present.
42
+
43
+ *Hubert Dąbrowski*
44
+
45
+ * Make sure transaction state gets reset after a commit operation on the record.
46
+
47
+ If a new transaction was open inside a callback, the record was loosing track
48
+ of the transaction level state, and it was leaking that state.
49
+
50
+ Fixes #12566.
51
+
52
+ *arthurnn*
53
+
54
+ * PostgreSQL implementation of `SchemaStatements#index_name_exists?`.
55
+
56
+ The database agnostic implementation does not detect with indexes that are
57
+ not supported by the ActiveRecord schema dumper. For example, expressions
58
+ indexes would not be detected.
59
+
60
+ Fixes #11018.
61
+
62
+ *Jonathan Baudanza*
63
+
64
+ * Parsing PostgreSQL arrays with empty strings now works correctly.
65
+
66
+ Previously, if you tried to parse `{"1","","2","","3"}` the result
67
+ would be `["1","2","3"]`, removing the empty strings from the array,
68
+ which would be incorrect. Now it will correctly produce `["1","","2","","3"]`
69
+ as the result of parsing the above PostgreSQL array.
70
+
71
+ Fixes #13907.
72
+
73
+ *Maurício Linhares*
74
+
75
+ * Fix regressions on `select_*` methods.
76
+ When `select_*` methods receive a `Relation` object, they should be able to get the arel/binds from it.
77
+ Also fix regressions on select_rows that was ignoring the binds.
78
+
79
+ Fixes #7538, #12017, #13731, #12056.
80
+
81
+ *arthurnn*
82
+
83
+ * Correctly send an user provided statement to a `lock!()` call.
84
+
85
+ person.lock! 'FOR SHARE NOWAIT'
86
+ # Before: SELECT * ... LIMIT 1 FOR UPDATE
87
+ # After: SELECT * ... LIMIT 1 FOR SHARE NOWAIT
88
+
89
+ Fixes #13788.
90
+
91
+ *Maurício Linhares*
92
+
93
+ * Active Record objects can now be correctly dumped, loaded and dumped again without issues.
94
+
95
+ Previously, if you did `YAML.dump`, `YAML.load` and then `YAML.dump` again
96
+ in an ActiveRecord model that used serialization it would fail at the last
97
+ dump due to the fields not being correctly serialized before being dumped
98
+ to YAML. Now it is possible to dump and load the same object as many times
99
+ as needed without any issues.
100
+
101
+ Fixes #13861.
102
+
103
+ *Maurício Linhares*
104
+
105
+ * `has_one` and `belongs_to` accessors don't add ORDER BY to the queries anymore.
106
+
107
+ Since Rails 4.0, we add an ORDER BY in the `first` method to ensure consistent results
108
+ among different database engines. But for singular associations this behavior is not needed
109
+ since we will have one record to return. As this ORDER BY option can lead some performance
110
+ issues we are removing it for singular associations accessors.
111
+
112
+ Fixes #12623.
113
+
114
+ *Rafael Mendonça França*
115
+
116
+ * Fail early with "Primary key not included in the custom select clause"
117
+ in `find_in_batches`.
118
+
119
+ Before this patch, the exception was raised after the first batch was
120
+ yielded to the block. This means that you only get it, when you hit the
121
+ `batch_size` treshold. This could shadow the issue in development.
122
+
123
+ *Alexander Balashov*
124
+
125
+ * ActiveRecord states are now correctly restored after a rollback for
126
+ models that did not define any transactional callbacks (i.e.
127
+ `after_commit`, `after_rollback` or `after_create`).
128
+
129
+ Fixes #13744.
130
+
131
+ *Godfrey Chan*
132
+
133
+ * Add back `#yaml_initialize` method for Syck deserialization
134
+
135
+ `ActiveRecord::Core#yaml_initialize` has been added back to support deserialization using
136
+ the Syck engine. This is to facilitate migration from Syck to Psych. Serialization support
137
+ will not been restored for Syck, Psych should be used to serialize YAML once its been
138
+ parsed with Syck.
139
+
140
+ *Blake Mesdag*, *arthurnn*
141
+
142
+ * Make `touch` fire the `after_commit` and `after_rollback` callbacks.
143
+
144
+ *Harry Brundage*
145
+
146
+ * Don't try to get the subclass if the inheritance column doesn't exist
147
+
148
+ The `subclass_from_attrs` method is called even if the column specified by
149
+ the `inheritance_column` setting doesn't exist. This prevents setting associations
150
+ via the attributes hash if the association name clashes with the value of the setting,
151
+ typically `:type`. This worked previously in Rails 3.2.
152
+
153
+ *Ujjwal Thaakar*
154
+
155
+ * Fix bug in `becomes!` when changing from the base model to a STI sub-class.
156
+
157
+ Fixes #13272.
158
+
159
+ *the-web-dev*, *Yves Senn*
160
+
161
+ * Initialize version on Migration objects so that it can be used in a migration,
162
+ and it will be included in the announce message.
163
+
164
+ *Dylan Thacker-Smith*
165
+
166
+ * `change_table` now uses the current adapter's `update_table_definition`
167
+ method to retrieve a specific table definition.
168
+ This ensures that `change_table` and `create_table` will use
169
+ similar objects.
170
+
171
+ Fixes #13577 and #13503.
172
+
173
+ *Nishant Modak*, *Prathamesh Sonpatki*, *Rafael Mendonça França*
174
+
175
+ * Fixed ActiveRecord::Store nil conversion TypeError when using YAML coder.
176
+ In case the YAML passed as paramter is nil, uses an empty string.
177
+
178
+ Fixes #13570.
179
+
180
+ *Thales Oliveira*
181
+
182
+ * Fix presence validator for association when the associated record responds to `to_a`.
183
+
184
+ *gmarik*
185
+
186
+ * Fix bug in `belongs_to` association with `touch: true`.
187
+ Associated records are no longer touched, when they are already destroyed.
188
+
189
+ Fixes #13445.
190
+
191
+ Example:
192
+
193
+ # Given Comment has belongs_to :post, touch: true
194
+ comment.post.destroy
195
+ comment.destroy # no longer touches post
196
+
197
+ *Paul Nikitochkin*
198
+
199
+ * Fixed `update_column`, `update_columns`, and `update_all` to correctly serialize
200
+ values for `array`, `hstore` and `json` column types in PostgreSQL.
201
+
202
+ Fixes #12261.
203
+
204
+ *Tadas Tamosauskas*, *Carlos Antonio da Silva*
205
+
206
+ * Do not consider PostgreSQL array columns as number or text columns.
207
+
208
+ The code uses these checks in several places to know what to do with a
209
+ particular column, for instance AR attribute query methods has a branch
210
+ like this:
211
+
212
+ if column.number?
213
+ !value.zero?
214
+ end
215
+
216
+ This should never be true for array columns, since it would be the same
217
+ as running [].zero?, which results in a NoMethodError exception.
218
+
219
+ Fixing this by ensuring that array columns in PostgreSQL never return
220
+ true for number?/text? checks.
221
+
222
+ *Carlos Antonio da Silva*
223
+
224
+ * Fix a bug when assigning an array containing string numbers to a
225
+ PostgreSQL integer array column.
226
+
227
+ Fixes #13444.
228
+
229
+ Example:
230
+
231
+ # Given Book#ratings is of type :integer, array: true
232
+ Book.new(ratings: [1, 2]) # worked before
233
+ Book.new(ratings: ['1', '2']) # now works as well
234
+
235
+ *Damien Mathieu*
236
+
237
+ * `db:test:clone` and `db:test:prepare` must load Rails environment.
238
+
239
+ `db:test:clone` and `db:test:prepare` use `ActiveRecord::Base`. configurations,
240
+ so we need to load the Rails environment, otherwise the config wont be in place.
241
+
242
+ *arthurnn*
243
+
244
+ * Use the right column to type cast grouped calculations with custom expressions.
245
+
246
+ Fixes #13230.
247
+
248
+ Example:
249
+
250
+ # Before
251
+ Account.group(:firm_name).sum('0.01 * credit_limit')
252
+ # => { '37signals' => '0.5' }
253
+
254
+ # After
255
+ Account.group(:firm_name).sum('0.01 * credit_limit')
256
+ # => { '37signals' => 0.5 }
257
+
258
+ *Paul Nikitochkin*
259
+
260
+ * Support deprecated finder options when performing calculations
261
+ on an association.
262
+
263
+ Fixes #13165.
264
+
265
+ *Garth Smedley*, *Yves Senn*
266
+
267
+ * `ActiveRecord::ConnectionAdapters.string_to_time` respects
268
+ string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
269
+
270
+ Fixes #12278, #12459.
271
+
272
+ *kennyj*, *George Guimarães*
273
+
274
+ * Polymorphic `belongs_to` associations with the `touch: true` option set update the timestamps of
275
+ the old and new owner correctly when moved between owners of different types.
276
+
277
+ Example:
278
+
279
+ class Rating < ActiveRecord::Base
280
+ belongs_to :rateable, polymorphic: true, touch: true
281
+ end
282
+
283
+ rating = Rating.create rateable: Song.find(1)
284
+ rating.update_attributes rateable: Book.find(2) # => timestamps of Song(1) and Book(2) are updated
285
+
286
+ *Severin Schoepke*
287
+
288
+ * `type_to_sql` returns a `String` for unmapped columns. This fixes an error
289
+ when using unmapped array types in combination with PostgreSQL's `array: true`.
290
+
291
+ Fixes #13146.
292
+
293
+ Example:
294
+
295
+ change_colum :table, :column, :bigint, array: true
296
+
297
+ *Jens Fahnenbruck*, *Yves Senn*
298
+
299
+ * Previously, the `has_one` macro incorrectly accepts the `counter_cache`
300
+ option due to a bug, although that options was never supported nor
301
+ functional on `has_one` and `has_one ... through` relationships. It now
302
+ correctly raises an `ArgumentError` when passed that option.
303
+
304
+ *Godfrey Chan*
305
+
306
+ * Update counter cache on a has_many relationship regardless of default scope
307
+
308
+ Fix #12952.
309
+
310
+ *Uku Taht*
311
+
312
+ * Fix bug when validating the uniqueness of an aliased attribute.
313
+
314
+ Fixes #12402.
315
+
316
+ *Lauro Caetano*
317
+
318
+ * Checks to see if the record contains the foreign key to set the inverse automatically.
319
+
320
+ *Edo Balvers*
321
+
322
+ * Prevent the counter cache from being decremented twice when destroying
323
+ a record on a has_many :through association.
324
+
325
+ Fixes #11079.
326
+
327
+ *Dmitry Dedov*
328
+
329
+ * Fix bug where has_one associaton record update result in crash, when replaced with itself.
330
+
331
+ Fixes #12834.
332
+
333
+ *Denis Redozubov*, *Sergio Cambra*
334
+
335
+ * Fix uninitialized constant TransactionState error when Marshall.load is used on an Active Record result.
336
+
337
+ Fixes #12790.
338
+
339
+ *Jason Ayre*
340
+
341
+ * Do not add to scope includes values from through associations.
342
+ Fixed bug when providing `includes` in through association scope, and fetching targets.
343
+
344
+ Example:
345
+ class Vendor < ActiveRecord::Base
346
+ has_many :relationships, -> { includes(:user) }
347
+ has_many :users, through: :relationships
348
+ end
349
+
350
+ vendor = Vendor.first
351
+
352
+ # Before
353
+
354
+ vendor.users.to_a # => Raises exception: not found `:user` for `User`
355
+
356
+ # After
357
+
358
+ vendor.users.to_a # => No exception is raised
359
+
360
+
361
+ Fixes #12242, #9517, #10240.
362
+
363
+ *Paul Nikitochkin*
364
+
365
+ * Save `has_one` association when primary key is manually set.
366
+
367
+ Fixes #12302.
368
+
369
+ *Lauro Caetano*
370
+
371
+ * Allow any version of BCrypt when using `has_secury_password`.
372
+
373
+ *Mike Perham*
374
+
375
+ * Assign inet/cidr attribute with `nil` value for invalid address.
376
+
377
+ Example:
378
+
379
+ record = User.new
380
+
381
+ record.logged_in_from_ip # is type of an inet or a cidr
382
+
383
+ # Before:
384
+ record.logged_in_from_ip = 'bad ip address' # raise exception
385
+
386
+ # After:
387
+ record.logged_in_from_ip = 'bad ip address' # do not raise exception
388
+ record.logged_in_from_ip # => nil
389
+ record.logged_in_from_ip_before_type_cast # => 'bad ip address'
390
+
391
+ *Paul Nikitochkin*
392
+
393
+ * `rake db:structure:dump` no longer crashes when the port was specified as `Fixnum`.
394
+
395
+ *Kenta Okamoto*
396
+
397
+ * Fix a bug where rake db:structure:load crashed when the path contained
398
+ spaces.
399
+
400
+ *Kevin Mook*
401
+
402
+ * `ActiveRecord::QueryMethods#unscope` unscopes negative equality
403
+
404
+ Allows you to call `#unscope` on a relation with negative equality
405
+ operators, i.e. `Arel::Nodes::NotIn` and `Arel::Nodes::NotEqual` that have
406
+ been generated through the use of `where.not`.
407
+
408
+ *Eric Hankins*
409
+
410
+
411
+ ## Rails 4.0.3 (February 18, 2014) ##
412
+
1
413
  * Correctly escape PostgreSQL arrays.
2
414
 
3
415
  Fixes: CVE-2014-0080
@@ -657,8 +657,8 @@ module ActiveRecord
657
657
  # class Asset < ActiveRecord::Base
658
658
  # belongs_to :attachable, polymorphic: true
659
659
  #
660
- # def attachable_type=(sType)
661
- # super(sType.to_s.classify.constantize.base_class.to_s)
660
+ # def attachable_type=(klass)
661
+ # super(klass.to_s.classify.constantize.base_class.to_s)
662
662
  # end
663
663
  # end
664
664
  #
@@ -70,7 +70,7 @@ module ActiveRecord
70
70
  # The target is stale if the target no longer points to the record(s) that the
71
71
  # relevant foreign_key(s) refers to. If stale, the association accessor method
72
72
  # on the owner will reload the target. It's up to subclasses to implement the
73
- # state_state method if relevant.
73
+ # stale_state method if relevant.
74
74
  #
75
75
  # Note that if the target has not been loaded, it is not considered stale.
76
76
  def stale_target?
@@ -235,7 +235,12 @@ module ActiveRecord
235
235
  # Returns true if inverse association on the given record needs to be set.
236
236
  # This method is redefined by subclasses.
237
237
  def invertible_for?(record)
238
- inverse_reflection_for(record)
238
+ foreign_key_for?(record) && inverse_reflection_for(record)
239
+ end
240
+
241
+ # Returns true if record contains the foreign_key
242
+ def foreign_key_for?(record)
243
+ record.has_attribute?(reflection.foreign_key)
239
244
  end
240
245
 
241
246
  # This should be implemented to return the values of the relevant key(s) on the owner,