Y
Y
yv19952016-10-11 22:50:07
ORM
yv1995, 2016-10-11 22:50:07

How to link two tables one to many in ORM?

I am making a module for magento and in the install file I need to link two tables:
The first menu table, the second link table, i.e. one menu - many links
Here are the sources themselves:
$installer = $this;
$tableCmsMenu = $installer->getTable('customcmsmenu/table_cmsmenu');
$tableCmsMenuLinks = $installer->getTable('customcmsmenu/table_cmsmenulinks');
$installer->startSetup();
$installer->getConnection()->dropTable($tableCmsMenu);
$installer->getConnection()->dropTable($tableCmsMenuLinks);
$tableMenu = $installer->getConnection()
->newTable($tableCmsMenu)
->addColumn('menu_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'identity' => true,
'nullable' => false,
'primary' => true,
))
->addColumn('menu_name', Varien_Db_Ddl_Table::TYPE_VARCHAR, '255', array(
'nullable' => false,
))
->addColumn('status ', Varien_Db_Ddl_Table::TYPE_VARCHAR, '255', null, array(
'nullable' => false,
))
->addColumn('created', Varien_Db_Ddl_Table::TYPE_DATE, null, array(
'nullable' => false,
)) ;
$tableLinks = $installer->getConnection()
->newTable($tableCmsMenuLinks)
->addColumn('links_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null,
'primary' => true,
))
->addColumn('label', Varien_Db_Ddl_Table::TYPE_TEXT, '255', array(
'nullable' => false,
))
->addColumn('url_key', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
'nullable' => false,
))
->addColumn('position', Varien_Db_Ddl_Table::TYPE_VARCHAR, '255', null, array(
'nullable' => false,
))
->addColumn('type' , Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
'nullable' => false,
));
$installer->getConnection()->createTable($tableMenu);
$installer->getConnection()->createTable($tableLinks);
$installer->endSetup();
Что нужно дописать, чтобы их связать? Спасибо)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
imdeveloper, 2016-10-12
@link_web

А если у вас ссылки будут добавляться позже? Что мешает в модуле в нужный блок поместить уже связанные через модели данные?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question