Jump to:

3432 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataObjectSet()->groupWithParents()

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

Page: 1
Go to End
Author Topic: 612 Views
  • SilverDan
    Avatar
    Community Member
    5 Posts

    DataObjectSet()->groupWithParents() Link to this post

    I've been using the DataObjectSet function 'groupWithParents()' with some limited success on my site. Basically, the problem I've run into is that the function seems to be failing without any errors when the dataobject has no matching results. Here's the code in the custom function I'm running:

    $grouped = $this->Expertise()->groupWithParents('ParentID','ExpertisePage');

    Where: $this->Expertise() is a many_many relationship.
    This function works if $this->Expertise() contains items whose Parent->ClassName = 'ExpertisePage', but fails if ALL items Parent->ClassName != 'ExpertisePage'. I've tried a Try/Catch block, but no exception occurs. I've also tried setting the collapse parameter to 'true', but still no go!

    There seems to be very little information about this function apart from the basics found in the API.

    Anyone had any experience with this, or should I submit it as a bug?

    Thanks in advance

    Here's a brief explanation of what I'm trying to achieve. In the CMS we have a page which has a multi-select-tree-dropdown control for assigning 'Expertise' areas (pages in the site tree of ClassName 'ExpertisePage'). This all works fine. In the frontend, I can control-output these Expertise items in a simple <ul> style nav. I'm now trying to group these expertise links in a nice 2-level <ul> list so if a sub-level Expertise is assigned to the page, it will show up under it's Expertise parent. It needs to be able to work for multiple sub-levels and group them with their parent only once.

    - Expertise Parent (not assigned to page, but included because sub's are assigned)
    - Expertise Sub1 (assigned to page)
    - Expertise Sub2 (assigned to page)
    - Expertise Parent (assigned to page)

    612 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.