I’m trying to build a snippet which can process the children of a document. However, I’m finding that the $modx->resource->getMany() function is behaving very strangely. Perhaps I’m missing something glaringly obvious, but any suggestions/feedback would be welcome at this point.
To demonstrate the issue I’m having with getMany() I’ve written a simple snippet as follows:
$output = "";
// getMany call #1
$criteria1 = $modx->newQuery('modResource');
$criteria1->where(array(
'parent' => $id1
));
$output .= "<p>document $id1 has ".sizeof($modx->resource->getMany('Children',$criteria1))." children</p>";
// getMany call #2
$criteria2 = $modx->newQuery('modResource');
$criteria2->where(array(
'parent' => $id2
));
$output .= "<p>document $id2 has ".sizeof($modx->resource->getMany('Children',$criteria2))." children</p>";
return $output;
I call this snippet from a simple template which contains only one line: [[!getManyTest?id1=`11`&id2=`12`]].
I should point out that document #11 has 7 children, and document #12 as 2 children in my document/resource tree. These documents are siblings in the tree (at the same level) and do not have a parent-child relationship, not that it should matter.
Now, when I run the snippet with both getMany calls I get:
document 11 has 7 children -- this is correct
document 12 has 7 children -- this is incorrect
If I reverse the order of the calls I get:
document 12 has 2 children -- this is correct
document 11 has 2 children -- this is incorrect
Additionally, commenting out either of the getMany() calls returns the correct answer every time.
Can anyone explain why this is happening? It appears to me that once getMany() has been called, the criteria remains the same for every subsequent call. Perhaps I should be fetching child documents in an entirely different way?
Any ideas would be greatly apprieciated.
I’m using MODx Revolution 2.0.0-pl rev7212 (basic installation) on a Linux server with PHP 5.2.13 and MySQL 5.0.91.