Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Many-to-many relationships in Kentico

Are there any best practices on how to build a Kentico CMS Portal implementation which is based around a many-to-many relationship (i.e. a website which sells food product and has a large section with recipes -- each product is used in many recipes, each recipe can use many of the products sold on the site)?

Is Kentico simply the wrong tool to do this or are there solutions within Kentico to handle this kind of relationships?

like image 286
Francesco Gallarotti Avatar asked Mar 08 '11 12:03

Francesco Gallarotti


2 Answers

I would consider the built in Related Documents system. Under the properties tab on a document, there is a section for the related documents. The functionality is described here:

Document Properties, Related Docs

If this was a big piece of functionality for your website, you could probably add the section as another tab to the existing Page, Design, Form, Properties tabs for easier access. You would just need to modify the Modules area of Site Manager -> Development . Another heads up: they are technically unidirectional relationships, but you can structure your queries to go both ways:

SELECT *
FROM CMS_Document d
JOIN CMS_Relationship r 
    ON (d.DocumentID = r.LeftNodeID
    OR d.DocumentID = r.RightNodeID)
Where DocumentID = 100

The above code will join the CMS_Document table to the CMS_Relationship table to give you all the related documents for Document with ID 100.

If you take a peak at the database, the table structure for Related Documents is VERY simple:

Related Document Tables

So as McBeev suggested, I would create a custom document types for the products and the recipes. Then you can link them as I outlined above. Good luck!

like image 123
John B Avatar answered Nov 08 '22 07:11

John B


Out of the box it does not support many-to-many very well, however you should be able to do it with a bit of custom development. Create the 2 custom document type, such as Recipes and Products, then create a custom Form Control to manage the relationship. You then place the Form Control on the page so that the fields are managable on the Form tab of the node. The Form Control (or 2 if you want to manage from both types) would be a many-to-many type control such as a list of checkboxes or a multi-select. Then on saving you would use API or SQL code to save to the join table rather than the document itself (or child document type). You may need to create the join table manually.

http://www.kentico.com/docs/devguide/index.html?developing_form_controls.htm

like image 21
Ben E G Avatar answered Nov 08 '22 07:11

Ben E G