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   2525 Views

Avatar
cuSSter

4 November 2010 at 9:16pm Community Member, 56 Posts

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

/C

Avatar
swaiba

4 November 2010 at 10:14pm Forum Moderator, 1796 Posts

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.

5 November 2010 at 8:10am Community Member, 309 Posts

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

5 November 2010 at 8:45am Forum Moderator, 1796 Posts

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.

5 November 2010 at 8:50am Community Member, 309 Posts

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

5 November 2010 at 8:53am Forum Moderator, 1796 Posts

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.

5 November 2010 at 9:01am Community Member, 309 Posts

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

5 November 2010 at 10:07am (Last edited: 6 November 2010 10:00pm), Forum Moderator, 1796 Posts

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