Class: ActiveRecord::ConnectionAdapters::ReferenceDefinition
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::ReferenceDefinition
- Defined in:
- lib/active_record/connection_adapters/abstract/schema_definitions.rb
Overview
:nodoc:
Direct Known Subclasses
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.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 154 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
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 174 def add_to(table) columns.each do |name, type, | table.column(name, type, **) end if index table.index(column_names, **(table.name)) end if foreign_key table.foreign_key(foreign_table_name, **) end end |