I’ve read the documentation, but I’m still having trouble figuring out how to use related objects in Revo. Not sure if it’s a schema problem or just how I’m using it once I’ve retrieved it. Can anyone help? I’m still learning Revo/xPDO, so please bear with me
In this case, I have a third-party table with lots of rows, and each row contains a field called userid, which is supposed to correspond with the id for a user in the modUser class. All I want to be able to do is iterate through each row of my third-party table and display user-associated fields (such as fullname, or possibly some extended fields) with each row.
The schema for my third-party DB object looks like this:
<object class="CakeStats" table="cake_stats" extends="xPDOSimpleObject">
<field key="userid" dbtype="int" precision="11" phptype="integer" null="true" />
<field key="year" dbtype="varchar" precision="11" phptype="string" null="true" />
<field key="position" dbtype="varchar" precision="11" phptype="string" null="true" />
<field key="week" dbtype="varchar" precision="11" phptype="string" null="true" />
<field key="statName" dbtype="varchar" precision="40" phptype="string" null="true" />
<field key="value" dbtype="int" precision="11" phptype="integer" null="true" />
<aggregate alias="AggUser" class="modUser" local="userid" foreign="id" cardinality="one" owner="foreign" />
</object>
You’ll notice the last line, which I thought was supposed to hook me up with the modUser object.
From there, I’m trying to iterate through it like this:
$path = MODX_CORE_PATH . 'components/stats/';
$result = $modx->addPackage('stats',$path . 'model/','modx_');
$state_abbr = $modx->getOption('state_abbr');
$stats = $modx->getCollection('CakeStats'.$state_abbr);
foreach($stats as $stat) {
$userid = $stat->get('userid');
$username = $stat->getOne('username');
echo $userid;
echo $username;
}
This returns the userid value for each, but not the username. Can anyone tell me what I’m doing wrong? And while you’re looking, what will I need to do differently to access the extended modUser fields in this situation?