activerecord 6.1.0.rc1 → 6.1.0.rc2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66ac86600eb6f03cff86765392e7ec1baf5741aca1050133653dab7d9552ede3
4
- data.tar.gz: ab475bbab2246deea73d3d699374c6f309fdddc97f467d783695af1e737cb352
3
+ metadata.gz: b093236482caac43173dfffd7096282d55d6fc0099ed9f6e684b84efabfbb466
4
+ data.tar.gz: ef623a179fbabb3fd9aa544baf87da3bf342cca09dd6a2bf9bd3f4d2435410a8
5
5
  SHA512:
6
- metadata.gz: 51480027525839e315d70abb310a433cfa48c9fb25084ba13ce4d18d205e0d3eb4ae79fe259716a15c055e7083d381e590ddc4e6829662c21276cacf70845834
7
- data.tar.gz: ec51c2bc1172ec830f700aea91674fed170a9d362c7a8be600328055db0132d79b38049d8ee9ad03729b962c7667982519b3fb0bfa8569cac7c3686c8f73ebd3
6
+ metadata.gz: 3ba3873e17ac4ad32e19d81a7669b24024195986c8cbbf9eb54ae9ecf798d9f82369594051712609458bf84f4bb58228c0dfcef9ce21cb8926dd07dd898efaba
7
+ data.tar.gz: 8fadd55a99b48ba91ec273fc76d24d3257d67c89999fde3851547b29711244b649edccbeb9c4ff9ba326348a61be4da361fd49f35dcd55109c19ada385f47de6
@@ -1,3 +1,28 @@
1
+ ## Rails 6.1.0.rc2 (December 01, 2020) ##
2
+
3
+ * Fix odd behavior of inverse_of with multiple belongs_to to same class.
4
+
5
+ Fixes #35204.
6
+
7
+ *Tomoyuki Kai*
8
+
9
+ * Build predicate conditions with objects that delegate `#id` and primary key:
10
+
11
+ ```ruby
12
+ class AdminAuthor
13
+ delegate_missing_to :@author
14
+
15
+ def initialize(author)
16
+ @author = author
17
+ end
18
+ end
19
+
20
+ Post.where(author: AdminAuthor.new(author))
21
+ ```
22
+
23
+ *Sean Doyle*
24
+
25
+
1
26
  ## Rails 6.1.0.rc1 (November 02, 2020) ##
2
27
 
3
28
  * Add `connected_to_many` API.
@@ -108,7 +133,7 @@
108
133
 
109
134
  * Named scope chain does no longer leak scope to class level querying methods.
110
135
 
111
- class class User < ActiveRecord::Base
136
+ class User < ActiveRecord::Base
112
137
  scope :david, -> { User.where(name: "David") }
113
138
  end
114
139
 
@@ -665,14 +690,14 @@
665
690
 
666
691
  *Ryuta Kamizono*
667
692
 
668
- * Inspect time attributes with subsec.
693
+ * Inspect time attributes with subsec and time zone offset.
669
694
 
670
695
  ```ruby
671
696
  p Knot.create
672
- => #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000">
697
+ => #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
673
698
  ```
674
699
 
675
- *akinomaeni*
700
+ *akinomaeni*, *Jonathan Hefner*
676
701
 
677
702
  * Deprecate passing a column to `type_cast`.
678
703
 
@@ -131,6 +131,11 @@ module ActiveRecord
131
131
  end
132
132
 
133
133
  def inversed_from(record)
134
+ self.target = record
135
+ @inversed = !!record
136
+ end
137
+
138
+ def inversed_from_queries(record)
134
139
  if inversable?(record)
135
140
  self.target = record
136
141
  @inversed = true
@@ -138,7 +143,6 @@ module ActiveRecord
138
143
  @inversed = false
139
144
  end
140
145
  end
141
- alias :inversed_from_queries :inversed_from
142
146
 
143
147
  # Returns the class of the target. belongs_to polymorphic overrides this to look at the
144
148
  # polymorphic_type field on the owner.
@@ -337,7 +341,8 @@ module ActiveRecord
337
341
 
338
342
  def matches_foreign_key?(record)
339
343
  if foreign_key_for?(record)
340
- record.read_attribute(reflection.foreign_key) == owner.id
344
+ record.read_attribute(reflection.foreign_key) == owner.id ||
345
+ (foreign_key_for?(owner) && owner.read_attribute(reflection.foreign_key) == record.id)
341
346
  else
342
347
  owner.read_attribute(reflection.foreign_key) == record.id
343
348
  end
@@ -41,6 +41,12 @@ module ActiveRecord
41
41
  # * +class_name_or_coder+ - Optional, a coder object, which responds to +.load+ and +.dump+
42
42
  # or a class name that the object type should be equal to.
43
43
  #
44
+ # ==== Options
45
+ #
46
+ # +default+ The default value to use when no value is provided. If this option
47
+ # is not passed, the previous default value (if any) will be used.
48
+ # Otherwise, the default will be +nil+.
49
+ #
44
50
  # ==== Example
45
51
  #
46
52
  # # Serialize a preferences attribute.
@@ -57,7 +63,7 @@ module ActiveRecord
57
63
  # class User < ActiveRecord::Base
58
64
  # serialize :preferences, Hash
59
65
  # end
60
- def serialize(attr_name, class_name_or_coder = Object)
66
+ def serialize(attr_name, class_name_or_coder = Object, **options)
61
67
  # When ::JSON is used, force it to go through the Active Support JSON encoder
62
68
  # to ensure special objects (e.g. Active Record models) are dumped correctly
63
69
  # using the #as_json hook.
@@ -69,7 +75,7 @@ module ActiveRecord
69
75
  Coders::YAMLColumn.new(attr_name, class_name_or_coder)
70
76
  end
71
77
 
72
- decorate_attribute_type(attr_name.to_s) do |cast_type|
78
+ decorate_attribute_type(attr_name.to_s, **options) do |cast_type|
73
79
  if type_incompatible_with_serialize?(cast_type, class_name_or_coder)
74
80
  raise ColumnNotSerializableError.new(attr_name, cast_type)
75
81
  end
@@ -12,6 +12,9 @@ module ActiveRecord
12
12
  end
13
13
 
14
14
  module ClassMethods
15
+ ##
16
+ # :call-seq: attribute(name, cast_type = nil, **options)
17
+ #
15
18
  # Defines an attribute with a type on this model. It will override the
16
19
  # type of existing attributes if needed. This allows control over how
17
20
  # values are converted to and from SQL when assigned to a model. It also
@@ -273,6 +276,8 @@ module ActiveRecord
273
276
  def decorate_attribute_type(attr_name, **default)
274
277
  type, options = attributes_to_define_after_schema_loads[attr_name]
275
278
 
279
+ default.with_defaults!(default: options[:default]) if options&.key?(:default)
280
+
276
281
  attribute(attr_name, **default) do |cast_type|
277
282
  if type && !type.is_a?(Proc)
278
283
  cast_type = _lookup_cast_type(attr_name, type, options)
@@ -301,8 +301,128 @@ module ActiveRecord
301
301
  :before_destroy, :around_destroy, :after_destroy, :after_commit, :after_rollback
302
302
  ]
303
303
 
304
- module ClassMethods # :nodoc:
304
+ module ClassMethods
305
305
  include ActiveModel::Callbacks
306
+
307
+ ##
308
+ # :method: after_initialize
309
+ #
310
+ # :call-seq: after_initialize(*args, &block)
311
+ #
312
+ # Registers a callback to be called after a record is instantiated. See
313
+ # ActiveRecord::Callbacks for more information.
314
+
315
+ ##
316
+ # :method: after_find
317
+ #
318
+ # :call-seq: after_find(*args, &block)
319
+ #
320
+ # Registers a callback to be called after a record is instantiated
321
+ # via a finder. See ActiveRecord::Callbacks for more information.
322
+
323
+ ##
324
+ # :method: after_touch
325
+ #
326
+ # :call-seq: after_touch(*args, &block)
327
+ #
328
+ # Registers a callback to be called after a record is touched. See
329
+ # ActiveRecord::Callbacks for more information.
330
+
331
+ ##
332
+ # :method: before_save
333
+ #
334
+ # :call-seq: before_save(*args, &block)
335
+ #
336
+ # Registers a callback to be called before a record is saved. See
337
+ # ActiveRecord::Callbacks for more information.
338
+
339
+ ##
340
+ # :method: around_save
341
+ #
342
+ # :call-seq: around_save(*args, &block)
343
+ #
344
+ # Registers a callback to be called around the save of a record. See
345
+ # ActiveRecord::Callbacks for more information.
346
+
347
+ ##
348
+ # :method: after_save
349
+ #
350
+ # :call-seq: after_save(*args, &block)
351
+ #
352
+ # Registers a callback to be called after a record is saved. See
353
+ # ActiveRecord::Callbacks for more information.
354
+
355
+ ##
356
+ # :method: before_create
357
+ #
358
+ # :call-seq: before_create(*args, &block)
359
+ #
360
+ # Registers a callback to be called before a record is created. See
361
+ # ActiveRecord::Callbacks for more information.
362
+
363
+ ##
364
+ # :method: around_create
365
+ #
366
+ # :call-seq: around_create(*args, &block)
367
+ #
368
+ # Registers a callback to be called around the creation of a record. See
369
+ # ActiveRecord::Callbacks for more information.
370
+
371
+ ##
372
+ # :method: after_create
373
+ #
374
+ # :call-seq: after_create(*args, &block)
375
+ #
376
+ # Registers a callback to be called after a record is created. See
377
+ # ActiveRecord::Callbacks for more information.
378
+
379
+ ##
380
+ # :method: before_update
381
+ #
382
+ # :call-seq: before_update(*args, &block)
383
+ #
384
+ # Registers a callback to be called before a record is updated. See
385
+ # ActiveRecord::Callbacks for more information.
386
+
387
+ ##
388
+ # :method: around_update
389
+ #
390
+ # :call-seq: around_update(*args, &block)
391
+ #
392
+ # Registers a callback to be called around the update of a record. See
393
+ # ActiveRecord::Callbacks for more information.
394
+
395
+ ##
396
+ # :method: after_update
397
+ #
398
+ # :call-seq: after_update(*args, &block)
399
+ #
400
+ # Registers a callback to be called after a record is updated. See
401
+ # ActiveRecord::Callbacks for more information.
402
+
403
+ ##
404
+ # :method: before_destroy
405
+ #
406
+ # :call-seq: before_destroy(*args, &block)
407
+ #
408
+ # Registers a callback to be called before a record is destroyed. See
409
+ # ActiveRecord::Callbacks for more information.
410
+
411
+ ##
412
+ # :method: around_destroy
413
+ #
414
+ # :call-seq: around_destroy(*args, &block)
415
+ #
416
+ # Registers a callback to be called around the destruction of a record.
417
+ # See ActiveRecord::Callbacks for more information.
418
+
419
+ ##
420
+ # :method: after_destroy
421
+ #
422
+ # :call-seq: after_destroy(*args, &block)
423
+ #
424
+ # Registers a callback to be called after a record is destroyed. See
425
+ # ActiveRecord::Callbacks for more information.
306
426
  end
307
427
 
308
428
  included do
@@ -23,6 +23,10 @@ module ActiveRecord
23
23
  include ConnectionAdapters::AbstractPool
24
24
 
25
25
  attr_accessor :schema_cache
26
+
27
+ def owner_name
28
+ nil
29
+ end
26
30
  end
27
31
 
28
32
  # Connection pool base class for managing Active Record database
@@ -356,7 +360,7 @@ module ActiveRecord
356
360
  include ConnectionAdapters::AbstractPool
357
361
 
358
362
  attr_accessor :automatic_reconnect, :checkout_timeout
359
- attr_reader :db_config, :size, :reaper, :pool_config
363
+ attr_reader :db_config, :size, :reaper, :pool_config, :owner_name
360
364
 
361
365
  delegate :schema_cache, :schema_cache=, to: :pool_config
362
366
 
@@ -371,6 +375,7 @@ module ActiveRecord
371
375
 
372
376
  @pool_config = pool_config
373
377
  @db_config = pool_config.db_config
378
+ @owner_name = pool_config.connection_specification_name
374
379
 
375
380
  @checkout_timeout = db_config.checkout_timeout
376
381
  @idle_timeout = db_config.idle_timeout
@@ -381,7 +386,7 @@ module ActiveRecord
381
386
  # registry of which thread owns which connection. Connection ownership is tracked by
382
387
  # the +connection.owner+ attr on each +connection+ instance.
383
388
  # The invariant works like this: if there is mapping of <tt>thread => conn</tt>,
384
- # then that +thread+ does indeed own that +conn+. However, an absence of a such
389
+ # then that +thread+ does indeed own that +conn+. However, an absence of such
385
390
  # mapping does not mean that the +thread+ doesn't own the said connection. In
386
391
  # that case +conn.owner+ attr should be consulted.
387
392
  # Access and modification of <tt>@thread_cached_conns</tt> does not require
@@ -317,25 +317,31 @@ module ActiveRecord
317
317
  end
318
318
  raise
319
319
  ensure
320
- if !error && transaction
321
- if Thread.current.status == "aborting"
322
- rollback_transaction
320
+ if transaction
321
+ if error
322
+ # @connection still holds an open transaction, so we must not
323
+ # put it back in the pool for reuse
324
+ @connection.throw_away! unless transaction.state.rolledback?
323
325
  else
324
- if !completed && transaction.written
325
- ActiveSupport::Deprecation.warn(<<~EOW)
326
- Using `return`, `break` or `throw` to exit a transaction block is
327
- deprecated without replacement. If the `throw` came from
328
- `Timeout.timeout(duration)`, pass an exception class as a second
329
- argument so it doesn't use `throw` to abort its block. This results
330
- in the transaction being committed, but in the next release of Rails
331
- it will rollback.
332
- EOW
333
- end
334
- begin
335
- commit_transaction
336
- rescue Exception
337
- rollback_transaction(transaction) unless transaction.state.completed?
338
- raise
326
+ if Thread.current.status == "aborting"
327
+ rollback_transaction
328
+ else
329
+ if !completed && transaction.written
330
+ ActiveSupport::Deprecation.warn(<<~EOW)
331
+ Using `return`, `break` or `throw` to exit a transaction block is
332
+ deprecated without replacement. If the `throw` came from
333
+ `Timeout.timeout(duration)`, pass an exception class as a second
334
+ argument so it doesn't use `throw` to abort its block. This results
335
+ in the transaction being committed, but in the next release of Rails
336
+ it will rollback.
337
+ EOW
338
+ end
339
+ begin
340
+ commit_transaction
341
+ rescue Exception
342
+ rollback_transaction(transaction) unless transaction.state.completed?
343
+ raise
344
+ end
339
345
  end
340
346
  end
341
347
  end
@@ -113,14 +113,20 @@ module ActiveRecord
113
113
 
114
114
  # Determines whether writes are currently being prevents.
115
115
  #
116
- # Returns true if the connection is a replica, or if +prevent_writes+
117
- # is set to true.
116
+ # Returns true if the connection is a replica.
117
+ #
118
+ # If the application is using legacy handling, returns
119
+ # true if `connection_handler.prevent_writes` is set.
120
+ #
121
+ # If the application is using the new connection handling
122
+ # will return true based on `current_preventing_writes`.
118
123
  def preventing_writes?
119
- if ActiveRecord::Base.legacy_connection_handling
120
- replica? || ActiveRecord::Base.connection_handler.prevent_writes
121
- else
122
- replica? || ActiveRecord::Base.current_preventing_writes
123
- end
124
+ return true if replica?
125
+ return ActiveRecord::Base.connection_handler.prevent_writes if ActiveRecord::Base.legacy_connection_handling
126
+ return false if owner_name.nil?
127
+
128
+ klass = self.owner_name.safe_constantize
129
+ klass&.current_preventing_writes
124
130
  end
125
131
 
126
132
  def migrations_paths # :nodoc:
@@ -196,6 +202,10 @@ module ActiveRecord
196
202
  @owner = Thread.current
197
203
  end
198
204
 
205
+ def owner_name # :nodoc:
206
+ @pool.owner_name
207
+ end
208
+
199
209
  def schema_cache
200
210
  @pool.get_schema_cache(self)
201
211
  end
@@ -501,6 +511,12 @@ module ActiveRecord
501
511
  # this should be overridden by concrete adapters
502
512
  end
503
513
 
514
+ # Removes the connection from the pool and disconnect it.
515
+ def throw_away!
516
+ pool.remove self
517
+ disconnect!
518
+ end
519
+
504
520
  # Clear any caching the database adapter may be doing.
505
521
  def clear_cache!
506
522
  @lock.synchronize { @statements.clear } if @statements
@@ -45,10 +45,9 @@ module ActiveRecord
45
45
  end
46
46
 
47
47
  def add_table_options!(create_sql, o)
48
- create_sql = super
49
48
  create_sql << " DEFAULT CHARSET=#{o.charset}" if o.charset
50
49
  create_sql << " COLLATE=#{o.collation}" if o.collation
51
- add_sql_comment!(create_sql, o.comment)
50
+ add_sql_comment!(super, o.comment)
52
51
  end
53
52
 
54
53
  def add_column_options!(sql, options)
@@ -166,10 +166,18 @@ module ActiveRecord
166
166
  end
167
167
 
168
168
  def self.connection_handlers
169
+ unless legacy_connection_handling
170
+ raise NotImplementedError, "The new connection handling does not support accessing multiple connection handlers."
171
+ end
172
+
169
173
  @@connection_handlers ||= {}
170
174
  end
171
175
 
172
176
  def self.connection_handlers=(handlers)
177
+ unless legacy_connection_handling
178
+ raise NotImplementedError, "The new connection handling does not setting support multiple connection handlers."
179
+ end
180
+
173
181
  @@connection_handlers = handlers
174
182
  end
175
183
 
@@ -324,7 +332,7 @@ module ActiveRecord
324
332
  hash = args.first
325
333
  return super unless Hash === hash
326
334
 
327
- values = hash.values.map! { |value| value.is_a?(Base) ? value.id : value }
335
+ values = hash.values.map! { |value| value.respond_to?(:id) ? value.id : value }
328
336
  return super if values.any? { |v| StatementCache.unsupported_value?(v) }
329
337
 
330
338
  keys = hash.keys.map! do |key|
@@ -10,7 +10,7 @@ module ActiveRecord
10
10
  MAJOR = 6
11
11
  MINOR = 1
12
12
  TINY = 0
13
- PRE = "rc1"
13
+ PRE = "rc2"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -69,6 +69,8 @@ module ActiveRecord
69
69
  attr_reader :scope_attributes
70
70
 
71
71
  def find_unique_index_for(unique_by)
72
+ return unique_by if !connection.supports_insert_conflict_target?
73
+
72
74
  name_or_columns = unique_by || model.primary_key
73
75
  match = Array(name_or_columns).map(&:to_s)
74
76
 
@@ -43,11 +43,9 @@ module ActiveRecord
43
43
  def create_table
44
44
  return unless enabled?
45
45
 
46
- unless table_exists?
47
- key_options = connection.internal_string_options_for_primary_key
48
-
46
+ unless connection.table_exists?(table_name)
49
47
  connection.create_table(table_name, id: false) do |t|
50
- t.string :key, **key_options
48
+ t.string :key, **connection.internal_string_options_for_primary_key
51
49
  t.string :value
52
50
  t.timestamps
53
51
  end
@@ -297,6 +297,35 @@ module ActiveRecord
297
297
 
298
298
  # Sets the columns names the model should ignore. Ignored columns won't have attribute
299
299
  # accessors defined, and won't be referenced in SQL queries.
300
+ #
301
+ # A common usage pattern for this method is to ensure all references to an attribute
302
+ # have been removed and deployed, before a migration to drop the column from the database
303
+ # has been deployed and run. Using this two step approach to dropping columns ensures there
304
+ # is no code that raises errors due to having a cached schema in memory at the time the
305
+ # schema migration is run.
306
+ #
307
+ # For example, given a model where you want to drop the "category" attribute, first mark it
308
+ # as ignored:
309
+ #
310
+ # class Project < ActiveRecord::Base
311
+ # # schema:
312
+ # # id :bigint
313
+ # # name :string, limit: 255
314
+ # # category :string, limit: 255
315
+ #
316
+ # self.ignored_columns = [:category]
317
+ # end
318
+ #
319
+ # The schema still contains `category`, but now the model omits it, so any meta-driven code or
320
+ # schema caching will not attempt to use the column:
321
+ #
322
+ # Project.columns_hash["category"] => nil
323
+ #
324
+ # You will get an error if accessing that attribute directly, so ensure all usages of the
325
+ # column are removed (automated tests can help you find any usages).
326
+ #
327
+ # user = Project.create!(name: "First Project")
328
+ # user.category # => raises NoMethodError
300
329
  def ignored_columns=(columns)
301
330
  reload_schema_from_cache
302
331
  @ignored_columns = columns.map(&:to_s).freeze
@@ -183,7 +183,7 @@ To keep using the current cache store, you can turn off cache versioning entirel
183
183
  end
184
184
  end
185
185
  rescue ActiveRecordError => error
186
- # Regardless of wether there was already a connection or not, we rescue any database
186
+ # Regardless of whether there was already a connection or not, we rescue any database
187
187
  # error because it is critical that the application can boot even if the database
188
188
  # is unhealthy.
189
189
  warn "Failed to define attribute methods because of #{error.class}: #{error.message}"
@@ -455,6 +455,14 @@ db_namespace = namespace :db do
455
455
  ActiveRecord::Tasks::DatabaseTasks.load_schema_current(ActiveRecord::Base.schema_format, ENV["SCHEMA"])
456
456
  end
457
457
 
458
+ task load_if_ruby: ["db:create", :environment] do
459
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
460
+ Using `bin/rails db:schema:load_if_ruby` is deprecated and will be removed in Rails 6.2.
461
+ Configure the format using `config.active_record.schema_format = :ruby` to use `schema.rb` and run `bin/rails db:schema:load` instead.
462
+ MSG
463
+ db_namespace["schema:load"].invoke if ActiveRecord::Base.schema_format == :ruby
464
+ end
465
+
458
466
  namespace :dump do
459
467
  ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
460
468
  desc "Creates a database schema file (either db/schema.rb or db/structure.sql, depending on `config.active_record.schema_format`) for #{name} database"
@@ -529,6 +537,14 @@ db_namespace = namespace :db do
529
537
  db_namespace["schema:load"].invoke
530
538
  end
531
539
 
540
+ task load_if_sql: ["db:create", :environment] do
541
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
542
+ Using `bin/rails db:structure:load_if_sql` is deprecated and will be removed in Rails 6.2.
543
+ Configure the format using `config.active_record.schema_format = :sql` to use `structure.sql` and run `bin/rails db:schema:load` instead.
544
+ MSG
545
+ db_namespace["schema:load"].invoke if ActiveRecord::Base.schema_format == :sql
546
+ end
547
+
532
548
  namespace :dump do
533
549
  ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
534
550
  desc "Dumps the #{name} database structure to db/structure.sql. Specify another file with SCHEMA=db/my_structure.sql"
@@ -623,6 +623,7 @@ module ActiveRecord
623
623
  # with the current reflection's klass name.
624
624
  def valid_inverse_reflection?(reflection)
625
625
  reflection &&
626
+ foreign_key == reflection.foreign_key &&
626
627
  klass <= reflection.active_record &&
627
628
  can_find_inverse_of_automatically?(reflection)
628
629
  end
@@ -59,7 +59,7 @@ module ActiveRecord
59
59
  end
60
60
 
61
61
  def build(attribute, value, operator = nil)
62
- value = value.id if value.is_a?(Base)
62
+ value = value.id if value.respond_to?(:id)
63
63
  if operator ||= table.type(attribute.name).force_equality?(value) && :eq
64
64
  bind = build_bind_attribute(attribute.name, value)
65
65
  attribute.public_send(operator, bind)
@@ -100,7 +100,7 @@ module ActiveRecord
100
100
  end
101
101
  elsif associated_table.through_association?
102
102
  next associated_table.predicate_builder.expand_from_hash(
103
- associated_table.join_foreign_key => value
103
+ associated_table.primary_key => value
104
104
  )
105
105
  end
106
106
 
@@ -31,9 +31,8 @@ module ActiveRecord
31
31
  end
32
32
 
33
33
  def convert_to_id(value)
34
- case value
35
- when Base
36
- value._read_attribute(primary_key)
34
+ if value.respond_to?(:id)
35
+ value.id
37
36
  else
38
37
  value
39
38
  end
@@ -69,8 +69,8 @@ module ActiveRecord
69
69
 
70
70
  private
71
71
  def relation_with(values)
72
- result = Relation.create(klass, values: values)
73
- result.extend(*extending_values) if extending_values.any?
72
+ result = spawn
73
+ result.instance_variable_set(:@values, values)
74
74
  result
75
75
  end
76
76
  end
@@ -23,11 +23,9 @@ module ActiveRecord
23
23
  end
24
24
 
25
25
  def create_table
26
- unless table_exists?
27
- version_options = connection.internal_string_options_for_primary_key
28
-
26
+ unless connection.table_exists?(table_name)
29
27
  connection.create_table(table_name, id: false) do |t|
30
- t.string :version, **version_options
28
+ t.string :version, **connection.internal_string_options_for_primary_key
31
29
  end
32
30
  end
33
31
  end
@@ -10,6 +10,10 @@ module ActiveRecord
10
10
  @reflection = reflection
11
11
  end
12
12
 
13
+ def primary_key
14
+ klass&.primary_key
15
+ end
16
+
13
17
  def type(column_name)
14
18
  arel_table.type_for_attribute(column_name)
15
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0.rc1
4
+ version: 6.1.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-02 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 6.1.0.rc1
19
+ version: 6.1.0.rc2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 6.1.0.rc1
26
+ version: 6.1.0.rc2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 6.1.0.rc1
33
+ version: 6.1.0.rc2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 6.1.0.rc1
40
+ version: 6.1.0.rc2
41
41
  description: Databases on Rails. Build a persistent domain model by mapping database
42
42
  tables to Ruby classes. Strong conventions for associations, validations, aggregations,
43
43
  migrations, and testing come baked-in.
@@ -390,10 +390,10 @@ licenses:
390
390
  - MIT
391
391
  metadata:
392
392
  bug_tracker_uri: https://github.com/rails/rails/issues
393
- changelog_uri: https://github.com/rails/rails/blob/v6.1.0.rc1/activerecord/CHANGELOG.md
394
- documentation_uri: https://api.rubyonrails.org/v6.1.0.rc1/
393
+ changelog_uri: https://github.com/rails/rails/blob/v6.1.0.rc2/activerecord/CHANGELOG.md
394
+ documentation_uri: https://api.rubyonrails.org/v6.1.0.rc2/
395
395
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
396
- source_code_uri: https://github.com/rails/rails/tree/v6.1.0.rc1/activerecord
396
+ source_code_uri: https://github.com/rails/rails/tree/v6.1.0.rc2/activerecord
397
397
  post_install_message:
398
398
  rdoc_options:
399
399
  - "--main"