Module: SchemaPlus::ActiveRecord::ColumnOptionsHandler
- Included in:
- SchemaPlus::ActiveRecord::ConnectionAdapters::TableDefinition, ForeignKeys, Migration::CommandRecorder
- Defined in:
- lib/schema_plus/active_record/column_options_handler.rb
Instance Method Summary collapse
-
#schema_plus_handle_column_options(table_name, column_name, column_options, opts = {}) ⇒ Object
:nodoc:.
Instance Method Details
#schema_plus_handle_column_options(table_name, column_name, column_options, opts = {}) ⇒ Object
:nodoc:
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/schema_plus/active_record/column_options_handler.rb', line 3 def (table_name, column_name, , opts = {}) #:nodoc: config = opts[:config] || SchemaPlus.config fk_args = get_fk_args(table_name, column_name, , config) # remove existing fk and auto-generated index in case of change to existing column if fk_args # includes :none for explicitly off remove_foreign_key_if_exists(table_name, column_name) remove_auto_index_if_exists(table_name, column_name) end fk_args = nil if fk_args == :none # create index if requested explicity or implicitly due to auto_index index = [:index] index = [:_index] if .include? :_index if index.nil? and fk_args && config.foreign_keys.auto_index? index = { :name => auto_index_name(table_name, column_name) } end column_index(table_name, column_name, index) if index if fk_args references = fk_args.delete(:references) add_foreign_key(table_name, column_name, references.first, references.last, fk_args) end end |