Sha256: 4f7ac68e3453aaacf8f5dddf1a64c297b35c838d7ef82218746929ea004ecda6

Contents?: true

Size: 1012 Bytes

Versions: 3

Compression:

Stored size: 1012 Bytes

Contents

module RedhillonrailsCore::ActiveRecord::ConnectionAdapters
  module TableDefinition
    def self.included(base)
      base.class_eval do
        attr_accessor :name
        alias_method_chain :initialize, :redhillonrails_core
        alias_method_chain :to_sql, :redhillonrails_core
      end
    end

    def initialize_with_redhillonrails_core(*args)
      initialize_without_redhillonrails_core(*args)
      @foreign_keys = []
    end

    def foreign_key(column_names, references_table_name, references_column_names, options = {})
      @foreign_keys << ForeignKeyDefinition.new(options[:name], nil, column_names, ActiveRecord::Migrator.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
      self
    end

    def to_sql_with_redhillonrails_core
      sql = to_sql_without_redhillonrails_core
      sql << ', ' << @foreign_keys * ', ' unless @foreign_keys.empty? || ActiveRecord::Schema.defining?
      sql
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aspgems-redhillonrails_core-2.0.0.beta4 lib/redhillonrails_core/active_record/connection_adapters/abstract/table_definition.rb
aspgems-redhillonrails_core-2.0.0.beta2 lib/redhillonrails_core/active_record/connection_adapters/abstract/table_definition.rb
aspgems-redhillonrails_core-2.0.0.beta1 lib/redhillonrails_core/active_record/connection_adapters/abstract/table_definition.rb