Creeaza foreign key in installer magento

In installerul modului presupunem ca ati creat un tabel –

$installer = $this;

$installer->startSetup();

$moduleTableName = $installer->getTable('mymodule/mymodule');
if($installer->getConnection()->isTableExists($moduleTableName) != true) {
    $table = $installer->getConnection()
        ->newTable($moduleTableName);
$installer->getConnection()->createTable($table);

Pe una din coloanele create doriti sa creati un foreign key -> asemanator

->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
    'nullable'  => false,
), 'Created at')

exista (->addForeignKey())

->addForeignKey(
    $installer->getFkName(
        'mymodule/mymodule',
        'product_id',
        'catalog/product',
        'entity_id'
    ),
    'product_id', $installer->getTable('catalog/product'), 'entity_id',
    Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE
);

 

Marmureanu Web: Programator ca meserie, mtb-ist ca pasiune.