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)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/active_record/connection_adapters/spanner/schema_definitions.rb', line 65

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