Class: ActiveRecord::ConnectionAdapters::ReferenceDefinition

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb

Overview

:nodoc:

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.


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 70

def initialize(
  name,
  polymorphic: false,
  index: true,
  foreign_key: false,
  type: :integer,
  **options
)
  @name = name
  @polymorphic = polymorphic
  @index = index
  @foreign_key = foreign_key
  @type = type
  @options = options

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

Instance Method Details

#add_to(table) ⇒ Object


90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 90

def add_to(table)
  columns.each do |column_options|
    table.column(*column_options)
  end

  if index
    table.index(column_names, index_options)
  end

  if foreign_key
    table.foreign_key(foreign_table_name, foreign_key_options)
  end
end