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


Reply


18 Posts   2584 Views

Avatar
cuSSter

Community Member, 56 Posts

4 November 2010 at 9:16pm

Sorry, I wasn't aware that Profile and Videos has a relationship.

/C

Avatar
swaiba

Forum Moderator, 1799 Posts

4 November 2010 at 10:14pm

Hi Ryan,

Have you debugged what is coming before?

print_r($vids); die(); //see what values 'Featured' has before the find
$vids->sort('Created', 'DESC');
$videos = $vids->find('Featured', 'true');

Barry

Avatar
Ryan M.

Community Member, 309 Posts

5 November 2010 at 8:10am

Hi Swaiba, yea if you notice one of my previous posts, it said I tried one line earlier and it returned all the dataobjects available. It's the find() function that doesn't work. =(

Avatar
swaiba

Forum Moderator, 1799 Posts

5 November 2010 at 8:45am

doh! I guess what I meant to ask is what is the data... the find function looks simple so it'd help to see the data... btw I wrap my output buffering around my print_r's so I can log 'em if it helps...

ob_start();
print_r($arr);
$var = ob_get_contents();
ob_end_clean();

Avatar
Ryan M.

Community Member, 309 Posts

5 November 2010 at 8:50am

The data displayed is a DataObjectSet of the DataObjects returned by this:

$vids = new DataObjectSet();
foreach($videoIDs as $id) {
$record = DataObject::get_by_id("Video", $id);
$vids->push(new ArrayData($record));
}
$vids->sort('Created', 'DESC');

Avatar
swaiba

Forum Moderator, 1799 Posts

5 November 2010 at 8:53am

Actually, that is not how I've ever done it...

instead of...

$vids->push(new ArrayData($record));

i use...

$vids->push($record);

...does that help?

Avatar
Ryan M.

Community Member, 309 Posts

5 November 2010 at 9:01am

I'll give it a try. That's not how the SS documentation for DataObjectSet says how to do it though... lol, these guys need to update the documentation. =)

Avatar
swaiba

Forum Moderator, 1799 Posts

5 November 2010 at 10:07am

Edited: 06/11/2010 10:00pm

well code is often the best documentation :)

throughout the code ss creates DataObjectSets with $dos->push($do) or $dos->push(new ArrayData(array(...))), what you've got is $dos->push(new ArrayData($do)) where ArrayData and DataObject are both similar sorts of classes, not like when ss creates a ArradyData with an array of values.

EDIT on this it looks like arraydata takes both as arguments to it's constructor and it may not make any difference...