Yeah, that's what I'm using. Still not working yet. But check out my latest progress.
This is a version that I tried
<?php
$path = MODX_CORE_PATH . 'components/myPackageName/';
$result = $modx->addPackage('myPackageName',$path .
'model/','ssm_');
/*SETS COLLECTION TO GET ALL COMPANIES*/
$query = $modx->newQuery('Companies');
$query->limit(15);
$query->leftJoin('modTemplateVarResource', 'TVR', array(
'Companies.id' => 'TVR.value',
));
$query->select($modx->getSelectColumns('Companies','Companies','co_',array('id','company_name')));
$whereArray = array(
'active'=>1
);
$query->where($whereArray);
$query->sortby('company_name','ASC');
// prepare and dump the SQL to the log
$query->prepare();
$modx->log(xPDO::LOG_LEVEL_ERROR, $query->toSql());
$companies = $modx->getCollection('Companies',$query);
foreach($companies as $company) {
$co_details = $company->toArray();
$output .= $modx->getChunk('tpl.company-row-pdo', $co_details);
}
return $output;
I get all the same results as when I didn't have the left join. Notice what the SQL output says
SELECT `Companies`.`id` AS `Companies_id`, `Companies`.`ticker` AS `Companies_ticker`, `Companies`.`company_name` AS `Companies_company_name`, `Companies`.`company_description` AS `Companies_company_description`, `Companies`.`exchange` AS `Companies_exchange`, `Companies`.`active` AS `Companies_active` FROM `ssm_companies` AS `Companies` LEFT JOIN `modx_site_tmplvar_contentvalues` `TVR` ON `Companies`.`id` = 0 WHERE `Companies`.`active` = 1 ORDER BY company_name ASC LIMIT 15
You see the "
ON `Companies`.`id` = 0"? Shouldn't it say "ON `Companies`.`id` = `TVR`.`value` and not a ZERO? I'm thinking it's not returning anything for TV.value because of the conflicting ID columns in the two tables. Just a guess.
So, I tried the same code, just with an added "getSelectColumns" in there so that I could prefix the queried columns
$query->select($modx->getSelectColumns('Companies','Companies','co_',array('id','company_name')));
The prefixing worked, but didn't solve my problem. (Strangely, it caused a 404 error)
Furthermore, I added
$fields = $modx->getFields('Companies');
print_r($fields);
after my join statement and it still only returns the original set of columns.
Array ( [id] => [ticker] => [company_name] => [company_description] => [exchange] => [active] => 1 )
If the join was successful, would this printout show the newly combined columns?
I've tried so many things -including hydrating- and nothing seems to work.
(Part of my problem is that the documentation for xPDO doesn't include very much information beyond what the function is supposed to do. So, I'm piecing things together from different people's forum posts.)