How to implement a one-to-many relationship between a custom entity and products?

I’m creating a module that needs a relationship (one-to-many) between my custom model and Magento catalog Product model. To achieve this, I tried to copy the relationship between Magento’s Category and Product models, but I don’t fully understand how this relationship is made.

Can you show me an overview of the implementation (in both model and database levels) of this relationship ?

The relationship between categories and products is not a right example for you, because it is a many-to-many relationship, not one-to-many.

An example of one-to-many relationship with products on the “many” side is a relationship bethween products and their types.

1 Like