We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50227
    • 18 Posts
    Hi All

    Whilst trying to solve this problem -

    https://forums.modx.com/thread/96835/custom-tables---child-record-not-being-deleted#dis-post-523947

    I've encountered this

    Fatal error: Call to a member function get() on a non-object in D:\Domains\******\wwwroot\core\cache\includes\elements\modsnippet\5.include.cache.php on line 17

    Its falling over at $pupil = $thechart->TutorToPupil->get('tutor_id');

    While trying to query my test tables
    $criteria = $modx->newQuery('Tutor');
    $thecharts = $modx->getCollectionGraph('Tutor', '{"TutorToPupil":{} }', $criteria);
    foreach ($thecharts as $thechart) {
        $tutor = $thechart->get('id');
    	$pupil = $thechart->TutorToPupil->get('tutor_id');
    	//$chart = $thechart->PupilTochart->get('pupil_id');
    	$output .= '<p>';
    	$output .= $tutor .' - ' . $pupil;// .' - ' . $chart;
    	$output .= '</p>';
    
    }
    


    What am I doing wrong?!?!?!?!?!?

    Thanks in advance ;-(


    <?xml version="1.0" encoding="UTF-8"?>
    <model package="sohow" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
    	<object class="Chart" table="chart" extends="xPDOSimpleObject">
    		<field key="pupil_id" dbtype="int" precision="11" phptype="integer" null="false" index="index" />
    
    		<index alias="pupil_id" name="pupil_id" primary="false" unique="false" type="BTREE" >
    			<column key="pupil_id" length="" collation="A" null="false" />
    		</index>
    		<composite alias="ChartToFeeling" class="Feeling" local="id" foreign="chart_id" cardinality="many" owner="local" />
    		<aggregate alias="ChartFromPupil" class="Pupil" local="pupil_id" foreign="id" cardinality="one" owner="foreign" />
    
    	</object>
    	<object class="Feeling" table="feeling" extends="xPDOSimpleObject">
    		<field key="chart_id" dbtype="int" precision="11" phptype="integer" null="false" index="index" />
    
    		<index alias="chart_id" name="chart_id" primary="false" unique="false" type="BTREE" >
    			<column key="chart_id" length="" collation="A" null="false" />
    		</index>
    		<aggregate alias="FeelingFromChart" class="Chart" local="chart_id" foreign="id" cardinality="one" owner="foreign" />
    	</object>
    	<object class="Pupil" table="pupil" extends="xPDOSimpleObject">
    		<field key="tutor_id" dbtype="int" precision="11" phptype="integer" null="false" index="index" />
    
    		<index alias="tutor_id" name="tutor_id" primary="false" unique="false" type="BTREE" >
    			<column key="tutor_id" length="" collation="A" null="false" />
    		</index>
    		<aggregate alias="PupilFromTutor" class="Tutor" local="tutor_id" foreign="id" cardinality="one" owner="foreign" />
    		<composite alias="PupilToChart" class="Chart" local="id" foreign="pupil_id" cardinality="many" owner="local" />
    	</object>
    	<object class="Tutor" table="tutor" extends="xPDOSimpleObject">
    		<field key="tutor_name" dbtype="varchar" precision="50" phptype="string" null="false" index="index" />
    
    		<index alias="tutor_name" name="tutor_name" primary="false" unique="false" type="BTREE" >
    			<column key="tutor_name" length="" collation="A" null="false" />
    		</index>
    		<composite alias="TutorToPupil" class="Pupil" local="id" foreign="tutor_id" cardinality="many" owner="local" />
    	</object>
    </model>
    



    MODX Revolution 2.3.3-pl (traditional)
    MYSQL: 5.1.36-community-log
    PHP: 5.2.9-1
    Windows NT OSHMYSQL01 5.2 build 3790

    This question has been answered by esradral. See the first response.

    • discuss.answer
      • 50227
      • 18 Posts
      DOH!!!!!!!!

      $pupil is an array - so I need to loop through it!!!!!!!!!!!!!

      Hanging my head in shame 8-}