activerecord 4.2.1 → 4.2.7.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +368 -1
- data/lib/active_record/aggregations.rb +4 -3
- data/lib/active_record/association_relation.rb +13 -0
- data/lib/active_record/associations/association.rb +15 -3
- data/lib/active_record/associations/association_scope.rb +1 -0
- data/lib/active_record/associations/belongs_to_association.rb +5 -1
- data/lib/active_record/associations/builder/association.rb +1 -1
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +8 -4
- data/lib/active_record/associations/collection_association.rb +1 -7
- data/lib/active_record/associations/collection_proxy.rb +8 -7
- data/lib/active_record/associations/has_many_association.rb +8 -1
- data/lib/active_record/associations/has_many_through_association.rb +9 -0
- data/lib/active_record/associations/join_dependency.rb +8 -2
- data/lib/active_record/associations/preloader/association.rb +5 -1
- data/lib/active_record/associations/preloader.rb +4 -4
- data/lib/active_record/associations/singular_association.rb +2 -8
- data/lib/active_record/associations/through_association.rb +0 -6
- data/lib/active_record/associations.rb +1 -1
- data/lib/active_record/attribute_assignment.rb +1 -1
- data/lib/active_record/attribute_methods/dirty.rb +7 -1
- data/lib/active_record/attribute_methods.rb +3 -7
- data/lib/active_record/attribute_set/builder.rb +21 -11
- data/lib/active_record/attribute_set.rb +4 -0
- data/lib/active_record/autosave_association.rb +1 -1
- data/lib/active_record/base.rb +4 -5
- data/lib/active_record/callbacks.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +4 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +11 -2
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +16 -24
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +49 -17
- data/lib/active_record/connection_adapters/abstract/transaction.rb +1 -5
- data/lib/active_record/connection_adapters/abstract_adapter.rb +12 -1
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +38 -5
- data/lib/active_record/connection_adapters/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +3 -3
- data/lib/active_record/connection_adapters/mysql_adapter.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +17 -5
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +15 -6
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -9
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +2 -12
- data/lib/active_record/core.rb +15 -8
- data/lib/active_record/enum.rb +2 -3
- data/lib/active_record/errors.rb +6 -5
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixtures.rb +8 -6
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/legacy_yaml_adapter.rb +30 -0
- data/lib/active_record/migration.rb +7 -4
- data/lib/active_record/model_schema.rb +1 -1
- data/lib/active_record/nested_attributes.rb +12 -2
- data/lib/active_record/persistence.rb +5 -3
- data/lib/active_record/railtie.rb +1 -1
- data/lib/active_record/railties/databases.rake +10 -7
- data/lib/active_record/reflection.rb +39 -27
- data/lib/active_record/relation/calculations.rb +8 -1
- data/lib/active_record/relation/delegation.rb +1 -1
- data/lib/active_record/relation/finder_methods.rb +3 -15
- data/lib/active_record/relation/merger.rb +24 -1
- data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -1
- data/lib/active_record/relation/predicate_builder.rb +11 -2
- data/lib/active_record/relation/query_methods.rb +15 -18
- data/lib/active_record/relation/spawn_methods.rb +7 -3
- data/lib/active_record/relation.rb +2 -1
- data/lib/active_record/scoping/default.rb +1 -0
- data/lib/active_record/tasks/database_tasks.rb +3 -2
- data/lib/active_record/tasks/mysql_database_tasks.rb +30 -16
- data/lib/active_record/tasks/postgresql_database_tasks.rb +19 -8
- data/lib/active_record/transactions.rb +16 -4
- data/lib/active_record/type/boolean.rb +1 -0
- data/lib/active_record/type/date.rb +4 -0
- data/lib/active_record/type/decimal.rb +12 -2
- data/lib/active_record/type/hash_lookup_type_map.rb +8 -2
- data/lib/active_record/type/serialized.rb +7 -1
- data/lib/active_record/validations/uniqueness.rb +15 -5
- data/lib/active_record.rb +2 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b27166a8cdbbc938588145984ecc536905ea7b49
|
4
|
+
data.tar.gz: b835c5264868bb6df623a97c7d8cdab457fe35c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa5ca2a1f3553ed395014a4c8808838dca260cec90266dc5dda61f4c8c4f5d4bc659ead3c4af9189555a96e87d4b053dcc04c8e5aae09744e4a4a0c14c57bb20
|
7
|
+
data.tar.gz: d9733d5c9e015373b0101299215f411cdc5dff68a961c307fe0336a5daa83bfa7992abe6266a43cb35690853f9df84921ee215ae54cfaf3baa2032aacc081418
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,371 @@
|
|
1
|
-
## Rails 4.2.
|
1
|
+
## Rails 4.2.7 (July 12, 2016) ##
|
2
|
+
|
3
|
+
* Inspecting an object with an associated array of over 10 elements no longer
|
4
|
+
truncates the array, preventing `inspect` from looping infinitely in some
|
5
|
+
cases.
|
6
|
+
|
7
|
+
*Kevin McPhillips*
|
8
|
+
|
9
|
+
* Ensure hashes can be assigned to attributes created using `composed_of`.
|
10
|
+
Fixes #25210.
|
11
|
+
|
12
|
+
*Sean Griffin*
|
13
|
+
|
14
|
+
* Queries such as `Computer.joins(:monitor).group(:status).count` will now be
|
15
|
+
interpreted as `Computer.joins(:monitor).group('computers.status').count`
|
16
|
+
so that when `Computer` and `Monitor` have both `status` columns we don't
|
17
|
+
have conflicts in projection.
|
18
|
+
|
19
|
+
*Rafael Sales*
|
20
|
+
|
21
|
+
* ActiveRecord::Relation#count: raise an ArgumentError when finder options
|
22
|
+
are specified or an ActiveRecord::StatementInvalid when an invalid type
|
23
|
+
is provided for a column name (e.g. a Hash).
|
24
|
+
|
25
|
+
Fixes #20434
|
26
|
+
|
27
|
+
*Konstantinos Rousis*
|
28
|
+
|
29
|
+
* Correctly pass MySQL options when using structure_dump or structure_load
|
30
|
+
|
31
|
+
Specifically, it fixes an issue when using SSL authentication.
|
32
|
+
|
33
|
+
*Alex Coomans*
|
34
|
+
|
35
|
+
|
36
|
+
## Rails 4.2.6 (March 07, 2016) ##
|
37
|
+
|
38
|
+
* Fix a bug where using `t.foreign_key` twice with the same `to_table` within
|
39
|
+
the same table definition would only create one foreign key.
|
40
|
+
|
41
|
+
*George Millo*
|
42
|
+
|
43
|
+
* Fix regression in dirty attribute tracking after #dup. Changes to the
|
44
|
+
clone no longer show as changed attributes in the original object.
|
45
|
+
|
46
|
+
*Dominic Cleal*
|
47
|
+
|
48
|
+
* Fix regression when loading fixture files with symbol keys.
|
49
|
+
|
50
|
+
Closes #22584.
|
51
|
+
|
52
|
+
*Yves Senn*
|
53
|
+
|
54
|
+
* Fix `rake db:structure:dump` on Postgres when multiple schemas are used.
|
55
|
+
|
56
|
+
Fixes #22346.
|
57
|
+
|
58
|
+
*Nick Muerdter*, *ckoenig*
|
59
|
+
|
60
|
+
* Introduce `connection.data_sources` and `connection.data_source_exists?`.
|
61
|
+
These methods determine what relations can be used to back Active Record
|
62
|
+
models (usually tables and views).
|
63
|
+
|
64
|
+
*Yves Senn*, *Matthew Draper*
|
65
|
+
|
66
|
+
|
67
|
+
## Rails 4.2.5.2 (February 26, 2016) ##
|
68
|
+
|
69
|
+
* No changes.
|
70
|
+
|
71
|
+
|
72
|
+
## Rails 4.2.5.1 (January 25, 2015) ##
|
73
|
+
|
74
|
+
* No changes.
|
75
|
+
|
76
|
+
|
77
|
+
## Rails 4.2.5 (November 12, 2015) ##
|
78
|
+
|
79
|
+
* No longer pass deprecated option `-i` to `pg_dump`.
|
80
|
+
|
81
|
+
*Paul Sadauskas*
|
82
|
+
|
83
|
+
* Set `scope.reordering_value` to `true` if :reordering values are specified.
|
84
|
+
|
85
|
+
Fixes #21886.
|
86
|
+
|
87
|
+
*Hiroaki Izu*
|
88
|
+
|
89
|
+
* Avoid disabling errors on the PostgreSQL connection when enabling the
|
90
|
+
standard_conforming_strings setting. Errors were previously disabled because
|
91
|
+
the setting wasn't writable in Postgres 8.1 and didn't exist in earlier
|
92
|
+
versions. Now Rails only supports Postgres 8.2+ we're fine to assume the
|
93
|
+
setting exists. Disabling errors caused problems when using a connection
|
94
|
+
pooling tool like PgBouncer because it's not guaranteed to have the same
|
95
|
+
connection between calls to `execute` and it could leave the connection
|
96
|
+
with errors disabled.
|
97
|
+
|
98
|
+
Fixes #22101.
|
99
|
+
|
100
|
+
*Harry Marr*
|
101
|
+
|
102
|
+
* Includes HABTM returns correct size now. It's caused by the join dependency
|
103
|
+
only instantiates one HABTM object because the join table hasn't a primary key.
|
104
|
+
|
105
|
+
Fixes #16032.
|
106
|
+
|
107
|
+
Examples:
|
108
|
+
|
109
|
+
before:
|
110
|
+
|
111
|
+
Project.first.salaried_developers.size # => 3
|
112
|
+
Project.includes(:salaried_developers).first.salaried_developers.size # => 1
|
113
|
+
|
114
|
+
after:
|
115
|
+
|
116
|
+
Project.first.salaried_developers.size # => 3
|
117
|
+
Project.includes(:salaried_developers).first.salaried_developers.size # => 3
|
118
|
+
|
119
|
+
*Bigxiang*
|
120
|
+
|
121
|
+
* Descriptive error message when fixtures contain a missing column.
|
122
|
+
|
123
|
+
Closes #21201.
|
124
|
+
|
125
|
+
*Yves Senn*
|
126
|
+
|
127
|
+
* `bin/rake db:migrate` uses
|
128
|
+
`ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of
|
129
|
+
`Migrator.migrations_paths`.
|
130
|
+
|
131
|
+
*Tobias Bielohlawek*
|
132
|
+
|
133
|
+
* Fix `rewhere` in a `has_many` association.
|
134
|
+
|
135
|
+
Fixes #21955.
|
136
|
+
|
137
|
+
*Josh Branchaud*, *Kal*
|
138
|
+
|
139
|
+
* Added run_cmd class method to ActiveRecord::Tasks::DatabaseTasks for
|
140
|
+
drying up Kernel.system() calls within this namespace and to avoid
|
141
|
+
shell expansion by using a paramter list instead of string as arguments
|
142
|
+
for Kernel.system(). Thanks to Nate Berkopec for supply patch to get
|
143
|
+
test units passing.
|
144
|
+
|
145
|
+
*Bryan Paxton*
|
146
|
+
|
147
|
+
* Avoid leaking the first relation we call `first` on, per model.
|
148
|
+
|
149
|
+
Fixes #21921.
|
150
|
+
|
151
|
+
*Matthew Draper*, *Jean Boussier*
|
152
|
+
|
153
|
+
* Allow deserialization of Active Record models that were YAML encoded prior
|
154
|
+
to Rails 4.2
|
155
|
+
|
156
|
+
*Sean Griffin*
|
157
|
+
|
158
|
+
* Correctly apply `unscope` when preloading through associations.
|
159
|
+
|
160
|
+
*Jimmy Bourassa*
|
161
|
+
|
162
|
+
* Ensure `select` quotes aliased attributes, even when using `from`.
|
163
|
+
|
164
|
+
Fixes #21488
|
165
|
+
|
166
|
+
*Sean Griffin & @johanlunds*
|
167
|
+
|
168
|
+
* Correct query for PostgreSQL 8.2 compatibility.
|
169
|
+
|
170
|
+
*Ben Murphy*, *Matthew Draper*
|
171
|
+
|
172
|
+
* Uniqueness validator raises descriptive error when running on a persisted
|
173
|
+
record without primary key.
|
174
|
+
|
175
|
+
Closes #21304.
|
176
|
+
|
177
|
+
*Yves Senn*
|
178
|
+
|
179
|
+
|
180
|
+
## Rails 4.2.4 (August 24, 2015) ##
|
181
|
+
|
182
|
+
* Skip statement cache on through association reader.
|
183
|
+
|
184
|
+
If the through class has default scopes we should skip the statement
|
185
|
+
cache.
|
186
|
+
|
187
|
+
Closes #20745.
|
188
|
+
|
189
|
+
*Rafael Mendonça França*
|
190
|
+
|
191
|
+
* Fixes #19420. When generating schema.rb using Postgres BigInt[] data type
|
192
|
+
the limit: 8 was not coming through. This caused it to become Int[] data type
|
193
|
+
after doing a rebuild off of schema.rb.
|
194
|
+
|
195
|
+
*Jake Waller*
|
196
|
+
|
197
|
+
* Fix state being carried over from previous transaction.
|
198
|
+
|
199
|
+
Considering the following example where `name` is a required attribute.
|
200
|
+
Before we had `new_record?` returning `true` for a persisted record:
|
201
|
+
|
202
|
+
author = Author.create! name: 'foo'
|
203
|
+
author.name = nil
|
204
|
+
author.save # => false
|
205
|
+
author.new_record? # => true
|
206
|
+
|
207
|
+
Fixes #20824.
|
208
|
+
|
209
|
+
*Roque Pinel*
|
210
|
+
|
211
|
+
* Correctly ignore `mark_for_destruction` when `autosave` isn't set to `true`
|
212
|
+
when validating associations.
|
213
|
+
|
214
|
+
Fixes #20882.
|
215
|
+
|
216
|
+
*Sean Griffin*
|
217
|
+
|
218
|
+
* Fix through associations using scopes having the scope merged multiple
|
219
|
+
times.
|
220
|
+
|
221
|
+
Fixes #20721.
|
222
|
+
Fixes #20727.
|
223
|
+
|
224
|
+
*Sean Griffin*
|
225
|
+
|
226
|
+
* `ActiveRecord::Base.dump_schema_after_migration` applies migration tasks
|
227
|
+
other than `db:migrate`. (eg. `db:rollback`, `db:migrate:dup`, ...)
|
228
|
+
|
229
|
+
Fixes #20743.
|
230
|
+
|
231
|
+
*Yves Senn*
|
232
|
+
|
233
|
+
* Correctly raise `ActiveRecord::AssociationTypeMismatch` when assigning
|
234
|
+
a wrong type to a namespaced association.
|
235
|
+
|
236
|
+
Fixes #20545.
|
237
|
+
|
238
|
+
*Diego Carrion*
|
239
|
+
|
240
|
+
* Prevent error when using `force_reload: true` on an unassigned polymorphic
|
241
|
+
belongs_to association.
|
242
|
+
|
243
|
+
Fixes #20426.
|
244
|
+
|
245
|
+
*James Dabbs*
|
246
|
+
|
247
|
+
|
248
|
+
## Rails 4.2.3 (June 25, 2015) ##
|
249
|
+
|
250
|
+
* Let `WITH` queries (Common Table Expressions) be explainable.
|
251
|
+
|
252
|
+
*Vladimir Kochnev*
|
253
|
+
|
254
|
+
* Fix n+1 query problem when eager loading nil associations (fixes #18312)
|
255
|
+
|
256
|
+
*Sammy Larbi*
|
257
|
+
|
258
|
+
* Fixed an error which would occur in dirty checking when calling
|
259
|
+
`update_attributes` from a getter.
|
260
|
+
|
261
|
+
Fixes #20531.
|
262
|
+
|
263
|
+
*Sean Griffin*
|
264
|
+
|
265
|
+
* Ensure symbols passed to `ActiveRecord::Relation#select` are always treated
|
266
|
+
as columns.
|
267
|
+
|
268
|
+
Fixes #20360.
|
269
|
+
|
270
|
+
*Sean Griffin*
|
271
|
+
|
272
|
+
* Clear query cache when `ActiveRecord::Base#reload` is called.
|
273
|
+
|
274
|
+
*Shane Hender*
|
275
|
+
|
276
|
+
* Pass `:extend` option for `has_and_belongs_to_many` associations to the
|
277
|
+
underlying `has_many :through`.
|
278
|
+
|
279
|
+
*Jaehyun Shin*
|
280
|
+
|
281
|
+
* Make `unscope` aware of "less than" and "greater than" conditions.
|
282
|
+
|
283
|
+
*TAKAHASHI Kazuaki*
|
284
|
+
|
285
|
+
* Revert behavior of `db:schema:load` back to loading the full
|
286
|
+
environment. This ensures that initializers are run.
|
287
|
+
|
288
|
+
Fixes #19545.
|
289
|
+
|
290
|
+
*Yves Senn*
|
291
|
+
|
292
|
+
* Fix missing index when using `timestamps` with the `index` option.
|
293
|
+
|
294
|
+
The `index` option used with `timestamps` should be passed to both
|
295
|
+
`column` definitions for `created_at` and `updated_at` rather than just
|
296
|
+
the first.
|
297
|
+
|
298
|
+
*Paul Mucur*
|
299
|
+
|
300
|
+
* Rename `:class` to `:anonymous_class` in association options.
|
301
|
+
|
302
|
+
Fixes #19659.
|
303
|
+
|
304
|
+
*Andrew White*
|
305
|
+
|
306
|
+
* Fixed a bug where uniqueness validations would error on out of range values,
|
307
|
+
even if an validation should have prevented it from hitting the database.
|
308
|
+
|
309
|
+
*Andrey Voronkov*
|
310
|
+
|
311
|
+
* Foreign key related methods in the migration DSL respect
|
312
|
+
`ActiveRecord::Base.pluralize_table_names = false`.
|
313
|
+
|
314
|
+
Fixes #19643.
|
315
|
+
|
316
|
+
*Mehmet Emin İNAÇ*
|
317
|
+
|
318
|
+
* Reduce memory usage from loading types on pg.
|
319
|
+
|
320
|
+
Fixes #19578.
|
321
|
+
|
322
|
+
*Sean Griffin*
|
323
|
+
|
324
|
+
* Fix referencing wrong table aliases while joining tables of has many through
|
325
|
+
association (only when calling calculation methods).
|
326
|
+
|
327
|
+
Fixes #19276.
|
328
|
+
|
329
|
+
*pinglamb*
|
330
|
+
|
331
|
+
* Don't attempt to update counter caches, when the column wasn't selected.
|
332
|
+
|
333
|
+
Fixes #19437.
|
334
|
+
|
335
|
+
*Sean Griffin*
|
336
|
+
|
337
|
+
* Correctly persist a serialized attribute that has been returned to
|
338
|
+
its default value by an in-place modification.
|
339
|
+
|
340
|
+
Fixes #19467.
|
341
|
+
|
342
|
+
*Matthew Draper*
|
343
|
+
|
344
|
+
* Fix default `format` value in `ActiveRecord::Tasks::DatabaseTasks#schema_file`.
|
345
|
+
|
346
|
+
*James Cox*
|
347
|
+
|
348
|
+
* Dont enroll records in the transaction if they dont have commit callbacks.
|
349
|
+
That was causing a memory grow problem when creating a lot of records inside a transaction.
|
350
|
+
|
351
|
+
Fixes #15549.
|
352
|
+
|
353
|
+
*Will Bryant*, *Aaron Patterson*
|
354
|
+
|
355
|
+
* Correctly create through records when created on a has many through
|
356
|
+
association when using `where`.
|
357
|
+
|
358
|
+
Fixes #19073.
|
359
|
+
|
360
|
+
*Sean Griffin*
|
361
|
+
|
362
|
+
|
363
|
+
## Rails 4.2.2 (June 16, 2015) ##
|
364
|
+
|
365
|
+
* No Changes *
|
366
|
+
|
367
|
+
|
368
|
+
## Rails 4.2.1 (March 19, 2015) ##
|
2
369
|
|
3
370
|
* Fixed ActiveRecord::Relation#becomes! and changed_attributes issues for type column
|
4
371
|
|
@@ -244,14 +244,15 @@ module ActiveRecord
|
|
244
244
|
def writer_method(name, class_name, mapping, allow_nil, converter)
|
245
245
|
define_method("#{name}=") do |part|
|
246
246
|
klass = class_name.constantize
|
247
|
-
if part.is_a?(Hash)
|
248
|
-
part = klass.new(*part.values)
|
249
|
-
end
|
250
247
|
|
251
248
|
unless part.is_a?(klass) || converter.nil? || part.nil?
|
252
249
|
part = converter.respond_to?(:call) ? converter.call(part) : klass.send(converter, part)
|
253
250
|
end
|
254
251
|
|
252
|
+
if part.is_a?(Hash)
|
253
|
+
part = klass.new(*part.values)
|
254
|
+
end
|
255
|
+
|
255
256
|
if part.nil? && allow_nil
|
256
257
|
mapping.each { |key, _| self[key] = nil }
|
257
258
|
@aggregation_cache[name] = nil
|
@@ -13,6 +13,19 @@ module ActiveRecord
|
|
13
13
|
other == to_a
|
14
14
|
end
|
15
15
|
|
16
|
+
def build(*args, &block)
|
17
|
+
scoping { @association.build(*args, &block) }
|
18
|
+
end
|
19
|
+
alias new build
|
20
|
+
|
21
|
+
def create(*args, &block)
|
22
|
+
scoping { @association.create(*args, &block) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def create!(*args, &block)
|
26
|
+
scoping { @association.create!(*args, &block) }
|
27
|
+
end
|
28
|
+
|
16
29
|
private
|
17
30
|
|
18
31
|
def exec_queries
|
@@ -211,9 +211,12 @@ module ActiveRecord
|
|
211
211
|
# the kind of the class of the associated objects. Meant to be used as
|
212
212
|
# a sanity check when you are about to assign an associated record.
|
213
213
|
def raise_on_type_mismatch!(record)
|
214
|
-
unless record.is_a?(reflection.klass)
|
215
|
-
|
216
|
-
|
214
|
+
unless record.is_a?(reflection.klass)
|
215
|
+
fresh_class = reflection.class_name.safe_constantize
|
216
|
+
unless fresh_class && record.is_a?(fresh_class)
|
217
|
+
message = "#{reflection.class_name}(##{reflection.klass.object_id}) expected, got #{record.class}(##{record.class.object_id})"
|
218
|
+
raise ActiveRecord::AssociationTypeMismatch, message
|
219
|
+
end
|
217
220
|
end
|
218
221
|
end
|
219
222
|
|
@@ -248,6 +251,15 @@ module ActiveRecord
|
|
248
251
|
initialize_attributes(record)
|
249
252
|
end
|
250
253
|
end
|
254
|
+
|
255
|
+
# Returns true if statement cache should be skipped on the association reader.
|
256
|
+
def skip_statement_cache?
|
257
|
+
reflection.scope_chain.any?(&:any?) ||
|
258
|
+
scope.eager_loading? ||
|
259
|
+
klass.current_scope ||
|
260
|
+
klass.default_scopes.any? ||
|
261
|
+
reflection.source_reflection.active_record.default_scopes.any?
|
262
|
+
end
|
251
263
|
end
|
252
264
|
end
|
253
265
|
end
|
@@ -68,7 +68,7 @@ module ActiveRecord
|
|
68
68
|
def increment_counter(counter_cache_name)
|
69
69
|
if foreign_key_present?
|
70
70
|
klass.increment_counter(counter_cache_name, target_id)
|
71
|
-
if target && !stale_target?
|
71
|
+
if target && !stale_target? && counter_cache_available_in_memory?(counter_cache_name)
|
72
72
|
target.increment(counter_cache_name)
|
73
73
|
end
|
74
74
|
end
|
@@ -110,6 +110,10 @@ module ActiveRecord
|
|
110
110
|
result = owner._read_attribute(reflection.foreign_key)
|
111
111
|
result && result.to_s
|
112
112
|
end
|
113
|
+
|
114
|
+
def counter_cache_available_in_memory?(counter_cache_name)
|
115
|
+
target.respond_to?(counter_cache_name)
|
116
|
+
end
|
113
117
|
end
|
114
118
|
end
|
115
119
|
end
|
@@ -21,7 +21,7 @@ module ActiveRecord::Associations::Builder
|
|
21
21
|
end
|
22
22
|
self.extensions = []
|
23
23
|
|
24
|
-
self.valid_options = [:class_name, :
|
24
|
+
self.valid_options = [:class_name, :anonymous_class, :foreign_key, :validate]
|
25
25
|
|
26
26
|
attr_reader :name, :scope, :options
|
27
27
|
|
@@ -46,7 +46,7 @@ module ActiveRecord::Associations::Builder
|
|
46
46
|
|
47
47
|
join_model = Class.new(ActiveRecord::Base) {
|
48
48
|
class << self;
|
49
|
-
attr_accessor :
|
49
|
+
attr_accessor :left_model
|
50
50
|
attr_accessor :name
|
51
51
|
attr_accessor :table_name_resolver
|
52
52
|
attr_accessor :left_reflection
|
@@ -58,7 +58,7 @@ module ActiveRecord::Associations::Builder
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.compute_type(class_name)
|
61
|
-
|
61
|
+
left_model.compute_type class_name
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.add_left_association(name, options)
|
@@ -72,13 +72,17 @@ module ActiveRecord::Associations::Builder
|
|
72
72
|
self.right_reflection = _reflect_on_association(rhs_name)
|
73
73
|
end
|
74
74
|
|
75
|
+
def self.retrieve_connection
|
76
|
+
left_model.retrieve_connection
|
77
|
+
end
|
78
|
+
|
75
79
|
}
|
76
80
|
|
77
81
|
join_model.name = "HABTM_#{association_name.to_s.camelize}"
|
78
82
|
join_model.table_name_resolver = habtm
|
79
|
-
join_model.
|
83
|
+
join_model.left_model = lhs_model
|
80
84
|
|
81
|
-
join_model.add_left_association :left_side,
|
85
|
+
join_model.add_left_association :left_side, anonymous_class: lhs_model
|
82
86
|
join_model.add_right_association association_name, belongs_to_options(options)
|
83
87
|
join_model
|
84
88
|
end
|
@@ -431,13 +431,7 @@ module ActiveRecord
|
|
431
431
|
|
432
432
|
private
|
433
433
|
def get_records
|
434
|
-
if
|
435
|
-
scope.eager_loading? ||
|
436
|
-
klass.current_scope ||
|
437
|
-
klass.default_scopes.any?
|
438
|
-
|
439
|
-
return scope.to_a
|
440
|
-
end
|
434
|
+
return scope.to_a if skip_statement_cache?
|
441
435
|
|
442
436
|
conn = klass.connection
|
443
437
|
sc = reflection.association_scope_cache(conn, owner) do
|
@@ -470,15 +470,16 @@ module ActiveRecord
|
|
470
470
|
@association.destroy_all
|
471
471
|
end
|
472
472
|
|
473
|
-
# Deletes the +records+ supplied
|
474
|
-
#
|
475
|
-
#
|
473
|
+
# Deletes the +records+ supplied from the collection according to the strategy
|
474
|
+
# specified by the +:dependent+ option. If no +:dependent+ option is given,
|
475
|
+
# then it will follow the default strategy. Returns an array with the
|
476
476
|
# deleted records.
|
477
477
|
#
|
478
|
-
#
|
479
|
-
#
|
480
|
-
#
|
481
|
-
# strategy is
|
478
|
+
# For +has_many :through+ associations, the default deletion strategy is
|
479
|
+
# +:delete_all+.
|
480
|
+
#
|
481
|
+
# For +has_many+ associations, the default deletion strategy is +:nullify+.
|
482
|
+
# This sets the foreign keys to +NULL+.
|
482
483
|
#
|
483
484
|
# class Person < ActiveRecord::Base
|
484
485
|
# has_many :pets # dependent: :nullify option by default
|
@@ -80,8 +80,15 @@ module ActiveRecord
|
|
80
80
|
[association_scope.limit_value, count].compact.min
|
81
81
|
end
|
82
82
|
|
83
|
+
|
84
|
+
# Returns whether a counter cache should be used for this association.
|
85
|
+
#
|
86
|
+
# The counter_cache option must be given on either the owner or inverse
|
87
|
+
# association, and the column must be present on the owner.
|
83
88
|
def has_cached_counter?(reflection = reflection())
|
84
|
-
|
89
|
+
if reflection.options[:counter_cache] || (inverse = inverse_which_updates_counter_cache(reflection)) && inverse.options[:counter_cache]
|
90
|
+
owner.attribute_present?(cached_counter_attribute_name(reflection))
|
91
|
+
end
|
85
92
|
end
|
86
93
|
|
87
94
|
def cached_counter_attribute_name(reflection = reflection())
|
@@ -94,6 +94,11 @@ module ActiveRecord
|
|
94
94
|
|
95
95
|
through_record = through_association.build(*options_for_through_record)
|
96
96
|
through_record.send("#{source_reflection.name}=", record)
|
97
|
+
|
98
|
+
if options[:source_type]
|
99
|
+
through_record.send("#{source_reflection.foreign_type}=", options[:source_type])
|
100
|
+
end
|
101
|
+
|
97
102
|
through_record
|
98
103
|
end
|
99
104
|
end
|
@@ -229,6 +234,10 @@ module ActiveRecord
|
|
229
234
|
false
|
230
235
|
end
|
231
236
|
|
237
|
+
def has_cached_counter?(reflection = reflection())
|
238
|
+
owner.attribute_present?(cached_counter_attribute_name(reflection))
|
239
|
+
end
|
240
|
+
|
232
241
|
def through_reflection_updates_counter_cache?
|
233
242
|
counter_name = cached_counter_attribute_name
|
234
243
|
inverse_updates_counter_named?(counter_name, through_reflection)
|
@@ -151,7 +151,8 @@ module ActiveRecord
|
|
151
151
|
|
152
152
|
message_bus.instrument('instantiation.active_record', payload) do
|
153
153
|
result_set.each { |row_hash|
|
154
|
-
|
154
|
+
parent_key = primary_key ? row_hash[primary_key] : row_hash
|
155
|
+
parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases)
|
155
156
|
construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
|
156
157
|
}
|
157
158
|
end
|
@@ -233,6 +234,7 @@ module ActiveRecord
|
|
233
234
|
end
|
234
235
|
|
235
236
|
def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
|
237
|
+
return if ar_parent.nil?
|
236
238
|
primary_id = ar_parent.id
|
237
239
|
|
238
240
|
parent.children.each do |node|
|
@@ -249,7 +251,11 @@ module ActiveRecord
|
|
249
251
|
|
250
252
|
key = aliases.column_alias(node, node.primary_key)
|
251
253
|
id = row[key]
|
252
|
-
|
254
|
+
if id.nil?
|
255
|
+
nil_association = ar_parent.association(node.reflection.name)
|
256
|
+
nil_association.loaded!
|
257
|
+
next
|
258
|
+
end
|
253
259
|
|
254
260
|
model = seen[parent.base_klass][primary_id][node.base_klass][id]
|
255
261
|
|
@@ -145,6 +145,10 @@ module ActiveRecord
|
|
145
145
|
scope.joins! preload_values[:joins] || values[:joins]
|
146
146
|
scope.order! preload_values[:order] || values[:order]
|
147
147
|
|
148
|
+
if preload_values[:reordering] || values[:reordering]
|
149
|
+
scope.reordering_value = true
|
150
|
+
end
|
151
|
+
|
148
152
|
if preload_values[:readonly] || values[:readonly]
|
149
153
|
scope.readonly!
|
150
154
|
end
|
@@ -153,7 +157,7 @@ module ActiveRecord
|
|
153
157
|
scope.where!(klass.table_name => { reflection.type => model.base_class.sti_name })
|
154
158
|
end
|
155
159
|
|
156
|
-
scope.unscope_values = Array(values[:unscope])
|
160
|
+
scope.unscope_values = Array(values[:unscope]) + Array(preload_values[:unscope])
|
157
161
|
klass.default_scoped.merge(scope)
|
158
162
|
end
|
159
163
|
end
|