$childs = $modx->getCollectionGraph('modResource', '{"TemplateVarResources":{}}', array(
'parent' => $parentId,
'TemplateVarResources.tmplvarid:IN' => array(1, 2, 3)
));
This question has been answered by klermonte. See the first response.
foreach($childs as $child) {
foreach($child->TemplateVarResources as $tv) {
if ($tv->get('tmplvarid') == 1) {
$tv1_value = $tv->get('value');
}
if ($tv->get('tmplvarid') == 2) {
$tv2_value = $tv->get('value');
}
}
}
$child_array = $child->toArray('', true);
foreach ($child->TemplateVarResources as $tv) {
$child_array['tv'][$tv->get('tmplvarid')] = $tv->get('value');
}
$tvs = $modx->getCollection('modTemplateVar', array(
'id:IN' => array(1, 2, 3)
));
$tvs_array = array();
foreach ($tvs as $tv_obj) {
$tvs_array[$tv_obj->get('id')] = $tv_obj->get('name');
}
...
foreach ($childs as $child) {
$child_array = $child->toArray('', true);
foreach ($child->TemplateVarResources as $tv) {
$child_array['tv'][$tvs_array[$tv->get('tmplvarid')]] = $tv->get('value');
}
}