What is the best way to create the tables relationships like one to many, many to many in magento 2? Specifically between a custom table created for a module and a system-defined table like Products table.
Thanks in advice.
Solved! Go to Solution.
You can define relationship between tables in a usual way, using foreign keys.
http://dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html
How to add a foreign key to a database table: https://mage2.pro/t/569
Magento uses its own classes inherited from Zend Framework classes.
An example of join: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/AdvancedPricingImportExport/Model/Ex...
You can define relationship between tables in a usual way, using foreign keys.
http://dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html
How to add a foreign key to a database table: https://mage2.pro/t/569
Hi Dmitry,
thanks for your response. Another question, when I have to get data from the relationship (join between the tables) is there a way to use Magento Framework or should I make a query in database using zend framework?
Thanks again
Magento uses its own classes inherited from Zend Framework classes.
An example of join: https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/AdvancedPricingImportExport/Model/Ex...