cancel
Showing results for 
Search instead for 
Did you mean: 

Relationships between custom table and system defined table

SOLVED

Relationships between custom table and system defined table

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.

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Relationships between custom table and system defined table

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

 

View solution in original post

Re: Relationships between custom table and system defined table

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...

View solution in original post

3 REPLIES 3

Re: Relationships between custom table and system defined table

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

 

Re: Relationships between custom table and system defined table

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

 

 

Re: Relationships between custom table and system defined table

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...