I’m trying to migrate some old snippet code into the new API. I’ve successfully set it up where I can retrieve/query my custom object. The problem I’m running into is when I attempt to reference a core Modx object from my custom object. Specifically, I’m trying join my xPDOQuery on the modUser object. I don’t get any errors, it just doesn’t do anything.
Here’s my code:
$base_path = MODX_CORE_PATH . 'components/foobar';
$modx->addPackage('myFooBar',$base_path.'/model/','');
$query = $modx->newQuery('Foo');
$query->innerJoin('Users','u', array('user_fk' => 'u.id')); // tried modUser vs Users and it didn't work
$query->select($modx->getSelectColumns('Foo','Foo','',
array(
'fooid',
'fooDescription',
'u.username',
'user_fk',
'fooContent',
'fooPublic'
)
)
);*/
$query->where(array(
'fooDescription:!=' => '',
'fooPublic' => 0
));
$query->sortby('fooPublic','DESC');
$query->limit(20,0);
$results = $modx->getCollection('Foo',$query);
foreach($result as $res){
//$username = $modx->getObject('modUser', $res->get('user_fk'))->username; // <-- this works, but I need it in the query
echo $res->get('u.username').'+ '.$res->get('fooDescription').'<br />'; // <-- this does not return the username
}
I can get what I need, but that’s resorting to calls within a loop which is obviously not efficient.