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(table_name, connection) ⇒ Object
- #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.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 199 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(table_name, connection) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 219 def add(table_name, connection) columns.each do |name, type, | connection.add_column(table_name, name, type, **) end if index connection.add_index(table_name, column_names, **(table_name)) end if foreign_key connection.add_foreign_key(table_name, foreign_table_name, **) end end |
#add_to(table) ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 233 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 |