I am trying to get a list of name-value pairs of all TVs of a Resource, in a Snippet. And I am having the problem of innerJoin + select (with both string argument and the commented
$modx->getSelectColumns statements) not working together. The code is:
$criteria = $modx->newQuery('modTemplateVar');
$criteria->innerJoin(
'modTemplateVarResource',
'TVi',
array('`modTemplateVar`.id = TVi.tmplvarid')
);
$criteria->select('`modTemplateVar`.`caption`, `TVi`.`value`');
/* $criteria->select($modx->getSelectColumns(
'modTemplateVar',
'modTemplateVar',
'',
array('caption')
));
$criteria->select($modx->getSelectColumns(
'modTemplateVarResource',
'TVi',
'',
array('value')
)); */
$criteria->where(
array('TVi.contentid'=>$modx->resource->get('id'),
'TVi.value:!=' => '')
);
// $criteria->prepare();
// return $criteria->toSQL();
$tvs = $modx->getCollection('modTemplateVar',$criteria);It gives
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in /my/site/path/core/xpdo/om/xpdoobject.class.php on line 116
Uncommenting return prints the query:
SELECT `modTemplateVar`.`caption`, `TVi`.`value`
FROM `bsaz_site_tmplvars` AS `modTemplateVar`
JOIN `bsaz_site_tmplvar_contentvalues` `TVi`
ON `modTemplateVar`.id = TVi.tmplvarid
WHERE ( `TVi`.`contentid` = '12' AND `TVi`.`value` != '' )
As
jaredloman mentioned, removing the
select makes the code work, but I really need that
value column in the result.
Could anyone please point at where I am doing wrong, or suggest some other solution?
Thanks!