Jump to:

3462 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Returning data grouped by value [SOLVED]

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

Page: 1
Go to End
Author Topic: 1222 Views
  • LesC
    Avatar
    Community Member
    70 Posts

    Returning data grouped by value [SOLVED] Link to this post

    I've got a bunch of dataobjects (lets call them Events) that each have a related category (EventCategory) and I'd like to return these to the template view so that I could show the events listed by category, something like:

    Category 1 title
    Event name
    Event name

    Category 2 title
    Event name

    Category 3 title
    Event name
    Event name

    How would I go about doing this, so that I can have a dynamic amount of categories (a category will always have events too)?

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Returning data grouped by value [SOLVED] Link to this post

    I recently had the same question and the way that I got around it was to use the NestedDataObjectManager, this allowed each page to has_many categories then each category to has_many objects. This way you could add many categories to each page as needed then add the objects to those categories. In the template it was then as simple as:

    <% control Categories %>
    $CategoryTitle
    <% control Events %>
    $EventTitle - $Description
    <% end_control %>
    <% end_control %>

  • LesC
    Avatar
    Community Member
    70 Posts

    Re: Returning data grouped by value [SOLVED] Link to this post

    Thanks Howard, I worked it out just as you posted that one!

    Cheers

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