Jump to:

3461 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Dynamically associate one page type to another?

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

Page: 1
Go to End
Author Topic: 988 Views
  • ck_bullet
    Community Member
    16 Posts

    Dynamically associate one page type to another? Link to this post

    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.

  • Willr
    Forum Moderator
    5511 Posts

    Re: Dynamically associate one page type to another? Link to this post

    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


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.