Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Object Relations with many_many

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

Page: 1
Go to End
Author Topic: 813 Views
  • toddmkimball
    Avatar
    Community Member
    13 Posts

    Object Relations with many_many Link to this post

    Has anyone developed an application with SilverStripe where an object has a many to many relationship with another object, and the related object has a many to many relationship with another object? e.g. Let's say I have a resource, and the resource has stages. A resource can have 1-n stages and a stage can be assigned to 1-n resources. In addition, a stage can have 1-n categories and a category be assigned to 1-n stages for each resource, but the relationship between stages and categories is not the same for every resource. Can SilverStripe handle a data model such as this? What would the workflow look like? In my estimation a user would:
    1. Create a resource
    2. Assign a stage
    3. Assign categories to the stage related to the resource.
    4. Repeat steps two and three for each additional stage assigned to the resource.

    Regards,
    Todd

  • sergieboy
    Avatar
    Community Member
    33 Posts

    Re: Object Relations with many_many Link to this post

    I work since four weeks with SS, and my primary concern is not the flashy lights and bells, but the management of a datamodel with several levels : objectA N----M object B N------M object C N------M object D
    I have same concerns of yours and I'm afraid that SS is not capable of handing this.
    F.Ex the DOM is very nice but only handles up to 2 levels .

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Object Relations with many_many Link to this post

    This is a little confusing the title is "many_many" but the notation in both posts are "1-n" and "n-m"... maybe if you stick to a slightly more long hand "has_many" or "many_many" this would be crystal clear.

    Using ModelAdmin I have not come across any relationship depths it is unable to handle in the form...

    a has_many b
    b has_many c
    c has_many d

    It opens a greybox popup to edit the relationship and then if you keep drilling down it down replace the greybox popup with the new one. This has a limitation of no back (i.e. once editing d you can only return to a, not c).

    If d has_many a this creates a circle and the scaffolding fails - easily fixed by removing it within getCMSFields, but it ends the ability to "drill down" into the relationship.

    I normally handle the many_many with multi select rather than the ManyManyComplexTableField, but I assume if I didn't it would allow the editing of the relationship as above.

    So to summarise - avoid circular relationships and try to use ModelAdmin.

    813 Views
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.