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.

Data Model Questions /

How to merge two DataObjectSets


Reply


3 Posts   1673 Views

Avatar
novaweb

Community Member, 115 Posts

16 April 2010 at 9:25am

Edited: 16/04/2010 9:26am

Hey guys,

Really simple one here. I'm wondering if one can take two DataObjectSets (from two separate DataObject::get requests) and join them together.

I have two different DataObjects, Module.php and Course.php. I want to call both of them using one function, so I can order both Modules AND Courses by Title ASC using a control block.

Currently the code I have is:

function Modules(){
return DataObject::get("Module");
}

function Courses(){
return DataObject::get("Course");
}

Can I do what i'm trying to achieve in it's own function? Or can I reference the above functions in another function to achieve the join?

Cheers,
Josh

Avatar
dayer

Community Member, 11 Posts

17 August 2010 at 5:01am

I have the same doubt.

Avatar
swaiba

Forum Moderator, 1804 Posts

17 August 2010 at 9:01am

how about...

function Composite()
{    
   $dosComposite = new DataObjectSet();
   $dosComposite->merge($this->Modules());      
   $dosComposite->merge($this->Courses());      
   $dosComposite->sort('FieldName','ASC');
   
   return $dosComposite;
}