Class: ActiveRecord::ConnectionAdapters::ReferenceDefinition
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::ReferenceDefinition
- Defined in:
- lib/active_record/connection_adapters/abstract/schema_definitions.rb
Overview
:nodoc:
Instance Method Summary collapse
- #add_to(table) ⇒ Object
-
#initialize(name, polymorphic: false, index: true, foreign_key: false, type: :bigint, **options) ⇒ ReferenceDefinition
constructor
A new instance of ReferenceDefinition.
Constructor Details
#initialize(name, polymorphic: false, index: true, foreign_key: false, type: :bigint, **options) ⇒ ReferenceDefinition
Returns a new instance of ReferenceDefinition.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 125 def initialize( name, polymorphic: false, index: true, foreign_key: false, type: :bigint, ** ) @name = name @polymorphic = polymorphic @index = index @foreign_key = foreign_key @type = type @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
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 145 def add_to(table) columns.each do || kwargs = . table.column(*, **kwargs) end if index table.index(column_names, ) end if foreign_key table.foreign_key(foreign_table_name, **) end end |