开发者

Many-to-many relationships in Kentico

Are ther开发者_开发技巧e 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?


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:

Many-to-many relationships in Kentico

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!


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


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


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜