Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Listing 2 DataObjectSets

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

Page: 1
Go to End
Author Topic: 332 Views
  • eceers
    Avatar
    Community Member
    24 Posts

    Listing 2 DataObjectSets Link to this post

    Howdy, I have created 2 DataObjects Rewards and Redemptions. I would like to display them on a single list sorted by their created field.

    Here is the code doing the work;

    function getRewardRedemptions() {   
       $doSet = new DataObjectSet();

       if($Rewards = DataObject::get('Rewards',"MemberID={$this->Member->ID}")) {
          $doSet->merge($Rewards);
       }
       if($this->Member && $Redemptions = DataObject::get('Redemptions',"MemberID={$this->Member->ID}")) {
          $doSet->merge($Redemptions);
       }
       $doSet->Sort('Created');
       
       return $doSet;
    }

    It all works a-ok with one small hick up the list is grouping the Objects. So all the rewards and the redemptions are sitting together. What I would like to happen is the rewards and redemptions to be intertwinned.

    I'm pretty certain there is one little tweak I need to make so it all falls into place.

    Any help would be greatly appreciated.

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Listing 2 DataObjectSets Link to this post

    What you are doing should work - at least within your getRewardRedemptions function itself. Did you do a var_dump there, or a foreach echo?

    What does your template look like? (the bit that handles getRewardRedemptions)?

  • eceers
    Avatar
    Community Member
    24 Posts

    Re: Listing 2 DataObjectSets Link to this post

    Thanks Martimiz, It turns out the problem was mine. Although the redemption has a created field there was also a sent date. So it was working correctly.

    I did a var_dump I could see that the Created field was way back when. Once I started using the correct date field all was sweet.

    Thanks again.

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