I have a table that has a parent_id column intended to infer a hierarchy. Here’s my schema:
<object class="ClientCategories" table="hg_clientcategories" extends="xPDOSimpleObject">
<field key="parent_id" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="true" />
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" />
<field key="seq" dbtype="tinyint" precision="3" phptype="integer" null="true" />
<field key="grp" dbtype="varchar" precision="16" phptype="string" null="true" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<aggregate alias="Parent" class="ClientCategories" local="parent_id" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="Children" class="ClientCategories" local="id" foreign="parent_id" cardinality="many" owner="local" />
</object>
But the join isn’t happening... from my snippet:
$query = $modx->newQuery('ClientCategories');
$categories = $modx->getCollectionGraph('ClientCategories','{"Children":{}}',$query);
$query->bindGraph('ClientCategories','{"Children":{}}');
$query->prepare();
return $query->toSQL();
There’s no Join in the resulting SQL query. What am I doing wrong?
I wrote this page, and if my schema isn’t correct for this, I’d like to update the page:
http://rtfm.modx.com/display/xPDO20/More+Examples+of+xPDO+XML+Schema+Files#MoreExamplesofxPDOXMLSchemaFiles-ParentID%3ASelfJoin