Sha256: 81e60b724699157e72b42713b4ffb40eedb347193c81abb5a909f12b3474eb44

Contents?: true

Size: 1.71 KB

Versions: 16

Compression:

Stored size: 1.71 KB

Contents

module SchemaPlus
  module Core
    module ActiveRecord
      module ConnectionAdapters
        module TableDefinition

          def column(name, type, options = {})
            options = options.deep_dup
            SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: name, type: type, implements_reference: options.delete(:_implements_reference), options: options) do |env|
              super env.column_name, env.type, env.options
            end
          end

          def references(name, options = {})
            options = options.deep_dup
            SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: "#{name}_id", type: :reference, options: options) do |env|
              super env.column_name.sub(/_id$/, ''), env.options.merge(_implements_reference: true)
            end
          end

          def belongs_to(name, options = {})
            options = options.deep_dup
            SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: "#{name}_id", type: :reference, options: options) do |env|
              super env.column_name.sub(/_id$/, ''), env.options.merge(_implements_reference: true)
            end
          end

          def index(*args)
            options = args.extract_options!
            column_name = args.first
            SchemaMonkey::Middleware::Migration::Index.start(caller: self, operation: :define, table_name: self.name, column_names: column_name, options: options.deep_dup) do |env|
              super env.column_names, env.options
            end
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
schema_plus_core-2.2.3 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-2.2.2 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-2.2.1 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-2.2.0 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-2.1.1 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-2.1.0 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-2.0.1 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-1.0.2 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-1.0.1 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-1.0.0 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-0.6.2 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-0.6.1 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-0.6.0 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-0.5.1 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-0.5.0 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
schema_plus_core-0.4.0 lib/schema_plus/core/active_record/connection_adapters/table_definition.rb