Many-to-many relationship between entities of same type (products ↔ products)

By default, AtroPIM uses many-to-many relationships e.g. between products and categories. This uses the relation table product_category with columns category_id and product_id.

I’ve tried to create a new many-to-many relationship between products and products, but it didn’t work. The created relation table product_product only contains one product_id and is missing the second ID for the foreign key. I’ve looked into the source code of AtroPIM and it appers that the class \Espo\Core\Utils\Database\Orm\Relations\ManyMany cannot handle a relationship where the entity and the foreign entity are of the same type.

My use case is to add products as accessories to a main product and to view which products are linked to a given product. For example:

  • Product “Notebook” has products “Keyboard” and “Mouse” as accessories
  • Product “Tablet” has product “Keyboard” as accessory
  • → Product “Keyboard” has products “Notebook” and “Tablet” as linked products (reverse)

Do you know if this could be achieved with the paid module “Advanced Data Types” or if there is another workaround that I have overlooked?

Hello fh_aimcom!
You can use Product Bundles module to also achieve this goal.

Thank you for your reply! I’ve searched for the module but only found 404 error pages:

The AtroCore store search doesn’t find anything else for “product bundles”. Does this module still exist?

Hello @fh_aimcom product-bundles has been deprecated, now you can use Associated Product to achieve your goal, you just need to define a custom Association (using the Entity Association) for your use case. it is available in Atrocore v2.0.0. You can activate associate for any entity in entity Management with the configuration Has associate

1 Like

Cool, “Entity Association” works pretty well! Thank you! :+1: