Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[SOLVED] Finding and filtering multiple related data objects


18 Posts   2527 Views

Ryan M.

7 November 2010 at 12:45pm Community Member, 309 Posts

You're right it doesn't make any difference. I tried your suggestion of using $do->push($record) instead of $do->push(new ArrayData($record)) but no change. I'm definitely sure it's got something to do with find()

Ryan M.

7 November 2010 at 1:44pm Community Member, 309 Posts

I figured out a solution without even using find().

Final code:

public function FeaturedVideo() {
      $vid = null;
      if($ClassName = "ProfileHolder" && $cat = $this->urlParams['ID']) {
         $cat = str_replace('-', ' ', $cat);
         $cat = ucwords($cat);
         $ccid = DataObject::get_one("ClientCategory", "Name = '{$cat}'")->ID;
         $profiles = DataObject::get("Profile", "ClientCategoryID = $ccid");
         $videoIDs = array();
         foreach($profiles as $profile => $data) {
            foreach($data->Videos() as $video) {
               $videoIDs[] = $video->ID;
         $vids = new DataObjectSet();
         foreach($videoIDs as $id) {
            $record = DataObject::get_by_id("Video", $id);
            if($record->Featured = true) {
         $vids->sort('LastEdited', 'DESC');
         $vid = $vids->First();
      if($vid) {
         return DataObject::get_by_id("Video", $vid->ID);
      } else
         return DataObject::get_one("Video", "Featured = true");