Class: Ardb::MigrationHelpers::ForeignKey

Inherits:
Object
  • Object
show all
Defined in:
lib/ardb/migration_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_table, from_column, to_table, options = nil) ⇒ ForeignKey

Returns a new instance of ForeignKey.



27
28
29
30
31
32
33
34
35
# File 'lib/ardb/migration_helpers.rb', line 27

def initialize(from_table, from_column, to_table, options=nil)
  options ||= {}
  @from_table  = from_table.to_s
  @from_column = from_column.to_s
  @to_table    = to_table.to_s
  @to_column   = (options[:to_column] || 'id').to_s
  @name        = (options[:name] || "fk_#{@from_table}_#{@from_column}").to_s
  @adapter     = Ardb::Adapter.send(Ardb.config.db.adapter)
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



25
26
27
# File 'lib/ardb/migration_helpers.rb', line 25

def adapter
  @adapter
end

#from_columnObject (readonly)

Returns the value of attribute from_column.



25
26
27
# File 'lib/ardb/migration_helpers.rb', line 25

def from_column
  @from_column
end

#from_tableObject (readonly)

Returns the value of attribute from_table.



25
26
27
# File 'lib/ardb/migration_helpers.rb', line 25

def from_table
  @from_table
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/ardb/migration_helpers.rb', line 25

def name
  @name
end

#to_columnObject (readonly)

Returns the value of attribute to_column.



25
26
27
# File 'lib/ardb/migration_helpers.rb', line 25

def to_column
  @to_column
end

#to_tableObject (readonly)

Returns the value of attribute to_table.



25
26
27
# File 'lib/ardb/migration_helpers.rb', line 25

def to_table
  @to_table
end

Instance Method Details

#add_sqlObject



37
38
39
# File 'lib/ardb/migration_helpers.rb', line 37

def add_sql
  apply_data(@adapter.foreign_key_add_sql)
end

#drop_sqlObject



41
42
43
# File 'lib/ardb/migration_helpers.rb', line 41

def drop_sql
  apply_data(@adapter.foreign_key_drop_sql)
end