Class: Baza::Driver::Mysql::ForeignKeys
- Inherits:
-
Object
- Object
- Baza::Driver::Mysql::ForeignKeys
- Defined in:
- lib/baza/driver/mysql/foreign_keys.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
- #create(from:, to:) ⇒ Object
-
#initialize(db:) ⇒ ForeignKeys
constructor
A new instance of ForeignKeys.
Constructor Details
#initialize(db:) ⇒ ForeignKeys
Returns a new instance of ForeignKeys.
4 5 6 |
# File 'lib/baza/driver/mysql/foreign_keys.rb', line 4 def initialize(db:) @db = db end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
2 3 4 |
# File 'lib/baza/driver/mysql/foreign_keys.rb', line 2 def db @db end |
Instance Method Details
#create(from:, to:) ⇒ Object
8 9 10 11 12 |
# File 'lib/baza/driver/mysql/foreign_keys.rb', line 8 def create(from:, to:) sql = "ALTER TABLE #{from[0]} ADD FOREIGN KEY (#{from[1]}) REFERENCES #{to[0]}(#{to[1]})" db.query(sql) end |