activerecord 4.2.0.beta4 → 4.2.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +107 -34
- data/lib/active_record/aggregations.rb +2 -2
- data/lib/active_record/associations.rb +1 -1
- data/lib/active_record/associations/alias_tracker.rb +3 -12
- data/lib/active_record/associations/association_scope.rb +1 -2
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +2 -2
- data/lib/active_record/associations/collection_association.rb +29 -6
- data/lib/active_record/associations/has_many_association.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +2 -2
- data/lib/active_record/associations/join_dependency.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +1 -1
- data/lib/active_record/associations/preloader.rb +1 -0
- data/lib/active_record/associations/preloader/association.rb +3 -8
- data/lib/active_record/associations/preloader/through_association.rb +1 -0
- data/lib/active_record/associations/singular_association.rb +2 -1
- data/lib/active_record/attribute_methods.rb +2 -2
- data/lib/active_record/attribute_methods/dirty.rb +1 -1
- data/lib/active_record/attribute_methods/primary_key.rb +2 -1
- data/lib/active_record/attribute_methods/read.rb +13 -5
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
- data/lib/active_record/attribute_set.rb +7 -11
- data/lib/active_record/attribute_set/builder.rb +66 -17
- data/lib/active_record/attributes.rb +20 -3
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +0 -4
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +1 -3
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +25 -24
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +9 -3
- data/lib/active_record/connection_adapters/abstract_adapter.rb +9 -7
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +25 -13
- data/lib/active_record/connection_adapters/connection_specification.rb +1 -1
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +6 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +6 -2
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +0 -4
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +6 -16
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +29 -7
- data/lib/active_record/connection_adapters/postgresql/utils.rb +15 -4
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +15 -6
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +5 -7
- data/lib/active_record/connection_handling.rb +1 -1
- data/lib/active_record/core.rb +5 -3
- data/lib/active_record/enum.rb +1 -1
- data/lib/active_record/errors.rb +21 -0
- data/lib/active_record/fixtures.rb +4 -2
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/locking/optimistic.rb +1 -1
- data/lib/active_record/migration.rb +15 -4
- data/lib/active_record/model_schema.rb +8 -4
- data/lib/active_record/persistence.rb +5 -5
- data/lib/active_record/railtie.rb +0 -2
- data/lib/active_record/railties/databases.rake +7 -6
- data/lib/active_record/reflection.rb +2 -2
- data/lib/active_record/relation.rb +21 -13
- data/lib/active_record/relation/calculations.rb +1 -0
- data/lib/active_record/relation/finder_methods.rb +8 -5
- data/lib/active_record/relation/merger.rb +0 -12
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
- data/lib/active_record/relation/query_methods.rb +30 -18
- data/lib/active_record/sanitization.rb +4 -1
- data/lib/active_record/schema_dumper.rb +1 -6
- data/lib/active_record/scoping/named.rb +1 -1
- data/lib/active_record/statement_cache.rb +21 -10
- data/lib/active_record/tasks/database_tasks.rb +17 -2
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -0
- data/lib/active_record/type.rb +1 -0
- data/lib/active_record/type/big_integer.rb +13 -0
- data/lib/active_record/type/decimal_without_scale.rb +2 -2
- data/lib/active_record/type/hash_lookup_type_map.rb +5 -7
- data/lib/active_record/type/integer.rb +29 -1
- data/lib/active_record/type/serialized.rb +1 -1
- data/lib/active_record/type/string.rb +4 -4
- data/lib/active_record/type/type_map.rb +23 -7
- data/lib/active_record/validations.rb +4 -3
- data/lib/active_record/validations/uniqueness.rb +1 -1
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +3 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb +6 -0
- metadata +15 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e36df2e99fc4c9ad7289fa8fd6a11f85a5933267
|
4
|
+
data.tar.gz: 181f2f79748d0e92fb6a0e3c253dce3d08332577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2450da5cfc14bdaea3914cb83a0f53193b26eb6600b1de7353901ba92edf085ff1437f970f6546b1701e28ba5f369747315e75a9692be14dccd6169f273ade26
|
7
|
+
data.tar.gz: 082d7b0fc38bbea2ba4591d8d14c2ac196de1c057e5710e6fac6e286c6e5ab494b760de8563f0570ee3daae96ef8274cd0e1c7fd7430c7c3cf3d630e6482c447
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,73 @@
|
|
1
|
+
* Bring back `db:test:prepare` to synchronize the test database schema.
|
2
|
+
|
3
|
+
Manual synchronization using `bin/rake db:test:prepare` is required
|
4
|
+
when a migration is rolled-back, edited and reapplied.
|
5
|
+
|
6
|
+
`ActiveRecord::Base.maintain_test_schema` now uses `db:test:prepare`
|
7
|
+
to synchronize the schema. Plugins can use this task as a hook to
|
8
|
+
provide custom behavior after the schema has been loaded.
|
9
|
+
|
10
|
+
NOTE: `test:prepare` runs before the schema is synchronized.
|
11
|
+
|
12
|
+
Fixes #17171, #15787.
|
13
|
+
|
14
|
+
*Yves Senn*
|
15
|
+
|
16
|
+
* Change `reflections` public api to return the keys as String objects.
|
17
|
+
|
18
|
+
Fixes #16928.
|
19
|
+
|
20
|
+
*arthurnn*
|
21
|
+
|
22
|
+
* Renaming a table in pg also renames the primary key index.
|
23
|
+
|
24
|
+
Fixes #12856
|
25
|
+
|
26
|
+
*Sean Griffin*
|
27
|
+
|
28
|
+
* Make it possible to access fixtures excluded by a `default_scope`.
|
29
|
+
|
30
|
+
*Yves Senn*
|
31
|
+
|
32
|
+
* Fix preloading of associations with a scope containing joins along with
|
33
|
+
conditions on the joined association.
|
34
|
+
|
35
|
+
*Siddharth Sharma*
|
36
|
+
|
37
|
+
* Add `Table#name` to match `TableDefinition#name`.
|
38
|
+
|
39
|
+
*Cody Cutrer*
|
40
|
+
|
41
|
+
* Cache `CollectionAssociation#reader` proxies separately before and after
|
42
|
+
the owner has been saved so that the proxy is not cached without the
|
43
|
+
owner's id.
|
44
|
+
|
45
|
+
*Ben Woosley*
|
46
|
+
|
47
|
+
* `ActiveRecord::ReadOnlyRecord` now has a descriptive message.
|
48
|
+
|
49
|
+
*Franky W.*
|
50
|
+
|
51
|
+
* Fix preloading of associations which unscope a default scope.
|
52
|
+
|
53
|
+
Fixes #11036.
|
54
|
+
|
55
|
+
*Byron Bischoff*
|
56
|
+
|
57
|
+
* Added SchemaDumper support for tables with jsonb columns.
|
58
|
+
|
59
|
+
*Ted O'Meara*
|
60
|
+
|
61
|
+
* Deprecate `sanitize_sql_hash_for_conditions` without replacement. Using a
|
62
|
+
`Relation` for performing queries and updates is the prefered API.
|
63
|
+
|
64
|
+
*Sean Griffin*
|
65
|
+
|
66
|
+
* Queries now properly type cast values that are part of a join statement,
|
67
|
+
even when using type decorators such as `serialize`.
|
68
|
+
|
69
|
+
*Melanie Gilman & Sean Griffin*
|
70
|
+
|
1
71
|
* MySQL enum type lookups, with values matching another type, no longer result
|
2
72
|
in an endless loop.
|
3
73
|
|
@@ -24,7 +94,7 @@
|
|
24
94
|
|
25
95
|
*Yuki Nishijima*
|
26
96
|
|
27
|
-
* Fix regression causing `after_create` callbacks to run before associated
|
97
|
+
* Fix a regression causing `after_create` callbacks to run before associated
|
28
98
|
records are autosaved.
|
29
99
|
|
30
100
|
Fixes #17209.
|
@@ -121,7 +191,7 @@
|
|
121
191
|
|
122
192
|
*Yves Senn*
|
123
193
|
|
124
|
-
*
|
194
|
+
* Fix a regression where whitespaces were stripped from DISTINCT queries in
|
125
195
|
PostgreSQL.
|
126
196
|
|
127
197
|
*Agis Anastasopoulos*
|
@@ -135,7 +205,7 @@
|
|
135
205
|
|
136
206
|
*Agis Anastasopoulos*
|
137
207
|
|
138
|
-
*
|
208
|
+
* Fix `Relation#exists?` to work with polymorphic associations.
|
139
209
|
|
140
210
|
Fixes #15821.
|
141
211
|
|
@@ -157,7 +227,7 @@
|
|
157
227
|
|
158
228
|
*arthurnn*
|
159
229
|
|
160
|
-
*
|
230
|
+
* Fix an issue where custom accessor methods (such as those generated by
|
161
231
|
`enum`) with the same name as a global method are incorrectly overridden
|
162
232
|
when subclassing.
|
163
233
|
|
@@ -221,7 +291,7 @@
|
|
221
291
|
|
222
292
|
*Yves Senn*
|
223
293
|
|
224
|
-
*
|
294
|
+
* Fix automatic maintaining test schema to properly handle sql structure
|
225
295
|
schema format.
|
226
296
|
|
227
297
|
Fixes #15394.
|
@@ -384,8 +454,8 @@
|
|
384
454
|
|
385
455
|
*Sean Griffin*
|
386
456
|
|
387
|
-
*
|
388
|
-
(Call to `count`
|
457
|
+
* Fix an error in `reset_counters` when associations have `select` scope.
|
458
|
+
(Call to `count` generated invalid SQL.)
|
389
459
|
|
390
460
|
*Cade Truitt*
|
391
461
|
|
@@ -610,7 +680,7 @@
|
|
610
680
|
|
611
681
|
*Yves Senn*
|
612
682
|
|
613
|
-
*
|
683
|
+
* Fix `columns_for_distinct` of PostgreSQL adapter to work correctly
|
614
684
|
with orders without sort direction modifiers.
|
615
685
|
|
616
686
|
*Nikolay Kondratyev*
|
@@ -646,7 +716,7 @@
|
|
646
716
|
|
647
717
|
*arthurnn*
|
648
718
|
|
649
|
-
*
|
719
|
+
* Fix serialization for records with an attribute named `format`.
|
650
720
|
|
651
721
|
Fixes #15188.
|
652
722
|
|
@@ -657,12 +727,12 @@
|
|
657
727
|
|
658
728
|
*Kuldeep Aggarwal*
|
659
729
|
|
660
|
-
*
|
730
|
+
* Fix serialized fields returning serialized data after being updated with
|
661
731
|
`update_column`.
|
662
732
|
|
663
733
|
*Simon Hørup Eskildsen*
|
664
734
|
|
665
|
-
*
|
735
|
+
* Fix polymorphic eager loading when using a String as foreign key.
|
666
736
|
|
667
737
|
Fixes #14734.
|
668
738
|
|
@@ -676,7 +746,7 @@
|
|
676
746
|
|
677
747
|
*Brock Trappitt*
|
678
748
|
|
679
|
-
*
|
749
|
+
* Fix the inferred table name of a `has_and_belongs_to_many` auxiliary
|
680
750
|
table inside a schema.
|
681
751
|
|
682
752
|
Fixes #14824.
|
@@ -788,7 +858,7 @@
|
|
788
858
|
|
789
859
|
*Yves Senn*
|
790
860
|
|
791
|
-
*
|
861
|
+
* Fix `has_and_belongs_to_many` CollectionAssociation size calculations.
|
792
862
|
|
793
863
|
`has_and_belongs_to_many` should fall back to using the normal CollectionAssociation's
|
794
864
|
size calculation if the collection is not cached or loaded.
|
@@ -893,10 +963,12 @@
|
|
893
963
|
|
894
964
|
*Earl St Sauver*
|
895
965
|
|
896
|
-
*
|
966
|
+
* Fix unexpected behavior for `has_many :through` associations going through
|
967
|
+
a scoped `has_many`.
|
897
968
|
|
898
|
-
If a `has_many` association is adjusted using a scope, and another
|
899
|
-
uses this association, then the scope adjustment is
|
969
|
+
If a `has_many` association is adjusted using a scope, and another
|
970
|
+
`has_many :through` uses this association, then the scope adjustment is
|
971
|
+
unexpectedly neglected.
|
900
972
|
|
901
973
|
Fixes #14537.
|
902
974
|
|
@@ -906,13 +978,13 @@
|
|
906
978
|
|
907
979
|
*Kuldeep Aggarwal*
|
908
980
|
|
909
|
-
*
|
981
|
+
* Enable `has_many` associations to support irregular inflections.
|
910
982
|
|
911
983
|
Fixes #8928.
|
912
984
|
|
913
985
|
*arthurnn*, *Javier Goizueta*
|
914
986
|
|
915
|
-
*
|
987
|
+
* Fix `count` used with a grouping not returning a Hash.
|
916
988
|
|
917
989
|
Fixes #14721.
|
918
990
|
|
@@ -967,8 +1039,8 @@
|
|
967
1039
|
|
968
1040
|
*Eileen M. Uchitelle*, *Aaron Patterson*
|
969
1041
|
|
970
|
-
*
|
971
|
-
|
1042
|
+
* Fix invalid SQL when aggregate methods (`empty?`, `any?`, `count`) used
|
1043
|
+
with `select`.
|
972
1044
|
|
973
1045
|
Fixes #13648.
|
974
1046
|
|
@@ -999,8 +1071,8 @@
|
|
999
1071
|
|
1000
1072
|
*Roderick van Domburg*
|
1001
1073
|
|
1002
|
-
*
|
1003
|
-
|
1074
|
+
* Fix a problem where an enum would overwrite values of another enum with the
|
1075
|
+
same name in an unrelated class.
|
1004
1076
|
|
1005
1077
|
Fixes #14607.
|
1006
1078
|
|
@@ -1035,7 +1107,7 @@
|
|
1035
1107
|
|
1036
1108
|
*arthurnn*
|
1037
1109
|
|
1038
|
-
*
|
1110
|
+
* Fix error when using `with_options` with lambda.
|
1039
1111
|
|
1040
1112
|
Fixes #9805.
|
1041
1113
|
|
@@ -1073,14 +1145,15 @@
|
|
1073
1145
|
|
1074
1146
|
*Yves Senn*
|
1075
1147
|
|
1076
|
-
*
|
1148
|
+
* Fix error when specifying a non-empty default value on a PostgreSQL array
|
1149
|
+
column.
|
1077
1150
|
|
1078
1151
|
Fixes #10613.
|
1079
1152
|
|
1080
1153
|
*Luke Steensen*
|
1081
1154
|
|
1082
|
-
*
|
1083
|
-
custom primary key that
|
1155
|
+
* Fix error where `.persisted?` throws SystemStackError for an unsaved model with a
|
1156
|
+
custom primary key that did not save due to validation error.
|
1084
1157
|
|
1085
1158
|
Fixes #14393.
|
1086
1159
|
|
@@ -1173,7 +1246,8 @@
|
|
1173
1246
|
|
1174
1247
|
*Aaron Patterson*
|
1175
1248
|
|
1176
|
-
* Only use BINARY for MySQL case sensitive uniqueness check when column
|
1249
|
+
* Only use BINARY for MySQL case sensitive uniqueness check when column
|
1250
|
+
has a case insensitive collation.
|
1177
1251
|
|
1178
1252
|
*Ryuta Kamizono*
|
1179
1253
|
|
@@ -1181,8 +1255,8 @@
|
|
1181
1255
|
|
1182
1256
|
*arthurnn*, *Tatsuhiko Miyagawa*
|
1183
1257
|
|
1184
|
-
* Support for
|
1185
|
-
|
1258
|
+
* Support for PostgreSQL `citext` data type enabling case-insensitive
|
1259
|
+
`where` values without needing to wrap in UPPER/LOWER sql functions.
|
1186
1260
|
|
1187
1261
|
*Troy Kruthoff*, *Lachlan Sylvester*
|
1188
1262
|
|
@@ -1212,9 +1286,8 @@
|
|
1212
1286
|
|
1213
1287
|
*Aaron Patterson*, *Yves Senn*
|
1214
1288
|
|
1215
|
-
*
|
1216
|
-
|
1217
|
-
uniqueness validation.
|
1289
|
+
* Fix error with validation with enum fields for records where the value for
|
1290
|
+
any enum attribute is always evaluated as 0 during uniqueness validation.
|
1218
1291
|
|
1219
1292
|
Fixes #14172.
|
1220
1293
|
|
@@ -1228,8 +1301,8 @@
|
|
1228
1301
|
|
1229
1302
|
Fixes #14144.
|
1230
1303
|
|
1231
|
-
*
|
1232
|
-
|
1304
|
+
* Fix STI classes not defining an attribute method if there is a conflicting
|
1305
|
+
private method defined on its ancestors.
|
1233
1306
|
|
1234
1307
|
Fixes #11569.
|
1235
1308
|
|
@@ -230,8 +230,8 @@ module ActiveRecord
|
|
230
230
|
private
|
231
231
|
def reader_method(name, class_name, mapping, allow_nil, constructor)
|
232
232
|
define_method(name) do
|
233
|
-
if @aggregation_cache[name].nil? && (!allow_nil || mapping.any? {|key, _| !
|
234
|
-
attrs = mapping.collect {|key, _|
|
233
|
+
if @aggregation_cache[name].nil? && (!allow_nil || mapping.any? {|key, _| !_read_attribute(key).nil? })
|
234
|
+
attrs = mapping.collect {|key, _| _read_attribute(key)}
|
235
235
|
object = constructor.respond_to?(:call) ?
|
236
236
|
constructor.call(*attrs) :
|
237
237
|
class_name.constantize.send(constructor, *attrs)
|
@@ -1700,7 +1700,7 @@ module ActiveRecord
|
|
1700
1700
|
hm_options[:through] = middle_reflection.name
|
1701
1701
|
hm_options[:source] = join_model.right_reflection.name
|
1702
1702
|
|
1703
|
-
[:before_add, :after_add, :before_remove, :after_remove, :autosave, :validate, :join_table].each do |k|
|
1703
|
+
[:before_add, :after_add, :before_remove, :after_remove, :autosave, :validate, :join_table, :class_name].each do |k|
|
1704
1704
|
hm_options[k] = options[k] if options.key? k
|
1705
1705
|
end
|
1706
1706
|
|
@@ -57,20 +57,10 @@ module ActiveRecord
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def aliased_table_for(table_name, aliased_name)
|
60
|
-
table_alias = aliased_name_for(table_name, aliased_name)
|
61
|
-
|
62
|
-
if table_alias == table_name
|
63
|
-
Arel::Table.new(table_name)
|
64
|
-
else
|
65
|
-
Arel::Table.new(table_name).alias(table_alias)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def aliased_name_for(table_name, aliased_name)
|
70
60
|
if aliases[table_name].zero?
|
71
61
|
# If it's zero, we can have our table_name
|
72
62
|
aliases[table_name] = 1
|
73
|
-
table_name
|
63
|
+
Arel::Table.new(table_name)
|
74
64
|
else
|
75
65
|
# Otherwise, we need to use an alias
|
76
66
|
aliased_name = connection.table_alias_for(aliased_name)
|
@@ -78,11 +68,12 @@ module ActiveRecord
|
|
78
68
|
# Update the count
|
79
69
|
aliases[aliased_name] += 1
|
80
70
|
|
81
|
-
if aliases[aliased_name] > 1
|
71
|
+
table_alias = if aliases[aliased_name] > 1
|
82
72
|
"#{truncate(aliased_name)}_#{aliases[aliased_name]}"
|
83
73
|
else
|
84
74
|
aliased_name
|
85
75
|
end
|
76
|
+
Arel::Table.new(table_name).alias(table_alias)
|
86
77
|
end
|
87
78
|
end
|
88
79
|
|
@@ -11,8 +11,7 @@ module ActiveRecord
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def bind_value(scope, column, value, alias_tracker)
|
14
|
-
substitute = alias_tracker.connection.substitute_at(
|
15
|
-
column, scope.bind_values.length)
|
14
|
+
substitute = alias_tracker.connection.substitute_at(column)
|
16
15
|
scope.bind_values += [[column, @block.call(value)]]
|
17
16
|
substitute
|
18
17
|
end
|
@@ -98,7 +98,7 @@ module ActiveRecord::Associations::Builder
|
|
98
98
|
|
99
99
|
def middle_options(join_model)
|
100
100
|
middle_options = {}
|
101
|
-
middle_options[:
|
101
|
+
middle_options[:class_name] = "#{lhs_model.name}::#{join_model.name}"
|
102
102
|
middle_options[:source] = join_model.left_reflection.name
|
103
103
|
if options.key? :foreign_key
|
104
104
|
middle_options[:foreign_key] = options[:foreign_key]
|
@@ -110,7 +110,7 @@ module ActiveRecord::Associations::Builder
|
|
110
110
|
rhs_options = {}
|
111
111
|
|
112
112
|
if options.key? :class_name
|
113
|
-
rhs_options[:foreign_key] = options[:class_name].foreign_key
|
113
|
+
rhs_options[:foreign_key] = options[:class_name].to_s.foreign_key
|
114
114
|
rhs_options[:class_name] = options[:class_name]
|
115
115
|
end
|
116
116
|
|
@@ -33,7 +33,13 @@ module ActiveRecord
|
|
33
33
|
reload
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
if owner.new_record?
|
37
|
+
# Cache the proxy separately before the owner has an id
|
38
|
+
# or else a post-save proxy will still lack the id
|
39
|
+
@new_record_proxy ||= CollectionProxy.create(klass, self)
|
40
|
+
else
|
41
|
+
@proxy ||= CollectionProxy.create(klass, self)
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
# Implements the writer method, e.g. foo.items= for Foo.has_many :items
|
@@ -169,8 +175,8 @@ module ActiveRecord
|
|
169
175
|
end
|
170
176
|
|
171
177
|
# Removes all records from the association without calling callbacks
|
172
|
-
# on the associated records. It honors the
|
173
|
-
# if the
|
178
|
+
# on the associated records. It honors the +:dependent+ option. However
|
179
|
+
# if the +:dependent+ value is +:destroy+ then in that case the +:delete_all+
|
174
180
|
# deletion strategy for the association is applied.
|
175
181
|
#
|
176
182
|
# You can force a particular deletion strategy by passing a parameter.
|
@@ -352,6 +358,7 @@ module ActiveRecord
|
|
352
358
|
if owner.new_record?
|
353
359
|
replace_records(other_array, original_target)
|
354
360
|
else
|
361
|
+
replace_common_records_in_memory(other_array, original_target)
|
355
362
|
if other_array != original_target
|
356
363
|
transaction { replace_records(other_array, original_target) }
|
357
364
|
end
|
@@ -379,11 +386,18 @@ module ActiveRecord
|
|
379
386
|
target
|
380
387
|
end
|
381
388
|
|
382
|
-
def add_to_target(record, skip_callbacks = false)
|
389
|
+
def add_to_target(record, skip_callbacks = false, &block)
|
390
|
+
if association_scope.distinct_value
|
391
|
+
index = @target.index(record)
|
392
|
+
end
|
393
|
+
replace_on_target(record, index, skip_callbacks, &block)
|
394
|
+
end
|
395
|
+
|
396
|
+
def replace_on_target(record, index, skip_callbacks)
|
383
397
|
callback(:before_add, record) unless skip_callbacks
|
384
398
|
yield(record) if block_given?
|
385
399
|
|
386
|
-
if
|
400
|
+
if index
|
387
401
|
@target[index] = record
|
388
402
|
else
|
389
403
|
@target << record
|
@@ -409,7 +423,8 @@ module ActiveRecord
|
|
409
423
|
def get_records
|
410
424
|
if reflection.scope_chain.any?(&:any?) ||
|
411
425
|
scope.eager_loading? ||
|
412
|
-
klass.current_scope
|
426
|
+
klass.current_scope ||
|
427
|
+
klass.default_scopes.any?
|
413
428
|
|
414
429
|
return scope.to_a
|
415
430
|
end
|
@@ -527,6 +542,14 @@ module ActiveRecord
|
|
527
542
|
target
|
528
543
|
end
|
529
544
|
|
545
|
+
def replace_common_records_in_memory(new_target, original_target)
|
546
|
+
common_records = new_target & original_target
|
547
|
+
common_records.each do |record|
|
548
|
+
skip_callbacks = true
|
549
|
+
replace_on_target(record, @target.index(record), skip_callbacks)
|
550
|
+
end
|
551
|
+
end
|
552
|
+
|
530
553
|
def concat_records(records, should_raise = false)
|
531
554
|
result = true
|
532
555
|
|