Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Dynamically associate one page type to another?

Go to End

2 Posts   1202 Views


Community Member, 16 Posts

24 August 2010 at 10:02am

Edited: 24/08/2010 10:04am

I would like to be able to "associate" as many items of one page type to another in the CMS. For example, I have a Person class that has certain properties ie name, email, phone number etc. Then I have a ContactPage class which has things like address, phone number, fax number, etc. However, in the CMS I would like to add as many Person items to the ContactPage. It's easy if I just want one, I have a has_one inside the ContactPage class $has_one = array('ContactPerson' => 'Person') and then create a new DropdownField which is a list of all the Person items. My initial thinking is that you have one dropdown field with a button that says add another and clicking it dynamically inserts another dropdown field using jquery. I don't know if this is the best approach. Has any attempted to do something like this? Is there a simple solution that I'm completely missing? Oh and in the Site tree these 2 items cannot be parent-child. I already have a PersonHolder page where all the Person items go under. Thanks.


Forum Moderator, 5521 Posts

24 August 2010 at 8:36pm

So basically what you want to use is rather than a has_one you want the has_many option (or a many_many might be better). Then you have a wide range of fields which allows you to manage has_many / many_many relationships.

Out of the box you can use something like the ManyManyComplexTableField or a CheckboxSetField.

A couple of modules also contain nice ways to managing many manys