activerecord 4.0.0 → 4.0.1.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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +326 -3
  3. data/README.rdoc +1 -1
  4. data/lib/active_record.rb +1 -0
  5. data/lib/active_record/association_relation.rb +18 -0
  6. data/lib/active_record/associations/association.rb +11 -3
  7. data/lib/active_record/associations/builder/belongs_to.rb +4 -2
  8. data/lib/active_record/associations/collection_association.rb +8 -8
  9. data/lib/active_record/associations/collection_proxy.rb +2 -4
  10. data/lib/active_record/associations/has_many_association.rb +2 -2
  11. data/lib/active_record/associations/has_one_association.rb +3 -1
  12. data/lib/active_record/associations/join_dependency/join_association.rb +2 -0
  13. data/lib/active_record/associations/join_dependency/join_part.rb +14 -1
  14. data/lib/active_record/associations/preloader.rb +3 -2
  15. data/lib/active_record/attribute_methods.rb +26 -2
  16. data/lib/active_record/attribute_methods/read.rb +15 -9
  17. data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
  18. data/lib/active_record/attribute_methods/write.rb +2 -0
  19. data/lib/active_record/autosave_association.rb +8 -8
  20. data/lib/active_record/callbacks.rb +4 -1
  21. data/lib/active_record/connection_adapters/abstract/database_statements.rb +7 -7
  22. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +12 -3
  23. data/lib/active_record/connection_adapters/abstract_adapter.rb +16 -2
  24. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +3 -1
  25. data/lib/active_record/connection_adapters/column.rb +12 -11
  26. data/lib/active_record/connection_adapters/mysql2_adapter.rb +9 -3
  27. data/lib/active_record/connection_adapters/mysql_adapter.rb +19 -9
  28. data/lib/active_record/connection_adapters/postgresql/cast.rb +1 -1
  29. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +7 -6
  30. data/lib/active_record/connection_adapters/postgresql/oid.rb +5 -0
  31. data/lib/active_record/connection_adapters/postgresql/quoting.rb +2 -0
  32. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +7 -10
  33. data/lib/active_record/connection_adapters/postgresql_adapter.rb +19 -13
  34. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +8 -5
  35. data/lib/active_record/core.rb +18 -18
  36. data/lib/active_record/dynamic_matchers.rb +1 -1
  37. data/lib/active_record/fixtures.rb +2 -2
  38. data/lib/active_record/locking/optimistic.rb +1 -1
  39. data/lib/active_record/migration.rb +1 -1
  40. data/lib/active_record/migration/command_recorder.rb +4 -1
  41. data/lib/active_record/model_schema.rb +27 -17
  42. data/lib/active_record/null_relation.rb +1 -5
  43. data/lib/active_record/persistence.rb +16 -5
  44. data/lib/active_record/railtie.rb +1 -0
  45. data/lib/active_record/railties/databases.rake +4 -1
  46. data/lib/active_record/reflection.rb +1 -1
  47. data/lib/active_record/relation.rb +1 -1
  48. data/lib/active_record/relation/batches.rb +2 -2
  49. data/lib/active_record/relation/calculations.rb +1 -0
  50. data/lib/active_record/relation/finder_methods.rb +10 -10
  51. data/lib/active_record/relation/merger.rb +31 -28
  52. data/lib/active_record/relation/query_methods.rb +13 -11
  53. data/lib/active_record/result.rb +15 -1
  54. data/lib/active_record/sanitization.rb +13 -3
  55. data/lib/active_record/schema_dumper.rb +5 -1
  56. data/lib/active_record/tasks/database_tasks.rb +2 -1
  57. data/lib/active_record/tasks/sqlite_database_tasks.rb +1 -1
  58. data/lib/active_record/transactions.rb +5 -5
  59. data/lib/active_record/validations/uniqueness.rb +2 -2
  60. data/lib/active_record/version.rb +1 -1
  61. metadata +10 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76ddb57b66b29722a983d38eba75ebc3e94610ea
4
- data.tar.gz: 743a630e5e1722c2655ca8c167dbb5be2ab49afb
3
+ metadata.gz: 8d1fd9865b3fb6273381e9e80a0d91873fbf3416
4
+ data.tar.gz: ca2daac77b93bd70b4bf2575a38fdec785e2cd08
5
5
  SHA512:
6
- metadata.gz: a643a5988de90b3145ab259ecc0f20acba5e66db188ad8ebfbdd12e14352e26d696faf570cc04c2da30e70bc1a490d9107cb4086f59b90614088941c96f095e3
7
- data.tar.gz: 513f56748c0e72bc073a068f29846737aeb95c11fd3fc23672295027a6d475c2764613f3b1653cdb8d32ac61b4dfcff32cade6279fad13ad4030bd1e01e536b0
6
+ metadata.gz: 86a8645f43b690acd7a646fed38fe923bf12de401fc62bee0bf2ec17c80ad76d13ce88ec4f6ac07149febd08f2c9dedb25afb8b9057c94ae443566598c6c82e0
7
+ data.tar.gz: c95f79b406c8d5453a19f7867283a1dab8799de4a3cb374f8cad1ba4a8bb3e29a21c52d4a9afbb6251f625e1f671d654c4d5808fef4086deb616358bdfb47216
@@ -1,3 +1,328 @@
1
+ ## Rails 4.0.1.rc1 (October 17, 2013) ##
2
+
3
+ * `NullRelation#pluck` takes a list of columns
4
+
5
+ The method signature in `NullRelation` was updated to mimic that in
6
+ `Calculations`.
7
+
8
+ *Derek Prior*
9
+
10
+ * `scope_chain` should not be mutated for other reflections.
11
+
12
+ Currently `scope_chain` uses same array for building different
13
+ `scope_chain` for different associations. During processing
14
+ these arrays are sometimes mutated and because of in-place
15
+ mutation the changed `scope_chain` impacts other reflections.
16
+
17
+ Fix is to dup the value before adding to the `scope_chain`.
18
+
19
+ Fixes #3882.
20
+
21
+ *Neeraj Singh*
22
+
23
+ * Prevent the inversed association from being reloaded on save.
24
+
25
+ Fixes #9499.
26
+
27
+ *Dmitry Polushkin*
28
+
29
+ * `Relation#order` quotes the column name if you pass a `Symbol`.
30
+ Fixes #11870.
31
+
32
+ Example:
33
+
34
+ # Before
35
+ Post.order(:id).to_sql == '... ORDER BY "posts".id ASC'
36
+
37
+ # After
38
+ Post.order(:id).to_sql == '... ORDER BY "posts"."id" ASC'
39
+
40
+ *Yves Senn*
41
+
42
+ * Generate subquery for `Relation` if it passed as array condition for `where`
43
+ method.
44
+
45
+ Example:
46
+
47
+ # Before
48
+ Blog.where('id in (?)', Blog.where(id: 1))
49
+ # => SELECT "blogs".* FROM "blogs" WHERE "blogs"."id" = 1
50
+ # => SELECT "blogs".* FROM "blogs" WHERE (id IN (1))
51
+
52
+ # After
53
+ Blog.where('id in (?)', Blog.where(id: 1).select(:id))
54
+ # => SELECT "blogs".* FROM "blogs"
55
+ # WHERE "blogs"."id" IN (SELECT "blogs"."id" FROM "blogs" WHERE "blogs"."id" = 1)
56
+
57
+ Fixes #12415.
58
+
59
+ *Paul Nikitochkin*
60
+
61
+ * For missed association exception message
62
+ which is raised in `ActiveRecord::Associations::Preloader` class
63
+ added owner record class name in order to simplify to find problem code.
64
+
65
+ *Paul Nikitochkin*
66
+
67
+ * Fixes bug when using includes combined with select, the select statement was overwritten.
68
+
69
+ Fixes #11773.
70
+
71
+ *Edo Balvers*
72
+
73
+ * Objects instantiated using a null relationship will now retain the
74
+ attributes of the where clause.
75
+
76
+ Fixes #11676, #11675, #11376.
77
+
78
+ *Paul Nikitochkin*, *Peter Brown*, *Nthalk*
79
+
80
+ * Fixed `ActiveRecord::Associations::CollectionAssociation#find`
81
+ when using `has_many` association with `:inverse_of` and finding an array of one element,
82
+ it should return an array of one element too.
83
+
84
+ *arthurnn*
85
+
86
+ * Callbacks on has_many should access the in memory parent if a inverse_of is set.
87
+
88
+ *arthurnn*
89
+
90
+ * Migration dump UUID default functions to schema.rb.
91
+
92
+ Fixes #10751.
93
+
94
+ *kennyj*
95
+
96
+ * Fixed a bug in `ActiveRecord::Associations::CollectionAssociation#find_by_scan`
97
+ when using `has_many` association with `:inverse_of` option and UUID primary key.
98
+
99
+ Fixes #10450.
100
+
101
+ *kennyj*
102
+
103
+ * Fix: joins association, with defined in the scope block constraints by using several
104
+ where constraints and at least of them is not `Arel::Nodes::Equality`,
105
+ generates invalid SQL expression.
106
+
107
+ Fixes: #11963
108
+
109
+ *Paul Nikitochkin*
110
+
111
+ * Make possible to run SQLite rake tasks without the `Rails` constant defined.
112
+
113
+ *Damien Mathieu*
114
+
115
+ * Allow Relation#from to accept other relations with bind values.
116
+
117
+ *Ryan Wallace*
118
+
119
+ * Make `find_in_batches` and `find_each` work without a logger.
120
+
121
+ *Dmitry Polushkin*
122
+
123
+ * Fix inserts with prepared statements disabled.
124
+
125
+ Fixes #12023.
126
+
127
+ *Rafael Mendonça França*
128
+
129
+ * Setting a has_one association on a new record no longer causes an empty
130
+ transaction.
131
+
132
+ *Dylan Thacker-Smith*
133
+
134
+ * Fix `AR::Relation#merge` sometimes failing to preserve `readonly(false)` flag.
135
+
136
+ *thedarkone*
137
+
138
+ * PostgreSQL adapter recognizes negative money values formatted with
139
+ parentheses (eg. `($1.25) # => -1.25`)).
140
+ Fixes #11899.
141
+
142
+ * Yves Senn*
143
+
144
+ * Do not load all child records for inverse case.
145
+
146
+ currently `post.comments.find(Comment.first.id)` would load all
147
+ comments for the given post to set the inverse association.
148
+
149
+ This has a huge performance penalty. Because if post has 100k
150
+ records and all these 100k records would be loaded in memory
151
+ even though the comment id was supplied.
152
+
153
+ Fix is to use in-memory records only if loaded? is true. Otherwise
154
+ load the records using full sql.
155
+
156
+ Fixes #10509.
157
+
158
+ *Neeraj Singh*
159
+
160
+ * `ActiveRecord::FinderMethods#exists?` returns `true`/`false` in all cases.
161
+
162
+ *Xavier Noria*
163
+
164
+ * Load fixtures from linked folders.
165
+
166
+ *Kassio Borges*
167
+
168
+ * Create a directory for sqlite3 file if not present on the system.
169
+
170
+ *Richard Schneeman*
171
+
172
+ * Removed redundant override of `xml` column definition for PG,
173
+ in order to use `xml` column type instead of `text`.
174
+
175
+ *Paul Nikitochkin*, *Michael Nikitochkin*
176
+
177
+ * Revert `ActiveRecord::Relation#order` change that make new order
178
+ prepend the old one.
179
+
180
+ Before:
181
+
182
+ User.order("name asc").order("created_at desc")
183
+ # SELECT * FROM users ORDER BY created_at desc, name asc
184
+
185
+ After:
186
+
187
+ User.order("name asc").order("created_at desc")
188
+ # SELECT * FROM users ORDER BY name asc, created_at desc
189
+
190
+ This also affects order defined in `default_scope` or any kind of associations.
191
+
192
+ *Rafael Mendonça França*
193
+
194
+ * When using optimistic locking, `update` was not passing the column to `quote_value`
195
+ to allow the connection adapter to properly determine how to quote the value. This was
196
+ affecting certain databases that use specific column types.
197
+
198
+ Fixes #6763.
199
+
200
+ *Alfred Wong*
201
+
202
+ * `change_column` for PostgreSQL adapter respects the `:array` option.
203
+
204
+ *Yves Senn*
205
+
206
+ * Fixes bug introduced by #3329. Now, when autosaving associations,
207
+ deletions happen before inserts and saves. This prevents a
208
+ 'duplicate unique value' database error that would occur if a record being created had
209
+ the same value on a unique indexed field as that of a record being destroyed.
210
+
211
+ *Johnny Holton*
212
+
213
+ * Flatten merged join values before building the joins.
214
+
215
+ While joining values special treatment is given to string values.
216
+ By flattening the array it ensures that string values are detected
217
+ as strings and not arrays.
218
+
219
+ Fixes #10669.
220
+
221
+ *Neeraj Singh and iwiznia*
222
+
223
+ * Remove extra select and update queries on `save`/`touch`/`destroy` Active Record model
224
+ with belongs to reflection with option `touch: true`.
225
+
226
+ Fixes #11288.
227
+
228
+ *Paul Nikitochkin*
229
+
230
+ * Support array as root element in JSON fields.
231
+
232
+ *Alexey Noskov & Francesco Rodriguez*
233
+
234
+ * Apply default scope when joining associations. For example:
235
+
236
+ class Post < ActiveRecord::Base
237
+ default_scope -> { where published: true }
238
+ end
239
+
240
+ class Comment
241
+ belongs_to :post
242
+ end
243
+
244
+ When calling `Comment.joins(:post)`, we expect to receive only
245
+ comments on published posts, since that is the default scope for
246
+ posts.
247
+
248
+ Before this change, the default scope from `Post` was not applied,
249
+ so we'd get comments on unpublished posts.
250
+
251
+ *Jon Leighton*
252
+
253
+ * `inspect` on Active Record model classes does not initiate a
254
+ new connection. This means that calling `inspect`, when the
255
+ database is missing, will no longer raise an exception.
256
+
257
+ Fixes #10936.
258
+
259
+ Example:
260
+
261
+ Author.inspect # => "Author(no database connection)"
262
+
263
+ *Yves Senn*
264
+
265
+ * Fix mysql2 adapter raises the correct exception when executing a query on a
266
+ closed connection.
267
+
268
+ *Yves Senn*
269
+
270
+ * Fix the `:primary_key` option for `has_many` associations.
271
+
272
+ Fixes #10693.
273
+
274
+ *Yves Senn*
275
+
276
+ * Fix bug where tiny types are incorectly coerced as booleand when the length is more than 1.
277
+
278
+ Fixes #10620.
279
+
280
+ *Aaron Patterson*
281
+
282
+ * Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1.
283
+
284
+ *kennyj*
285
+
286
+ * Deprecate `ConnectionAdapters::SchemaStatements#distinct`,
287
+ as it is no longer used by internals.
288
+
289
+ *Ben Woosley#
290
+
291
+ * Remove not needed bind variables. Port of commit #5082345.
292
+
293
+ Fixes #10958.
294
+
295
+ *Neeraj Singh*
296
+
297
+ * Confirm a record has not already been destroyed before decrementing counter cache.
298
+
299
+ *Ben Tucker*
300
+
301
+ * Fixed a bug in `ActiveRecord#sanitize_sql_hash_for_conditions` in which
302
+ `self.class` is an argument to `PredicateBuilder#build_from_hash`
303
+ causing `PredicateBuilder` to call non-existent method
304
+ `Class#reflect_on_association`.
305
+
306
+ *Zach Ohlgren*
307
+
308
+ * While removing index if column option is missing then raise IrreversibleMigration exception.
309
+
310
+ Following code should raise `IrreversibleMigration`. But the code was
311
+ failing since options is an array and not a hash.
312
+
313
+ def change
314
+ change_table :users do |t|
315
+ t.remove_index [:name, :email]
316
+ end
317
+ end
318
+
319
+ Fix was to check if the options is a Hash before operating on it.
320
+
321
+ Fixes #10419.
322
+
323
+ *Neeraj Singh*
324
+
325
+
1
326
  ## Rails 4.0.0 (June 25, 2013) ##
2
327
 
3
328
  * Fix `add_column` with `array` option when using PostgreSQL. Fixes #10432
@@ -30,7 +355,6 @@
30
355
 
31
356
  *Adam Anderson*
32
357
 
33
-
34
358
  * Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix`
35
359
  is not blank.
36
360
 
@@ -2046,7 +2370,7 @@
2046
2370
  * The primary key is always initialized in the @attributes hash to `nil` (unless
2047
2371
  another value has been specified).
2048
2372
 
2049
- *Aaron Paterson*
2373
+ *Aaron Patterson*
2050
2374
 
2051
2375
  * In previous releases, the following would generate a single query with
2052
2376
  an `OUTER JOIN comments`, rather than two separate queries:
@@ -2098,5 +2422,4 @@
2098
2422
 
2099
2423
  *Aaron Patterson*
2100
2424
 
2101
-
2102
2425
  Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activerecord/CHANGELOG.md) for previous changes.
@@ -192,7 +192,7 @@ The latest version of Active Record can be installed with RubyGems:
192
192
 
193
193
  Source code can be downloaded as part of the Rails project on GitHub:
194
194
 
195
- * https://github.com/rails/rails/tree/master/activerecord
195
+ * https://github.com/rails/rails/tree/4-0-stable/activerecord
196
196
 
197
197
 
198
198
  == License
@@ -76,6 +76,7 @@ module ActiveRecord
76
76
  autoload :AutosaveAssociation
77
77
 
78
78
  autoload :Relation
79
+ autoload :AssociationRelation
79
80
  autoload :NullRelation
80
81
 
81
82
  autoload_under 'relation' do
@@ -0,0 +1,18 @@
1
+ module ActiveRecord
2
+ class AssociationRelation < Relation
3
+ def initialize(klass, table, association)
4
+ super(klass, table)
5
+ @association = association
6
+ end
7
+
8
+ def proxy_association
9
+ @association
10
+ end
11
+
12
+ private
13
+
14
+ def exec_queries
15
+ super.each { |r| @association.set_inverse_instance r }
16
+ end
17
+ end
18
+ end
@@ -18,6 +18,7 @@ module ActiveRecord
18
18
  # HasManyThroughAssociation + ThroughAssociation
19
19
  class Association #:nodoc:
20
20
  attr_reader :owner, :target, :reflection
21
+ attr_accessor :inversed
21
22
 
22
23
  delegate :options, :to => :reflection
23
24
 
@@ -43,6 +44,7 @@ module ActiveRecord
43
44
  @loaded = false
44
45
  @target = nil
45
46
  @stale_state = nil
47
+ @inversed = false
46
48
  end
47
49
 
48
50
  # Reloads the \target and returns +self+ on success.
@@ -60,8 +62,9 @@ module ActiveRecord
60
62
 
61
63
  # Asserts the \target has been loaded setting the \loaded flag to +true+.
62
64
  def loaded!
63
- @loaded = true
65
+ @loaded = true
64
66
  @stale_state = stale_state
67
+ @inversed = false
65
68
  end
66
69
 
67
70
  # The target is stale if the target no longer points to the record(s) that the
@@ -71,7 +74,7 @@ module ActiveRecord
71
74
  #
72
75
  # Note that if the target has not been loaded, it is not considered stale.
73
76
  def stale_target?
74
- loaded? && @stale_state != stale_state
77
+ !inversed && loaded? && @stale_state != stale_state
75
78
  end
76
79
 
77
80
  # Sets the target of this association to <tt>\target</tt>, and the \loaded flag to +true+.
@@ -110,6 +113,7 @@ module ActiveRecord
110
113
  if record && invertible_for?(record)
111
114
  inverse = record.association(inverse_reflection_for(record).name)
112
115
  inverse.target = owner
116
+ inverse.inversed = true
113
117
  end
114
118
  end
115
119
 
@@ -122,7 +126,11 @@ module ActiveRecord
122
126
  # Can be overridden (i.e. in ThroughAssociation) to merge in other scopes (i.e. the
123
127
  # through association's scope)
124
128
  def target_scope
125
- klass.all
129
+ all = klass.all
130
+ scope = AssociationRelation.new(klass, klass.arel_table, self)
131
+ scope.merge! all
132
+ scope.default_scoped = all.default_scoped?
133
+ scope
126
134
  end
127
135
 
128
136
  # Loads the \target if needed and returns it.