activerecord 6.0.2.2 → 6.0.3.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 +66 -0
- 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 +4 -11
- data/lib/active_record/associations.rb +1 -1
- data/lib/active_record/associations/alias_tracker.rb +0 -1
- data/lib/active_record/associations/association.rb +5 -9
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +0 -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 +9 -0
- data/lib/active_record/associations/preloader.rb +0 -1
- 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 +3 -3
- 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 +0 -3
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +17 -15
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +0 -1
- 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 +7 -3
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +12 -28
- data/lib/active_record/connection_adapters/connection_specification.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +5 -11
- 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 +6 -2
- 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 +5 -2
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +5 -6
- 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 +8 -7
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_handling.rb +10 -26
- data/lib/active_record/core.rb +0 -2
- 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 +2 -2
- data/lib/active_record/inheritance.rb +0 -3
- data/lib/active_record/insert_all.rb +3 -3
- 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 +1 -2
- 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 +0 -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/reflection.rb +8 -8
- data/lib/active_record/relation.rb +12 -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 +0 -1
- 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 +9 -7
- 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 -4
- 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 +1 -1
- data/lib/active_record/timestamp.rb +0 -1
- data/lib/active_record/touch_later.rb +1 -2
- data/lib/active_record/transactions.rb +8 -8
- 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 +5 -1
- 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 +14 -13
@@ -176,7 +176,6 @@ module ActiveRecord
|
|
176
176
|
end
|
177
177
|
|
178
178
|
protected
|
179
|
-
|
180
179
|
# Returns the class type of the record using the current module as a prefix. So descendants of
|
181
180
|
# MyApp::Business::Account would appear as MyApp::Business::AccountSubclass.
|
182
181
|
def compute_type(type_name)
|
@@ -208,7 +207,6 @@ module ActiveRecord
|
|
208
207
|
end
|
209
208
|
|
210
209
|
private
|
211
|
-
|
212
210
|
# Called by +instantiate+ to decide which class to use for a new
|
213
211
|
# record instance. For single-table inheritance, we check the record
|
214
212
|
# for a +type+ column and return the corresponding class.
|
@@ -272,7 +270,6 @@ module ActiveRecord
|
|
272
270
|
end
|
273
271
|
|
274
272
|
private
|
275
|
-
|
276
273
|
def initialize_internals_callback
|
277
274
|
super
|
278
275
|
ensure_proper_type
|
@@ -120,7 +120,7 @@ module ActiveRecord
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def into
|
123
|
-
"INTO #{model.quoted_table_name}(#{columns_list})"
|
123
|
+
"INTO #{model.quoted_table_name} (#{columns_list})"
|
124
124
|
end
|
125
125
|
|
126
126
|
def values_list
|
@@ -130,7 +130,7 @@ module ActiveRecord
|
|
130
130
|
connection.with_yaml_fallback(types[key].serialize(value))
|
131
131
|
end
|
132
132
|
|
133
|
-
Arel::
|
133
|
+
connection.visitor.compile(Arel::Nodes::ValuesList.new(values_list))
|
134
134
|
end
|
135
135
|
|
136
136
|
def returning
|
@@ -164,7 +164,7 @@ module ActiveRecord
|
|
164
164
|
unknown_column = (keys - columns.keys).first
|
165
165
|
raise UnknownAttributeError.new(model.new, unknown_column) if unknown_column
|
166
166
|
|
167
|
-
keys.
|
167
|
+
keys.index_with { |key| model.type_for_attribute(key) }
|
168
168
|
end
|
169
169
|
|
170
170
|
def format_columns(columns)
|
@@ -156,7 +156,6 @@ module ActiveRecord
|
|
156
156
|
end
|
157
157
|
|
158
158
|
private
|
159
|
-
|
160
159
|
# We need to apply this decorator here, rather than on module inclusion. The closure
|
161
160
|
# created by the matcher would otherwise evaluate for `ActiveRecord::Base`, not the
|
162
161
|
# sub class being decorated. As such, changes to `lock_optimistically`, or
|
@@ -44,7 +44,6 @@ module ActiveRecord
|
|
44
44
|
end
|
45
45
|
|
46
46
|
private
|
47
|
-
|
48
47
|
def read_from_primary(&blk)
|
49
48
|
ActiveRecord::Base.connected_to(role: ActiveRecord::Base.writing_role, prevent_writes: true) do
|
50
49
|
instrumenter.instrument("database_selector.active_record.read_from_primary") do
|
@@ -54,7 +53,7 @@ module ActiveRecord
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def read_from_replica(&blk)
|
57
|
-
ActiveRecord::Base.connected_to(role: ActiveRecord::Base.reading_role) do
|
56
|
+
ActiveRecord::Base.connected_to(role: ActiveRecord::Base.reading_role, prevent_writes: true) do
|
58
57
|
instrumenter.instrument("database_selector.active_record.read_from_replica") do
|
59
58
|
yield
|
60
59
|
end
|
@@ -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
|
@@ -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
|
#
|
@@ -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
|
|