/** * Shortcut for adding foreign keys * * @param Varien_Db_Ddl_Table $table * @param Varien_Db_Ddl_Table|string $refTable * @param string $columnName * @return Mzax_Emarketing_Model_Resource_Setup */ public function addForeignKey(Varien_Db_Ddl_Table $table, $refTable, $columnName) { if ($refTable instanceof Varien_Db_Ddl_Table) { $refTable = $refTable->getName(); } else { $refTable = $this->getTable($refTable); } $fkName = $this->getFkName($table->getName(), $columnName, $refTable, $columnName); $table->addForeignKey($fkName, $columnName, $refTable, $columnName, Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE); return $this; }
<?php /* @var $this Mage_Core_Model_Resource_Setup */ $this->startSetup(); $quotes = new Varien_Db_Ddl_Table(); $quotes->setName($this->getTable('guestcookies/quote')); // Reference to foreign table $quotes->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 10, array('primary' => true, 'nullable' => false, 'unsigned' => true)); $quotes->addForeignKey('FK_GUESTCOOKIES_QUOTE_ID_SALES_QUOTE_ENTITY_ID', 'quote_id', $this->getTable('sales/quote'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE); // Token key to be stored in cookie $quotes->addColumn('token', Varien_Db_Ddl_Table::TYPE_CHAR, 32, array('nullable' => false)); $quotes->addIndex('IDX_TOKEN', 'token', array('unique' => true)); $this->getConnection()->createTable($quotes); $this->endSetup();