Sha256: f7d390d57d87b277037f4e7b946606e6d4759852cbddc2f43b16daef6937e81b

Contents?: true

Size: 1.3 KB

Versions: 69

Compression:

Stored size: 1.3 KB

Contents

module RedHillConsulting::Core::ActiveRecord::ConnectionAdapters
  class ForeignKeyDefinition < Struct.new(:name, :table_name, :column_names, :references_table_name, :references_column_names, :on_update, :on_delete, :deferrable)
    ACTIONS = { :cascade => "CASCADE", :restrict => "RESTRICT", :set_null => "SET NULL", :set_default => "SET DEFAULT", :no_action => "NO ACTION" }.freeze

    def to_dump
      dump = "add_foreign_key"
      dump << " #{table_name.inspect}, [#{column_names.collect{ |name| name.inspect }.join(', ')}]"
      dump << ", #{references_table_name.inspect}, [#{references_column_names.collect{ |name| name.inspect }.join(', ')}]"
      dump << ", :on_update => :#{on_update}" if on_update
      dump << ", :on_delete => :#{on_delete}" if on_delete
      dump << ", :deferrable => #{deferrable}" if deferrable
      dump << ", :name => #{name.inspect}" if name
      dump
    end

    def to_sql
      sql = name ? "CONSTRAINT #{name} " : ""
      sql << "FOREIGN KEY (#{Array(column_names).join(", ")}) REFERENCES #{references_table_name} (#{Array(references_column_names).join(", ")})"
      sql << " ON UPDATE #{ACTIONS[on_update]}" if on_update
      sql << " ON DELETE #{ACTIONS[on_delete]}" if on_delete
      sql << " DEFERRABLE" if deferrable
      sql
    end
    alias :to_s :to_sql
  end
end

Version data entries

69 entries across 69 versions & 2 rubygems

Version Path
backlog-0.36.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
advertnet-1.0.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
advertnet-1.0.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.10.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.10.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.10.3 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.10.4 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.10.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.10.5 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.10.7 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.10.6 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.10.8 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.12.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.11.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.12.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.12.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.12.4 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.12.3 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.13.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb
backlog-0.14.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb