Many-to-many relationships in Kentico
Asked Answered
C

6

10

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?

Chassepot answered 8/3, 2011 at 12:44 Comment(1)
Assuming your storing your data to b presented as a website, then I think Kentico will work great.Cilla
C
7

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!

Cilla answered 10/3, 2011 at 14:34 Comment(0)
C
2

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

Circulate answered 2/8, 2011 at 7:26 Comment(0)
D
0

Using Custom Tables and writing your own custom webparts will help you a long way to accomplishing these goals.

Dogear answered 8/3, 2011 at 22:40 Comment(0)
C
0

You can also go a long way with creating custom Document Types for your Products and Recipes and then use the built in Link to an Existing Document functionality.

I do agree with dvanbale though, you could accomplish this as well with Custom Tables.

It kind of does depend on what you want to do exactly.

Chaos answered 9/3, 2011 at 13:26 Comment(2)
Agreed, in the example he provide the ecommerce module would also suffice, to make a better suggestion we would need to know more details of the spec.Dogear
What kind of extra information do you need? I am asking a "best practice" question here but it did spark from a real problem. I know about relationships in Kentico and I could build a "is ingredient of" relationship, but then every time the user creates a new recipe they have to remember to go the each product used and set the relationships manually. In the end I would like a list of related recipes on the product page and of related products on the recipe page and I would like to make it easy for the user to create this relationship. Has anyone built something like this before? Any advice?Chassepot
E
0

I've run into this a few times and came up with a quick work-around for the parent-child hierarchy of the content tree using a sql function and a sql repeater. By no means is it a robust implementation. If that was your immediate need, I would agree that custom tables is probably the way to go.

I actually just posted a detailed version of what I've done. I found this when I was searching to see if it was indexed. You can see it here:

http://www.kenticosolutions.com/Developer-Tips/Tip/May-2011/Many-to-Many-relationships-in-the-Kentico-CMS-Cont.aspx

Elderly answered 20/5, 2011 at 22:24 Comment(1)
Can you include the detail in your answer rather than through a link?Fishhook
R
0

It is possible to do this directly using kentico CMS and without writing any custom code or query.

Luckily I wrote an article about it and have successfully implemented it which gives enough flexibility to content admin to manage relational data without the need of a developer.

Related Content through a repeater

Radiotelegram answered 27/1, 2017 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.