We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8386 ☆ A M B ☆
    • 160 Posts
    I currently have a xPDO lookup that looks like this
    $modx->getObjectGraph('Post', array(
                'Photos' => array(),
                'Comments' => array(
                    'CreatedBy' => array()
                ),
                'CreatedBy' => array()
    		), $id);

    This currently return null since I have CreatedBy twice even though they are in different relationships. If I however remove one of the CreatedBy it works fine or if I change the name of one of the CreatedBy to something like PostCreatedBy it then works. Is this a bug or am I doing something wrong? [ed. note: easylancer last edited this post 14 years, 9 months ago.]
      • 8386 ☆ A M B ☆
      • 160 Posts
      Here is the schema
      <object class="Post" table="post" extends="xPDOSimpleObject">
      		<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default="" index="index" />
      		<field key="description" dbtype="text" phptype="string" null="false" default="" />
      		<field key="street1" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
      		<field key="street2" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
      		<field key="city" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
      		<field key="postcode" dbtype="varchar" precision="16" phptype="string" null="false" default="" />
      		<field key="country" dbtype="varchar" precision="255" phptype="string" null="false" default="0" />
      		<field key="logo" dbtype="varchar" precision="160" phptype="string" null="false" default="" />
      		<field key="website" dbtype="varchar" precision="160" phptype="string" null="false" default="" />
      		<field key="keywords" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
      		<field key="active" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
      
      		<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
      		<field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
      
      		<index alias="name" name="name" primary="false" unique="false" type="BTREE">
      			<column key="name" length="" collation="A" null="false" />
      		</index>
      
      		<index alias="createdby" name="createdby" primary="false" unique="false" type="BTREE">
      			<column key="createdby" length="" collation="A" null="false" />
      		</index>
      
      		<aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign" />
      		<composite alias="Comments" class="Comment" local="id" foreign="post" cardinality="many" owner="local" />
      		<composite alias="Facilities" class="vxFacility" local="id" foreign="post" cardinality="many" owner="local" />
      		<composite alias="Photos" class="vxPhoto" local="id" foreign="post" cardinality="many" owner="local" />
      	</object>
      
      	<object class="Comment" table="comments" extends="xPDOSimpleObject">
      		<field key="post" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
      		<field key="comments" dbtype="text" phptype="string" null="false" default="" />
      		<field key="problems" dbtype="text" phptype="string" null="false" default="" />
      		<field key="delegates" dbtype="varchar" precision="30" phptype="string" null="false" default="" />
      		<field key="event_type" dbtype="varchar" precision="160" phptype="string" null="false" default="" />
      		<field key="facilities" dbtype="text" phptype="json" null="false" default="{}" />
      		<field key="ratings" dbtype="text" phptype="json" null="false" default="{}" />
      
      		<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
      		<field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
      
      		<aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign" />
      		<aggregate alias="Post" class="Post" local="post" foreign="id" cardinality="one" owner="foreign" />
      	</object>
      
        • 22303 MODX Staff
        • 10,725 Posts
        This will not work because the graph query is trying to select fields from the same table with the same alias for two different relations. You would have to manually join in this case, or use different aliases for your relations.
          • 8386 ☆ A M B ☆
          • 160 Posts
          Ah ok that make sense.