Class: Ardb::MigrationHelpers::ForeignKey
- Inherits:
-
Object
- Object
- Ardb::MigrationHelpers::ForeignKey
- Defined in:
- lib/ardb/migration_helpers.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#from_column ⇒ Object
readonly
Returns the value of attribute from_column.
-
#from_table ⇒ Object
readonly
Returns the value of attribute from_table.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#to_column ⇒ Object
readonly
Returns the value of attribute to_column.
-
#to_table ⇒ Object
readonly
Returns the value of attribute to_table.
Instance Method Summary collapse
- #add_sql ⇒ Object
- #drop_sql ⇒ Object
-
#initialize(from_table, from_column, to_table, options = nil) ⇒ ForeignKey
constructor
A new instance of ForeignKey.
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, =nil) ||= {} @from_table = from_table.to_s @from_column = from_column.to_s @to_table = to_table.to_s @to_column = ([:to_column] || 'id').to_s @name = ([:name] || "fk_#{@from_table}_#{@from_column}").to_s @adapter = Ardb::Adapter.send(Ardb.config.db.adapter) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
25 26 27 |
# File 'lib/ardb/migration_helpers.rb', line 25 def adapter @adapter end |
#from_column ⇒ Object (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_table ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/ardb/migration_helpers.rb', line 25 def name @name end |
#to_column ⇒ Object (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_table ⇒ Object (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_sql ⇒ Object
37 38 39 |
# File 'lib/ardb/migration_helpers.rb', line 37 def add_sql apply_data(@adapter.foreign_key_add_sql) end |
#drop_sql ⇒ Object
41 42 43 |
# File 'lib/ardb/migration_helpers.rb', line 41 def drop_sql apply_data(@adapter.foreign_key_drop_sql) end |