Hello! I'm trying to get a collection of objects with this snippet
$ids = $modx->getChildIds($modx->resource->id);
$query=$modx->newQuery('modResource');
$query->setClassAlias('mR');
$query->leftJoin('modTemplateVarResource','mTVR','mR.id=mTVR.contentid AND mTVR.tmplvarid=1');
$query->select(array('mR.id','mR.pagetitle','mTVR.value price'));
if(count($ids)>0){
$query->where(array("mR.id:IN"=>$ids));
}
else{
$query->where(array("mR.id"=>$modx->resource->id));
}
$col = $modx->getCollection('modResource',$query);
$modx->log(1,$query->toSQL());
foreach($col as $c){
$params = $c->toArray();
$modx->log(1,print_r($params,true));
$output.=$modx->getChunk($tpl,$params);
}
return $output;
SQL query in log is:
SELECT mR.id, mR.pagetitle, mTVR.value price FROM `modx_site_content` AS `mR` LEFT JOIN `modx_site_tmplvar_contentvalues` `mTVR` ON mR.id=mTVR.contentid AND mTVR.tmplvarid=1 WHERE `mR`.`id` = 213
So, every thing is fine but when I see logged objects ( $modx->log(1,print_r($params,true)) ) they have all thair fields as I would get all fields from DB. But my query contains only id, pagetitle and price. Can anybody help me? I was debugging sources of xPdo, acessibleSimpleObject and modResource, but there is no any extra fields, only fields from my query. But when I see log my objects have all their fields filled with data of that object. If I had had the object with fields pagetitle='p',alias='a',content='c' and executed my query I would get the same object (pagetitle='p',alias='a',content='c'). I thought that not presenting in query fields should be blank or default. I guess that answer should be rather simple, and digging sources isnt a right way. I'm stumped and will be glad for any help.
[ed. note: Qwarble last edited this post 14 years, 1 month ago.]