Class: ActiveRecord::ConnectionAdapters::Spanner::ReferenceDefinition

Inherits:
ReferenceDefinition
  • Object
show all
Defined in:
lib/active_record/connection_adapters/spanner/schema_definitions.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, polymorphic: false, index: true, foreign_key: false, type: :integer, **options) ⇒ ReferenceDefinition

Returns a new instance of ReferenceDefinition.

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/active_record/connection_adapters/spanner/schema_definitions.rb', line 52

def initialize \
    name,
    polymorphic: false,
    index: true,
    foreign_key: false,
    type: :integer,
    **options
  @name = name
  @polymorphic = polymorphic
  @foreign_key = foreign_key
  # Only add an index if there is no foreign key, as Cloud Spanner will automatically add a managed index when
  # a foreign key is added.
  @index = index unless foreign_key
  @type = type
  @options = options

  return unless polymorphic && foreign_key
  raise ArgumentError, "Cannot add a foreign key to a polymorphic relation"
end