So what I’m trying to do is get a JSON array of modUser + modUserProfile objects for my grid that only has these fields:
- id (user)
- active (user)
- fullname (profile)
- email (profile)
Should be simple enough.. but with the code below it returns all fields from the modUser object (and the two profile fields I requested). While it’s not a huge problem, it does fetch password hashes and stuff like that and it’s just plain useless. It’s not harming anything right now, but would love to know what I’m doing wrong here
The toSql you see ti breaking on returns what I would expect:
SELECT modUser.id, modUser.active, Profile.fullname, Profile.email FROM `modx_users` AS `modUser` JOIN `modx_user_attributes` `Profile` ON `modUser`.`id` = `Profile`.`internalKey
This is the processor code:
$c = $modx->newQuery('modUser');
$total = $modx->getCount('modUser',$c);
$c->select(
array(
'modUser.id',
'modUser.active',
'Profile.fullname',
'Profile.email',
)
);
$c->innerJoin('modUserProfile','Profile');
$c->prepare();
return $modx->error->failure($c->toSql());
$results = array();
$qr = $modx->getCollection('modUser',$c);
foreach ($qr as $r) {
$results[] = $r->toArray();
}
$ra = array(
'success' => true,
'total' => $total,
'results' => $results
);
return $modx->toJSON($ra);