I have two objects, category and subcategory.
There is no separate db table describing the relationship - subcategory has a ’category id’ field, and in that way, categories can contain 0..infinite subcategories.
<object class="ResumeCategory" table="resume_category" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="64" phptype="string" null="true" default="" />
<composite alias="ResumeSubcategory" class="ResumeSubcategory" local="id" foreign="category_id" cardinality="one" owner="local" />
</object>
<object class="ResumeSubcategory" table="resume_subcategory" extends="xPDOSimpleObject">
<field key="category_id" dbtype="mediumint" precision="8" attributes="unsigned" phptype="integer" null="true" default="0" />
<field key="name" dbtype="varchar" precision="64" phptype="string" null="true" default="" />
<aggregate alias="ResumeCategory" class="ResumeCategory" local="category_id" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="ResumeForm" class="ResumeForm" local="id" foreign="subcat_id" cardinality="many" owner="foreign" />
</object>
xPDO is mostly handling this relationship just fine, except for one problem. When I load a CollectionGraph of a category that does NOT contain any subcategories, I still end up with a related subcategory object, whose fields are all null.
I have traced this, but I’m not sure where the fix/workaround should be implemented, if indeed I’m not missing something else that would solve my problem.
The "empty" related object which represents the fact that there are no related objects is created when $xpdoquery::hydrateGraph runs, because the the query’s graph property contains an empty array (who’s key is the related object’s name).
It seems to me that that empty array shouldn’t be there. A fix would either
a) prevent that empty array from being created in the $xpdoquery_(db)::graph property
b) prevent hydrateGraphNode from being called when the graph property is looped through, if the subrelations are an empty array
c) implement the check/fix in hydrateGraph node
Thoughts?