activerecord 6.0.0 → 6.0.3
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 +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
@@ -568,7 +568,6 @@ module ActiveRecord
|
|
568
568
|
end
|
569
569
|
|
570
570
|
private
|
571
|
-
|
572
571
|
def connection
|
573
572
|
ActiveRecord::Base.connection
|
574
573
|
end
|
@@ -619,6 +618,7 @@ module ActiveRecord
|
|
619
618
|
def method_missing(name, *args, &block) #:nodoc:
|
620
619
|
nearest_delegate.send(name, *args, &block)
|
621
620
|
end
|
621
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
622
622
|
|
623
623
|
def migrate(direction)
|
624
624
|
new.migrate direction
|
@@ -890,6 +890,7 @@ module ActiveRecord
|
|
890
890
|
connection.send(method, *arguments, &block)
|
891
891
|
end
|
892
892
|
end
|
893
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
893
894
|
|
894
895
|
def copy(destination, sources, options = {})
|
895
896
|
copied = []
|
@@ -1001,7 +1002,6 @@ module ActiveRecord
|
|
1001
1002
|
delegate :migrate, :announce, :write, :disable_ddl_transaction, to: :migration
|
1002
1003
|
|
1003
1004
|
private
|
1004
|
-
|
1005
1005
|
def migration
|
1006
1006
|
@migration ||= load_migration
|
1007
1007
|
end
|
@@ -1261,7 +1261,6 @@ module ActiveRecord
|
|
1261
1261
|
end
|
1262
1262
|
|
1263
1263
|
private
|
1264
|
-
|
1265
1264
|
# Used for running a specific migration.
|
1266
1265
|
def run_without_lock
|
1267
1266
|
migration = migrations.detect { |m| m.version == @target_version }
|
@@ -1375,7 +1374,8 @@ module ActiveRecord
|
|
1375
1374
|
|
1376
1375
|
def with_advisory_lock
|
1377
1376
|
lock_id = generate_migrator_advisory_lock_id
|
1378
|
-
|
1377
|
+
AdvisoryLockBase.establish_connection(ActiveRecord::Base.connection_config) unless AdvisoryLockBase.connected?
|
1378
|
+
connection = AdvisoryLockBase.connection
|
1379
1379
|
got_lock = connection.get_advisory_lock(lock_id)
|
1380
1380
|
raise ConcurrentMigrationError unless got_lock
|
1381
1381
|
load_migrated # reload schema_migrations to be sure it wasn't changed by another process before we got the lock
|
@@ -32,7 +32,8 @@ module ActiveRecord
|
|
32
32
|
# * rename_index
|
33
33
|
# * rename_table
|
34
34
|
class CommandRecorder
|
35
|
-
ReversibleAndIrreversibleMethods = [
|
35
|
+
ReversibleAndIrreversibleMethods = [
|
36
|
+
:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
|
36
37
|
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
|
37
38
|
:change_column_default, :add_reference, :remove_reference, :transaction,
|
38
39
|
:drop_join_table, :drop_table, :execute_block, :enable_extension, :disable_extension,
|
@@ -103,11 +104,12 @@ module ActiveRecord
|
|
103
104
|
record(:"#{method}", args, &block) # record(:create_table, args, &block)
|
104
105
|
end # end
|
105
106
|
EOV
|
107
|
+
ruby2_keywords(method) if respond_to?(:ruby2_keywords, true)
|
106
108
|
end
|
107
109
|
alias :add_belongs_to :add_reference
|
108
110
|
alias :remove_belongs_to :remove_reference
|
109
111
|
|
110
|
-
def change_table(table_name, options
|
112
|
+
def change_table(table_name, **options) # :nodoc:
|
111
113
|
yield delegate.update_table_definition(table_name, self)
|
112
114
|
end
|
113
115
|
|
@@ -118,7 +120,6 @@ module ActiveRecord
|
|
118
120
|
end
|
119
121
|
|
120
122
|
private
|
121
|
-
|
122
123
|
module StraightReversions # :nodoc:
|
123
124
|
private
|
124
125
|
{
|
@@ -128,6 +129,7 @@ module ActiveRecord
|
|
128
129
|
add_column: :remove_column,
|
129
130
|
add_timestamps: :remove_timestamps,
|
130
131
|
add_reference: :remove_reference,
|
132
|
+
add_foreign_key: :remove_foreign_key,
|
131
133
|
enable_extension: :disable_extension
|
132
134
|
}.each do |cmd, inv|
|
133
135
|
[[inv, cmd], [cmd, inv]].uniq.each do |method, inverse|
|
@@ -218,21 +220,6 @@ module ActiveRecord
|
|
218
220
|
[:change_column_null, args]
|
219
221
|
end
|
220
222
|
|
221
|
-
def invert_add_foreign_key(args)
|
222
|
-
from_table, to_table, add_options = args
|
223
|
-
add_options ||= {}
|
224
|
-
|
225
|
-
if add_options[:name]
|
226
|
-
options = { name: add_options[:name] }
|
227
|
-
elsif add_options[:column]
|
228
|
-
options = { column: add_options[:column] }
|
229
|
-
else
|
230
|
-
options = to_table
|
231
|
-
end
|
232
|
-
|
233
|
-
[:remove_foreign_key, [from_table, options]]
|
234
|
-
end
|
235
|
-
|
236
223
|
def invert_remove_foreign_key(args)
|
237
224
|
options = args.extract_options!
|
238
225
|
from_table, to_table = args
|
@@ -279,6 +266,7 @@ module ActiveRecord
|
|
279
266
|
super
|
280
267
|
end
|
281
268
|
end
|
269
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
282
270
|
end
|
283
271
|
end
|
284
272
|
end
|
@@ -97,7 +97,7 @@ module ActiveRecord
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
def create_table(table_name, options
|
100
|
+
def create_table(table_name, **options)
|
101
101
|
if connection.adapter_name == "Mysql2"
|
102
102
|
super(table_name, options: "ENGINE=InnoDB", **options)
|
103
103
|
else
|
@@ -119,7 +119,7 @@ module ActiveRecord
|
|
119
119
|
alias :belongs_to :references
|
120
120
|
end
|
121
121
|
|
122
|
-
def create_table(table_name, options
|
122
|
+
def create_table(table_name, **options)
|
123
123
|
if connection.adapter_name == "PostgreSQL"
|
124
124
|
if options[:id] == :uuid && !options.key?(:default)
|
125
125
|
options[:default] = "uuid_generate_v4()"
|
@@ -147,7 +147,7 @@ module ActiveRecord
|
|
147
147
|
super
|
148
148
|
end
|
149
149
|
|
150
|
-
def add_column(table_name, column_name, type, options
|
150
|
+
def add_column(table_name, column_name, type, **options)
|
151
151
|
if type == :primary_key
|
152
152
|
type = :integer
|
153
153
|
options[:primary_key] = true
|
@@ -456,13 +456,11 @@ module ActiveRecord
|
|
456
456
|
end
|
457
457
|
|
458
458
|
protected
|
459
|
-
|
460
459
|
def initialize_load_schema_monitor
|
461
460
|
@load_schema_monitor = Monitor.new
|
462
461
|
end
|
463
462
|
|
464
463
|
private
|
465
|
-
|
466
464
|
def inherited(child_class)
|
467
465
|
super
|
468
466
|
child_class.initialize_load_schema_monitor
|
@@ -480,6 +478,9 @@ module ActiveRecord
|
|
480
478
|
load_schema!
|
481
479
|
|
482
480
|
@schema_loaded = true
|
481
|
+
rescue
|
482
|
+
reload_schema_from_cache # If the schema loading failed half way through, we must reset the state.
|
483
|
+
raise
|
483
484
|
end
|
484
485
|
end
|
485
486
|
|
@@ -354,7 +354,6 @@ module ActiveRecord
|
|
354
354
|
end
|
355
355
|
|
356
356
|
private
|
357
|
-
|
358
357
|
# Generates a writer method for this association. Serves as a point for
|
359
358
|
# accessing the objects in the association. For example, this method
|
360
359
|
# could generate the following:
|
@@ -386,7 +385,6 @@ module ActiveRecord
|
|
386
385
|
end
|
387
386
|
|
388
387
|
private
|
389
|
-
|
390
388
|
# Attribute hash keys that should not be assigned as normal attributes.
|
391
389
|
# These hash keys are nested attributes implementation details.
|
392
390
|
UNASSIGNABLE_KEYS = %w( id _destroy )
|
@@ -54,11 +54,11 @@ module ActiveRecord
|
|
54
54
|
NoTouching.applied_to?(self.class)
|
55
55
|
end
|
56
56
|
|
57
|
-
def touch_later(
|
57
|
+
def touch_later(*, **) # :nodoc:
|
58
58
|
super unless no_touching?
|
59
59
|
end
|
60
60
|
|
61
|
-
def touch(
|
61
|
+
def touch(*, **) # :nodoc:
|
62
62
|
super unless no_touching?
|
63
63
|
end
|
64
64
|
end
|
@@ -466,8 +466,8 @@ module ActiveRecord
|
|
466
466
|
#
|
467
467
|
# Attributes marked as readonly are silently ignored if the record is
|
468
468
|
# being updated.
|
469
|
-
def save(*args, &block)
|
470
|
-
create_or_update(*args, &block)
|
469
|
+
def save(*args, **options, &block)
|
470
|
+
create_or_update(*args, **options, &block)
|
471
471
|
rescue ActiveRecord::RecordInvalid
|
472
472
|
false
|
473
473
|
end
|
@@ -499,8 +499,8 @@ module ActiveRecord
|
|
499
499
|
# being updated.
|
500
500
|
#
|
501
501
|
# Unless an error is raised, returns true.
|
502
|
-
def save!(*args, &block)
|
503
|
-
create_or_update(*args, &block) || raise(RecordNotSaved.new("Failed to save the record", self))
|
502
|
+
def save!(*args, **options, &block)
|
503
|
+
create_or_update(*args, **options, &block) || raise(RecordNotSaved.new("Failed to save the record", self))
|
504
504
|
end
|
505
505
|
|
506
506
|
# Deletes the record in the database and freezes this instance to
|
@@ -870,7 +870,6 @@ module ActiveRecord
|
|
870
870
|
end
|
871
871
|
|
872
872
|
private
|
873
|
-
|
874
873
|
# A hook to be overridden by association modules.
|
875
874
|
def destroy_associations
|
876
875
|
end
|
@@ -36,7 +36,7 @@ module ActiveRecord
|
|
36
36
|
#
|
37
37
|
# # A simple SQL query spanning multiple tables
|
38
38
|
# Post.find_by_sql "SELECT p.title, c.author FROM posts p, comments c WHERE p.id = c.post_id"
|
39
|
-
# # => [#<Post:0x36bff9c @attributes={"title"=>"Ruby Meetup", "
|
39
|
+
# # => [#<Post:0x36bff9c @attributes={"title"=>"Ruby Meetup", "author"=>"Quentin"}>, ...]
|
40
40
|
#
|
41
41
|
# You can use the same string replacement techniques as you can with <tt>ActiveRecord::QueryMethods#where</tt>:
|
42
42
|
#
|
@@ -80,11 +80,14 @@ db_namespace = namespace :db do
|
|
80
80
|
|
81
81
|
desc "Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
|
82
82
|
task migrate: :load_config do
|
83
|
+
original_config = ActiveRecord::Base.connection_config
|
83
84
|
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
|
84
85
|
ActiveRecord::Base.establish_connection(db_config.config)
|
85
86
|
ActiveRecord::Tasks::DatabaseTasks.migrate
|
86
87
|
end
|
87
88
|
db_namespace["_dump"].invoke
|
89
|
+
ensure
|
90
|
+
ActiveRecord::Base.establish_connection(original_config)
|
88
91
|
end
|
89
92
|
|
90
93
|
# IMPORTANT: This task won't dump the schema if ActiveRecord::Base.dump_schema_after_migration is set to false
|
@@ -183,20 +183,22 @@ module ActiveRecord
|
|
183
183
|
scope_chain_items = join_scopes(table, predicate_builder)
|
184
184
|
klass_scope = klass_join_scope(table, predicate_builder)
|
185
185
|
|
186
|
+
if type
|
187
|
+
klass_scope.where!(type => foreign_klass.polymorphic_name)
|
188
|
+
end
|
189
|
+
|
190
|
+
scope_chain_items.inject(klass_scope, &:merge!)
|
191
|
+
|
186
192
|
key = join_keys.key
|
187
193
|
foreign_key = join_keys.foreign_key
|
188
194
|
|
189
195
|
klass_scope.where!(table[key].eq(foreign_table[foreign_key]))
|
190
196
|
|
191
|
-
if type
|
192
|
-
klass_scope.where!(type => foreign_klass.polymorphic_name)
|
193
|
-
end
|
194
|
-
|
195
197
|
if klass.finder_needs_type_condition?
|
196
198
|
klass_scope.where!(klass.send(:type_condition, table))
|
197
199
|
end
|
198
200
|
|
199
|
-
|
201
|
+
klass_scope
|
200
202
|
end
|
201
203
|
|
202
204
|
def join_scopes(table, predicate_builder) # :nodoc:
|
@@ -590,7 +592,6 @@ module ActiveRecord
|
|
590
592
|
end
|
591
593
|
|
592
594
|
private
|
593
|
-
|
594
595
|
def calculate_constructable(macro, options)
|
595
596
|
true
|
596
597
|
end
|
@@ -620,7 +621,7 @@ module ActiveRecord
|
|
620
621
|
end
|
621
622
|
|
622
623
|
if valid_inverse_reflection?(reflection)
|
623
|
-
|
624
|
+
inverse_name
|
624
625
|
end
|
625
626
|
end
|
626
627
|
end
|
@@ -704,7 +705,6 @@ module ActiveRecord
|
|
704
705
|
end
|
705
706
|
|
706
707
|
private
|
707
|
-
|
708
708
|
def calculate_constructable(macro, options)
|
709
709
|
!options[:through]
|
710
710
|
end
|
@@ -385,6 +385,15 @@ module ActiveRecord
|
|
385
385
|
end
|
386
386
|
private :compute_cache_version
|
387
387
|
|
388
|
+
# Returns a cache key along with the version.
|
389
|
+
def cache_key_with_version
|
390
|
+
if version = cache_version
|
391
|
+
"#{cache_key}-#{version}"
|
392
|
+
else
|
393
|
+
cache_key
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
388
397
|
# Scope all queries to the current scope.
|
389
398
|
#
|
390
399
|
# Comment.where(post_id: 1).scoping do
|
@@ -479,7 +488,9 @@ module ActiveRecord
|
|
479
488
|
|
480
489
|
if touch
|
481
490
|
names = touch if touch != true
|
482
|
-
|
491
|
+
names = Array.wrap(names)
|
492
|
+
options = names.extract_options!
|
493
|
+
touch_updates = klass.touch_attributes_with_time(*names, **options)
|
483
494
|
updates.merge!(touch_updates) unless touch_updates.empty?
|
484
495
|
end
|
485
496
|
|
@@ -629,6 +640,7 @@ module ActiveRecord
|
|
629
640
|
@to_sql = @arel = @loaded = @should_eager_load = nil
|
630
641
|
@records = [].freeze
|
631
642
|
@offsets = {}
|
643
|
+
@take = nil
|
632
644
|
self
|
633
645
|
end
|
634
646
|
|
@@ -172,7 +172,7 @@ module ActiveRecord
|
|
172
172
|
# # SELECT people.id FROM people WHERE people.age = 21 LIMIT 5
|
173
173
|
# # => [2, 3]
|
174
174
|
#
|
175
|
-
# Person.pluck('DATEDIFF(updated_at, created_at)')
|
175
|
+
# Person.pluck(Arel.sql('DATEDIFF(updated_at, created_at)'))
|
176
176
|
# # SELECT DATEDIFF(updated_at, created_at) FROM people
|
177
177
|
# # => ['0', '27761', '173']
|
178
178
|
#
|
@@ -60,15 +60,17 @@ module ActiveRecord
|
|
60
60
|
return if method_defined?(method)
|
61
61
|
|
62
62
|
if /\A[a-zA-Z_]\w*[!?]?\z/.match?(method)
|
63
|
+
definition = RUBY_VERSION >= "2.7" ? "..." : "*args, &block"
|
63
64
|
module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
64
|
-
def #{method}(
|
65
|
-
scoping { klass.#{method}(
|
65
|
+
def #{method}(#{definition})
|
66
|
+
scoping { klass.#{method}(#{definition}) }
|
66
67
|
end
|
67
68
|
RUBY
|
68
69
|
else
|
69
70
|
define_method(method) do |*args, &block|
|
70
71
|
scoping { klass.public_send(method, *args, &block) }
|
71
72
|
end
|
73
|
+
ruby2_keywords(method) if respond_to?(:ruby2_keywords, true)
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
@@ -99,7 +101,6 @@ module ActiveRecord
|
|
99
101
|
end
|
100
102
|
|
101
103
|
private
|
102
|
-
|
103
104
|
def method_missing(method, *args, &block)
|
104
105
|
if @klass.respond_to?(method)
|
105
106
|
@klass.generate_relation_method(method)
|
@@ -108,15 +109,15 @@ module ActiveRecord
|
|
108
109
|
super
|
109
110
|
end
|
110
111
|
end
|
112
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
111
113
|
end
|
112
114
|
|
113
115
|
module ClassMethods # :nodoc:
|
114
|
-
def create(klass, *args)
|
115
|
-
relation_class_for(klass).new(klass, *args)
|
116
|
+
def create(klass, *args, **kwargs)
|
117
|
+
relation_class_for(klass).new(klass, *args, **kwargs)
|
116
118
|
end
|
117
119
|
|
118
120
|
private
|
119
|
-
|
120
121
|
def relation_class_for(klass)
|
121
122
|
klass.relation_delegate_class(self)
|
122
123
|
end
|
@@ -346,7 +346,6 @@ module ActiveRecord
|
|
346
346
|
end
|
347
347
|
|
348
348
|
private
|
349
|
-
|
350
349
|
def offset_index
|
351
350
|
offset_value || 0
|
352
351
|
end
|
@@ -376,7 +375,16 @@ module ActiveRecord
|
|
376
375
|
)
|
377
376
|
relation = except(:includes, :eager_load, :preload).joins!(join_dependency)
|
378
377
|
|
379
|
-
if eager_loading && !
|
378
|
+
if eager_loading && !(
|
379
|
+
using_limitable_reflections?(join_dependency.reflections) &&
|
380
|
+
using_limitable_reflections?(
|
381
|
+
construct_join_dependency(
|
382
|
+
select_association_list(joins_values).concat(
|
383
|
+
select_association_list(left_outer_joins_values)
|
384
|
+
), nil
|
385
|
+
).reflections
|
386
|
+
)
|
387
|
+
)
|
380
388
|
if has_limit_or_offset?
|
381
389
|
limited_ids = limited_ids_for(relation)
|
382
390
|
limited_ids.empty? ? relation.none! : relation.where!(primary_key => limited_ids)
|