-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
I'm trying access nested related objects using getCollectionGraph().
My schema:
<object class="TestClass" table="test_class" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="true" />
<field key="description" dbtype="mediumtext" phptype="string" null="true" />
<composite alias="actions" class="MyActions" local="id" foreign="test_id" cardinality="many" owner="local" />
</object>
<object class="MyActions" table="actions_table" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="true" />
<field key="description" dbtype="mediumtext" phptype="string" null="true" />
<field key="test_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" index="index" />
<composite alias="activities" class="MyActivities" local="id" foreign="action_id" cardinality="many" owner="local" />
</object>
<object class="MyActivities" table="activities_table" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="true" />
<field key="description" dbtype="mediumtext" phptype="string" null="true" />
<field key="action_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" index="index" />
</object>
Code:
$collection = $this->modx->getCollectionGraph('TestClass','{"actions":{"activities":{}}}',array('id' => 5));
foreach ($collection as $row) {
foreach ($row->actions as $action) {
//do something
foreach ($action->activities as $activity) {
//do something
}
}
}
There are multiple related actions and they are all fetched correctly. However with the nested related activities, only one row is returned even though there are multiple rows per action. The row with the highest id is returned only.
getMany() works as expected with multiple activities returned:
$collection = $this->modx->getCollectionGraph('TestClass','{"actions":{}}',array('id' => 5));
foreach ($collection as $row) {
foreach ($row->actions as $action) {
//do something
$activities = $action->getMany('activities');
foreach ($activities as $activity) {
//do something
}
}
}
Is this a bug anyone else can replicate or am I making a mistake somewhere?
Thanks
Metadata
Metadata
Assignees
Labels
No labels