activerecord 6.0.0 → 6.0.3
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 +4 -4
- data/CHANGELOG.md +185 -1
- data/README.rdoc +1 -1
- data/lib/active_record.rb +1 -0
- data/lib/active_record/advisory_lock_base.rb +18 -0
- data/lib/active_record/aggregations.rb +0 -1
- data/lib/active_record/association_relation.rb +10 -8
- data/lib/active_record/associations.rb +2 -2
- data/lib/active_record/associations/alias_tracker.rb +0 -1
- data/lib/active_record/associations/association.rb +5 -1
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +0 -2
- data/lib/active_record/associations/collection_association.rb +6 -2
- data/lib/active_record/associations/collection_proxy.rb +1 -2
- data/lib/active_record/associations/has_many_association.rb +0 -1
- data/lib/active_record/associations/join_dependency.rb +13 -0
- data/lib/active_record/associations/join_dependency/join_association.rb +1 -1
- data/lib/active_record/associations/preloader.rb +2 -3
- data/lib/active_record/attribute_assignment.rb +0 -1
- data/lib/active_record/attribute_decorators.rb +0 -2
- data/lib/active_record/attribute_methods/before_type_cast.rb +0 -1
- data/lib/active_record/attribute_methods/dirty.rb +2 -2
- data/lib/active_record/attribute_methods/primary_key.rb +0 -2
- data/lib/active_record/attribute_methods/read.rb +0 -1
- data/lib/active_record/attribute_methods/serialization.rb +0 -1
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +0 -2
- data/lib/active_record/attribute_methods/write.rb +0 -1
- data/lib/active_record/attributes.rb +0 -1
- data/lib/active_record/autosave_association.rb +8 -6
- data/lib/active_record/callbacks.rb +1 -2
- data/lib/active_record/coders/yaml_column.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +14 -7
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +21 -15
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +2 -2
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +1 -2
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +27 -27
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +47 -30
- data/lib/active_record/connection_adapters/abstract/transaction.rb +4 -5
- data/lib/active_record/connection_adapters/abstract_adapter.rb +23 -8
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +25 -32
- data/lib/active_record/connection_adapters/connection_specification.rb +2 -3
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +8 -12
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +0 -1
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +8 -8
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +9 -3
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +15 -29
- data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -2
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +8 -7
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +0 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +3 -3
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +12 -7
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_handling.rb +13 -22
- data/lib/active_record/core.rb +8 -6
- data/lib/active_record/counter_cache.rb +4 -1
- data/lib/active_record/database_configurations/url_config.rb +0 -1
- data/lib/active_record/dynamic_matchers.rb +2 -3
- data/lib/active_record/explain.rb +0 -1
- data/lib/active_record/fixture_set/table_row.rb +0 -1
- data/lib/active_record/fixture_set/table_rows.rb +0 -1
- data/lib/active_record/fixtures.rb +0 -3
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/inheritance.rb +0 -3
- data/lib/active_record/insert_all.rb +4 -4
- data/lib/active_record/internal_metadata.rb +1 -1
- data/lib/active_record/locking/optimistic.rb +0 -1
- data/lib/active_record/log_subscriber.rb +1 -1
- data/lib/active_record/middleware/database_selector.rb +0 -1
- data/lib/active_record/middleware/database_selector/resolver.rb +9 -14
- data/lib/active_record/migration.rb +4 -4
- data/lib/active_record/migration/command_recorder.rb +6 -18
- data/lib/active_record/migration/compatibility.rb +3 -3
- data/lib/active_record/migration/join_table.rb +0 -1
- data/lib/active_record/model_schema.rb +3 -2
- data/lib/active_record/nested_attributes.rb +0 -2
- data/lib/active_record/no_touching.rb +2 -2
- data/lib/active_record/null_relation.rb +0 -1
- data/lib/active_record/persistence.rb +4 -5
- data/lib/active_record/querying.rb +1 -1
- data/lib/active_record/railtie.rb +1 -1
- data/lib/active_record/railties/collection_cache_association_loading.rb +1 -1
- data/lib/active_record/railties/databases.rake +3 -0
- data/lib/active_record/reflection.rb +8 -8
- data/lib/active_record/relation.rb +13 -1
- data/lib/active_record/relation/batches.rb +0 -1
- data/lib/active_record/relation/calculations.rb +1 -1
- data/lib/active_record/relation/delegation.rb +7 -6
- data/lib/active_record/relation/finder_methods.rb +10 -2
- data/lib/active_record/relation/from_clause.rb +4 -0
- data/lib/active_record/relation/merger.rb +0 -1
- data/lib/active_record/relation/predicate_builder.rb +1 -5
- data/lib/active_record/relation/query_methods.rb +37 -12
- data/lib/active_record/relation/spawn_methods.rb +0 -1
- data/lib/active_record/relation/where_clause.rb +0 -1
- data/lib/active_record/result.rb +0 -1
- data/lib/active_record/schema_migration.rb +1 -1
- data/lib/active_record/scoping.rb +0 -1
- data/lib/active_record/scoping/default.rb +0 -1
- data/lib/active_record/scoping/named.rb +3 -3
- data/lib/active_record/store.rb +1 -1
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +16 -1
- data/lib/active_record/tasks/mysql_database_tasks.rb +0 -1
- data/lib/active_record/tasks/postgresql_database_tasks.rb +0 -1
- data/lib/active_record/tasks/sqlite_database_tasks.rb +0 -1
- data/lib/active_record/test_fixtures.rb +2 -1
- data/lib/active_record/timestamp.rb +0 -1
- data/lib/active_record/touch_later.rb +1 -2
- data/lib/active_record/transactions.rb +9 -9
- data/lib/active_record/type.rb +0 -1
- data/lib/active_record/type/adapter_specific_registry.rb +2 -5
- data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
- data/lib/active_record/type/serialized.rb +0 -1
- data/lib/active_record/type/type_map.rb +0 -1
- data/lib/active_record/type/unsigned_integer.rb +0 -1
- data/lib/active_record/validations.rb +2 -3
- data/lib/active_record/validations/associated.rb +1 -2
- data/lib/arel.rb +17 -6
- data/lib/arel/predications.rb +5 -6
- data/lib/arel/visitors/depth_first.rb +0 -1
- data/lib/arel/visitors/dot.rb +0 -1
- data/lib/arel/visitors/mssql.rb +0 -1
- data/lib/arel/visitors/oracle.rb +1 -2
- data/lib/arel/visitors/oracle12.rb +0 -1
- data/lib/arel/visitors/postgresql.rb +0 -1
- data/lib/arel/visitors/sqlite.rb +0 -1
- data/lib/arel/visitors/to_sql.rb +0 -1
- data/lib/arel/visitors/visitor.rb +0 -1
- data/lib/arel/visitors/where_sql.rb +0 -1
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
- data/lib/rails/generators/active_record/migration.rb +0 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +0 -1
- metadata +13 -9
|
@@ -67,7 +67,7 @@ module ActiveRecord
|
|
|
67
67
|
|
|
68
68
|
attributes.flat_map do |key, value|
|
|
69
69
|
if value.is_a?(Hash) && !table.has_column?(key)
|
|
70
|
-
associated_predicate_builder(key).expand_from_hash(value)
|
|
70
|
+
table.associated_predicate_builder(key).expand_from_hash(value)
|
|
71
71
|
elsif table.associated_with?(key)
|
|
72
72
|
# Find the foreign key when using queries such as:
|
|
73
73
|
# Post.where(author: author)
|
|
@@ -114,10 +114,6 @@ module ActiveRecord
|
|
|
114
114
|
private
|
|
115
115
|
attr_reader :table
|
|
116
116
|
|
|
117
|
-
def associated_predicate_builder(association_name)
|
|
118
|
-
self.class.new(table.associated_table(association_name))
|
|
119
|
-
end
|
|
120
|
-
|
|
121
117
|
def convert_dot_notation_to_hash(attributes)
|
|
122
118
|
dot_notation = attributes.select do |k, v|
|
|
123
119
|
k.include?(".") && !v.is_a?(Hash)
|
|
@@ -51,8 +51,16 @@ module ActiveRecord
|
|
|
51
51
|
if not_behaves_as_nor?(opts)
|
|
52
52
|
ActiveSupport::Deprecation.warn(<<~MSG.squish)
|
|
53
53
|
NOT conditions will no longer behave as NOR in Rails 6.1.
|
|
54
|
-
To continue using NOR conditions, NOT each
|
|
55
|
-
(`#{
|
|
54
|
+
To continue using NOR conditions, NOT each condition individually
|
|
55
|
+
(`#{
|
|
56
|
+
opts.flat_map { |key, value|
|
|
57
|
+
if value.is_a?(Hash) && value.size > 1
|
|
58
|
+
value.map { |k, v| ".where.not(#{key.inspect} => { #{k.inspect} => ... })" }
|
|
59
|
+
else
|
|
60
|
+
".where.not(#{key.inspect} => ...)"
|
|
61
|
+
end
|
|
62
|
+
}.join
|
|
63
|
+
}`).
|
|
56
64
|
MSG
|
|
57
65
|
@scope.where_clause += where_clause.invert(:nor)
|
|
58
66
|
else
|
|
@@ -64,7 +72,10 @@ module ActiveRecord
|
|
|
64
72
|
|
|
65
73
|
private
|
|
66
74
|
def not_behaves_as_nor?(opts)
|
|
67
|
-
opts.is_a?(Hash)
|
|
75
|
+
return false unless opts.is_a?(Hash)
|
|
76
|
+
|
|
77
|
+
opts.any? { |k, v| v.is_a?(Hash) && v.size > 1 } ||
|
|
78
|
+
opts.size > 1
|
|
68
79
|
end
|
|
69
80
|
end
|
|
70
81
|
|
|
@@ -157,7 +168,7 @@ module ActiveRecord
|
|
|
157
168
|
end
|
|
158
169
|
|
|
159
170
|
def eager_load!(*args) # :nodoc:
|
|
160
|
-
self.eager_load_values
|
|
171
|
+
self.eager_load_values |= args
|
|
161
172
|
self
|
|
162
173
|
end
|
|
163
174
|
|
|
@@ -171,7 +182,7 @@ module ActiveRecord
|
|
|
171
182
|
end
|
|
172
183
|
|
|
173
184
|
def preload!(*args) # :nodoc:
|
|
174
|
-
self.preload_values
|
|
185
|
+
self.preload_values |= args
|
|
175
186
|
self
|
|
176
187
|
end
|
|
177
188
|
|
|
@@ -320,7 +331,7 @@ module ActiveRecord
|
|
|
320
331
|
def group!(*args) # :nodoc:
|
|
321
332
|
args.flatten!
|
|
322
333
|
|
|
323
|
-
self.group_values
|
|
334
|
+
self.group_values |= args
|
|
324
335
|
self
|
|
325
336
|
end
|
|
326
337
|
|
|
@@ -488,7 +499,7 @@ module ActiveRecord
|
|
|
488
499
|
def joins!(*args) # :nodoc:
|
|
489
500
|
args.compact!
|
|
490
501
|
args.flatten!
|
|
491
|
-
self.joins_values
|
|
502
|
+
self.joins_values |= args
|
|
492
503
|
self
|
|
493
504
|
end
|
|
494
505
|
|
|
@@ -506,7 +517,7 @@ module ActiveRecord
|
|
|
506
517
|
def left_outer_joins!(*args) # :nodoc:
|
|
507
518
|
args.compact!
|
|
508
519
|
args.flatten!
|
|
509
|
-
self.left_outer_joins_values
|
|
520
|
+
self.left_outer_joins_values |= args
|
|
510
521
|
self
|
|
511
522
|
end
|
|
512
523
|
|
|
@@ -1083,15 +1094,23 @@ module ActiveRecord
|
|
|
1083
1094
|
end
|
|
1084
1095
|
end
|
|
1085
1096
|
|
|
1086
|
-
def
|
|
1097
|
+
def select_association_list(associations)
|
|
1098
|
+
result = []
|
|
1087
1099
|
associations.each do |association|
|
|
1088
1100
|
case association
|
|
1089
1101
|
when Hash, Symbol, Array
|
|
1090
|
-
|
|
1102
|
+
result << association
|
|
1091
1103
|
else
|
|
1092
|
-
|
|
1104
|
+
yield if block_given?
|
|
1093
1105
|
end
|
|
1094
1106
|
end
|
|
1107
|
+
result
|
|
1108
|
+
end
|
|
1109
|
+
|
|
1110
|
+
def valid_association_list(associations)
|
|
1111
|
+
select_association_list(associations) do
|
|
1112
|
+
raise ArgumentError, "only Hash, Symbol and Array are allowed"
|
|
1113
|
+
end
|
|
1095
1114
|
end
|
|
1096
1115
|
|
|
1097
1116
|
def build_left_outer_joins(manager, outer_joins, aliases)
|
|
@@ -1108,6 +1127,10 @@ module ActiveRecord
|
|
|
1108
1127
|
buckets[:stashed_join] << construct_join_dependency(left_joins, Arel::Nodes::OuterJoin)
|
|
1109
1128
|
end
|
|
1110
1129
|
|
|
1130
|
+
if joins.last.is_a?(ActiveRecord::Associations::JoinDependency)
|
|
1131
|
+
buckets[:stashed_join] << joins.pop if joins.last.base_klass == klass
|
|
1132
|
+
end
|
|
1133
|
+
|
|
1111
1134
|
joins.map! do |join|
|
|
1112
1135
|
if join.is_a?(String)
|
|
1113
1136
|
table.create_string_join(Arel.sql(join.strip)) unless join.blank?
|
|
@@ -1198,7 +1221,9 @@ module ActiveRecord
|
|
|
1198
1221
|
end
|
|
1199
1222
|
|
|
1200
1223
|
def table_name_matches?(from)
|
|
1201
|
-
|
|
1224
|
+
table_name = Regexp.escape(table.name)
|
|
1225
|
+
quoted_table_name = Regexp.escape(connection.quote_table_name(table.name))
|
|
1226
|
+
/(?:\A|(?<!FROM)\s)(?:\b#{table_name}\b|#{quoted_table_name})(?!\.)/i.match?(from.to_s)
|
|
1202
1227
|
end
|
|
1203
1228
|
|
|
1204
1229
|
def reverse_sql_order(order_query)
|
data/lib/active_record/result.rb
CHANGED
|
@@ -95,7 +95,6 @@ module ActiveRecord
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
private
|
|
98
|
-
|
|
99
98
|
def raise_invalid_scope_type!(scope_type)
|
|
100
99
|
if !VALID_SCOPE_TYPES.include?(scope_type)
|
|
101
100
|
raise ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. Scope types must be included in VALID_SCOPE_TYPES"
|
|
@@ -31,7 +31,7 @@ module ActiveRecord
|
|
|
31
31
|
ActiveSupport::Deprecation.warn(<<~MSG.squish)
|
|
32
32
|
Class level methods will no longer inherit scoping from `#{scope._deprecated_scope_source}`
|
|
33
33
|
in Rails 6.1. To continue using the scoped relation, pass it into the block directly.
|
|
34
|
-
To instead access the full set of models, as Rails 6.1 will, use `#{name}.
|
|
34
|
+
To instead access the full set of models, as Rails 6.1 will, use `#{name}.default_scoped`.
|
|
35
35
|
MSG
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -53,7 +53,8 @@ module ActiveRecord
|
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
# Returns a scope for the model with default scopes.
|
|
57
|
+
def default_scoped(scope = relation)
|
|
57
58
|
build_default_scope(scope) || scope
|
|
58
59
|
end
|
|
59
60
|
|
|
@@ -204,7 +205,6 @@ module ActiveRecord
|
|
|
204
205
|
end
|
|
205
206
|
|
|
206
207
|
private
|
|
207
|
-
|
|
208
208
|
def valid_scope_name?(name)
|
|
209
209
|
if respond_to?(name, true) && logger
|
|
210
210
|
logger.warn "Creating scope :#{name}. " \
|
data/lib/active_record/store.rb
CHANGED
|
@@ -103,7 +103,7 @@ module ActiveRecord
|
|
|
103
103
|
module ClassMethods
|
|
104
104
|
def store(store_attribute, options = {})
|
|
105
105
|
serialize store_attribute, IndifferentCoder.new(store_attribute, options[:coder])
|
|
106
|
-
store_accessor(store_attribute, options[:accessors], options.slice(:prefix, :suffix)) if options.has_key? :accessors
|
|
106
|
+
store_accessor(store_attribute, options[:accessors], **options.slice(:prefix, :suffix)) if options.has_key? :accessors
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
def store_accessor(store_attribute, *keys, prefix: nil, suffix: nil)
|
|
@@ -40,11 +40,11 @@ module ActiveRecord
|
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def save(
|
|
43
|
+
def save(*, **) # :nodoc:
|
|
44
44
|
SuppressorRegistry.suppressed[self.class.name] ? true : super
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
def save!(
|
|
47
|
+
def save!(*, **) # :nodoc:
|
|
48
48
|
SuppressorRegistry.suppressed[self.class.name] ? true : super
|
|
49
49
|
end
|
|
50
50
|
end
|
|
@@ -45,7 +45,7 @@ module ActiveRecord
|
|
|
45
45
|
association = klass._reflect_on_association(table_name) || klass._reflect_on_association(table_name.to_s.singularize)
|
|
46
46
|
|
|
47
47
|
if !association && table_name == arel_table.name
|
|
48
|
-
|
|
48
|
+
self
|
|
49
49
|
elsif association && !association.polymorphic?
|
|
50
50
|
association_klass = association.klass
|
|
51
51
|
arel_table = association_klass.arel_table.alias(table_name)
|
|
@@ -57,6 +57,10 @@ module ActiveRecord
|
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
def associated_predicate_builder(table_name)
|
|
61
|
+
associated_table(table_name).predicate_builder
|
|
62
|
+
end
|
|
63
|
+
|
|
60
64
|
def polymorphic_association?
|
|
61
65
|
association && association.polymorphic?
|
|
62
66
|
end
|
|
@@ -69,6 +73,17 @@ module ActiveRecord
|
|
|
69
73
|
klass.reflect_on_aggregation(aggregation_name)
|
|
70
74
|
end
|
|
71
75
|
|
|
76
|
+
protected
|
|
77
|
+
def predicate_builder
|
|
78
|
+
if klass
|
|
79
|
+
predicate_builder = klass.predicate_builder.dup
|
|
80
|
+
predicate_builder.instance_variable_set(:@table, self)
|
|
81
|
+
predicate_builder
|
|
82
|
+
else
|
|
83
|
+
PredicateBuilder.new(self)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
72
87
|
private
|
|
73
88
|
attr_reader :klass, :types, :arel_table, :association
|
|
74
89
|
end
|
|
@@ -129,6 +129,7 @@ module ActiveRecord
|
|
|
129
129
|
# When connections are established in the future, begin a transaction too
|
|
130
130
|
@connection_subscriber = ActiveSupport::Notifications.subscribe("!connection.active_record") do |_, _, _, _, payload|
|
|
131
131
|
spec_name = payload[:spec_name] if payload.key?(:spec_name)
|
|
132
|
+
setup_shared_connection_pool
|
|
132
133
|
|
|
133
134
|
if spec_name
|
|
134
135
|
begin
|
|
@@ -179,7 +180,6 @@ module ActiveRecord
|
|
|
179
180
|
end
|
|
180
181
|
|
|
181
182
|
private
|
|
182
|
-
|
|
183
183
|
# Shares the writing connection pool with connections on
|
|
184
184
|
# other handlers.
|
|
185
185
|
#
|
|
@@ -194,6 +194,7 @@ module ActiveRecord
|
|
|
194
194
|
handler.connection_pool_list.each do |pool|
|
|
195
195
|
name = pool.spec.name
|
|
196
196
|
writing_connection = writing_handler.retrieve_connection_pool(name)
|
|
197
|
+
return unless writing_connection
|
|
197
198
|
handler.send(:owner_to_pool)[name] = writing_connection
|
|
198
199
|
end
|
|
199
200
|
end
|
|
@@ -9,7 +9,7 @@ module ActiveRecord
|
|
|
9
9
|
before_commit_without_transaction_enrollment :touch_deferred_attributes
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def touch_later(*names) # :nodoc:
|
|
12
|
+
def touch_later(*names, **) # :nodoc:
|
|
13
13
|
unless persisted?
|
|
14
14
|
raise ActiveRecordError, <<-MSG.squish
|
|
15
15
|
cannot touch on a new or destroyed record object. Consider using
|
|
@@ -41,7 +41,6 @@ module ActiveRecord
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
private
|
|
44
|
-
|
|
45
44
|
def surreptitiously_touch(attrs)
|
|
46
45
|
attrs.each { |attr| write_attribute attr, @_touch_time }
|
|
47
46
|
clear_attribute_changes attrs
|
|
@@ -208,8 +208,8 @@ module ActiveRecord
|
|
|
208
208
|
# Note that "TRUNCATE" is also a MySQL DDL statement!
|
|
209
209
|
module ClassMethods
|
|
210
210
|
# See the ConnectionAdapters::DatabaseStatements#transaction API docs.
|
|
211
|
-
def transaction(options
|
|
212
|
-
connection.transaction(options, &block)
|
|
211
|
+
def transaction(**options, &block)
|
|
212
|
+
connection.transaction(**options, &block)
|
|
213
213
|
end
|
|
214
214
|
|
|
215
215
|
def before_commit(*args, &block) # :nodoc:
|
|
@@ -282,7 +282,6 @@ module ActiveRecord
|
|
|
282
282
|
end
|
|
283
283
|
|
|
284
284
|
private
|
|
285
|
-
|
|
286
285
|
def set_options_for_callbacks!(args, enforced_options = {})
|
|
287
286
|
options = args.extract_options!.merge!(enforced_options)
|
|
288
287
|
args << options
|
|
@@ -304,22 +303,22 @@ module ActiveRecord
|
|
|
304
303
|
|
|
305
304
|
# See ActiveRecord::Transactions::ClassMethods for detailed documentation.
|
|
306
305
|
def transaction(options = {}, &block)
|
|
307
|
-
self.class.transaction(options, &block)
|
|
306
|
+
self.class.transaction(**options, &block)
|
|
308
307
|
end
|
|
309
308
|
|
|
310
309
|
def destroy #:nodoc:
|
|
311
310
|
with_transaction_returning_status { super }
|
|
312
311
|
end
|
|
313
312
|
|
|
314
|
-
def save(
|
|
313
|
+
def save(*, **) #:nodoc:
|
|
315
314
|
with_transaction_returning_status { super }
|
|
316
315
|
end
|
|
317
316
|
|
|
318
|
-
def save!(
|
|
317
|
+
def save!(*, **) #:nodoc:
|
|
319
318
|
with_transaction_returning_status { super }
|
|
320
319
|
end
|
|
321
320
|
|
|
322
|
-
def touch(
|
|
321
|
+
def touch(*, **) #:nodoc:
|
|
323
322
|
with_transaction_returning_status { super }
|
|
324
323
|
end
|
|
325
324
|
|
|
@@ -333,14 +332,14 @@ module ActiveRecord
|
|
|
333
332
|
# Ensure that it is not called if the object was never persisted (failed create),
|
|
334
333
|
# but call it after the commit of a destroyed object.
|
|
335
334
|
def committed!(should_run_callbacks: true) #:nodoc:
|
|
335
|
+
force_clear_transaction_record_state
|
|
336
336
|
if should_run_callbacks
|
|
337
337
|
@_committed_already_called = true
|
|
338
338
|
_run_commit_without_transaction_enrollment_callbacks
|
|
339
339
|
_run_commit_callbacks
|
|
340
340
|
end
|
|
341
341
|
ensure
|
|
342
|
-
@_committed_already_called = false
|
|
343
|
-
force_clear_transaction_record_state
|
|
342
|
+
@_committed_already_called = @_trigger_update_callback = @_trigger_destroy_callback = false
|
|
344
343
|
end
|
|
345
344
|
|
|
346
345
|
# Call the #after_rollback callbacks. The +force_restore_state+ argument indicates if the record
|
|
@@ -353,6 +352,7 @@ module ActiveRecord
|
|
|
353
352
|
ensure
|
|
354
353
|
restore_transaction_record_state(force_restore_state)
|
|
355
354
|
clear_transaction_record_state
|
|
355
|
+
@_trigger_update_callback = @_trigger_destroy_callback = false if force_restore_state
|
|
356
356
|
end
|
|
357
357
|
|
|
358
358
|
# Executes +method+ within a transaction and captures its return value as a
|