We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    Maybe I've been looking at it too long, this bit of code is giving me a "PHP Fatal error: Call to a member function addOne() on a non-object in" error:

    $newData = $this->modx->newObject('FundRequest');
    
    		foreach($formfields as $key => $value){			
    			
    			$newData->set($key,$value);			
    					
    		}	
    				
    		$comment = !empty($formfields['comment']) ? $formfields['comment'] : 'none';
    		
    		if($comment != 'none'){
    
    				$newComment = $this->modx->newObject('FundComment');
    				$newComment->set('comment',$comment);	
    				$newdata->addOne($newComment);
    		}
    
    		$newData->save();




    It sure looks right to me, and the exact same code works elsewhere [well not exact]

    Here is the bit of the schema that is concerned.,..

    	<object class="FundRequest" table="fund_request" extends="xPDOSimpleObject">
    		<field key="created" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP"  extra="on update current_timestamp" />
    		<field key="modified" dbtype="timestamp" phptype="timestamp" null="false" default="0000-00-00 00:00:00" />
    		<field key="token" dbtype="varchar" precision="50" phptype="string" null="true" />
    		<field key="unixtime" dbtype="varchar" precision="50" phptype="string" null="true" />
    		<field key="status_id" dbtype="int" precision="8" phptype="integer" null="true" />
    		<field key="program_id" dbtype="int" precision="8" phptype="integer" null="false" />
    		<field key="contract_id" dbtype="int" precision="8" phptype="integer" null="false" />
    		<field key="requester_uid" dbtype="int" precision="8" phptype="integer" null="false" />
    		<field key="approver_uid" dbtype="int" precision="8" phptype="integer" null="true" />
    		<field key="payee_uid" dbtype="int" precision="8" phptype="integer" null="true" />
    		<field key="budget_type_id" dbtype="int" precision="8" phptype="integer" null="false" />
    		<field key="category_id" dbtype="int" precision="8" phptype="integer" null="true" />
    		<field key="comment_id" dbtype="int" precision="8" phptype="integer" null="true" />
    		<field key="amount" dbtype="decimal" precision="12,2" phptype="float" null="false" />
    		<field key="payment_reference" dbtype="varchar" precision="250" phptype="string" null="false" />
    		<field key="method_paid" dbtype="int" precision="8" phptype="integer" null="true" />
    		<field key="request_date" dbtype="date" phptype="date" null="false" />
    		<field key="approved_date" dbtype="date" phptype="date" null="true" />
    		<field key="paid_date" dbtype="date" phptype="date" null="true" />
    		<!--field key="comments" dbtype="longtext" phptype="string" null="true" /-->
    		
    		<aggregate alias="StatusFlag" class="StatusFlag" local="status_id" foreign="id" cardinality="one" owner="foreign" />
    		<aggregate alias="FundCategory" class="FundCategory" local="category_id" foreign="id" cardinality="one" owner="foreign" />
    		<aggregate alias="BudgetType" class="BudgetType" local="budget_type_id" foreign="id" cardinality="one" owner="foreign" />
    		<aggregate alias="Program" class="Program" local="program_id" foreign="id" cardinality="one" owner="foreign" />
    		<aggregate alias="Contract" class="Contract" local="contract_id" foreign="id" cardinality="one" owner="foreign" />
    		<aggregate alias="Employer" class="Employer" local="payee_uid" foreign="id" cardinality="one" owner="foreign" />
    		<aggregate alias="PaymentMethod" class="PaymentMethod" local="method_paid" foreign="id" cardinality="one" owner="foreign" />
    
    		<composite alias="FundLog" class="FundLog" local="id" foreign="request_id" cardinality="many" owner="local" />		
    		<composite alias="FundComment" class="FundComment" local="id" foreign="request_id" cardinality="many" owner="local" />		
    		
    	</object>	
    
    	<object class="FundComment" table="fund_comment" extends="xPDOSimpleObject">
    		<field key="created" dbtype="timestamp" phptype="timestamp" null="true" default="CURRENT_TIMESTAMP"  extra="on update current_timestamp" />
    		<field key="modified" dbtype="timestamp" phptype="timestamp" null="true" />
    		<field key="comment" dbtype="text" phptype="string" null="false" />
    		<field key="request_id" dbtype="text" phptype="string" null="true" />
    		
    		<aggregate alias="FundComment" class="FundComment" local="request_id" foreign="id" cardinality="one" owner="foreign" />
    
    	</object>



    Does any one see my [probably obvious] error?

    -thanks
    -sean
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 26503
      • 620 Posts
      Well, I found my error, $newdata should have been $newData, however; now it's not inserting the comment into the fund comment table sad
        *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

        Sean Kimball CLP, CLS.
        Technical Director / Sr. Developer | BigBlock Studios
        ._______________________________________________.
        Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
        27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
        phone/fax: 905-426-5525
        • 3749
        • 24,544 Posts
        Check the return value of $newData->save(). It will return true if the save is successful.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Does it have anything to do with the line that is commented out in your XML
              <!--field key="comments" dbtype="longtext" phptype="string" null="true" /-->

            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 26503
            • 620 Posts
            No, I don't think so. That was left over when the requirement was changed to allow multiple comments. That field isn't used anymore.

            Quote from: sottwell at Mar 31, 2014, 12:34 AM
            Does it have anything to do with the line that is commented out in your XML
                <!--field key="comments" dbtype="longtext" phptype="string" null="true" /-->

              *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

              Sean Kimball CLP, CLS.
              Technical Director / Sr. Developer | BigBlock Studios
              ._______________________________________________.
              Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
              27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
              phone/fax: 905-426-5525
              • 26503
              • 620 Posts
              I can dump both objects and get data back, the $newData->save() will save the data to the FundRequest table, just not the FundComment table... both objects do exist!

              Quote from: BobRay at Mar 30, 2014, 11:54 PM
              Check the return value of $newData->save(). It will return true if the save is successful.
                *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                Sean Kimball CLP, CLS.
                Technical Director / Sr. Developer | BigBlock Studios
                ._______________________________________________.
                Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                phone/fax: 905-426-5525
                • 3749
                • 24,544 Posts
                I think your aggregate alias in the FundComment class should be:

                <aggregate alias="FundRequest" class="FundRequest" local="request_id" foreign="id" cardinality="one" owner="foreign" />


                It has to point back to the related object, not to itself.

                Be sure to regenerate the class and map files after making the change.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 26503
                  • 620 Posts
                  I don't see the difference, though it started working, I have no explanation, I didn't change any code, nothing. I manually put a record in the fund_comment table and it just worked after that.... ? wery strange!

                  Quote from: BobRay at Mar 31, 2014, 12:38 PM
                  I think your aggregate alias in the FundComment class should be:

                  <aggregate alias="FundRequest" class="FundRequest" local="request_id" foreign="id" cardinality="one" owner="foreign">


                  It has to point back to the related object, not to itself.

                  Be sure to regenerate the class and map files after making the change.</aggregate>
                    *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                    Sean Kimball CLP, CLS.
                    Technical Director / Sr. Developer | BigBlock Studios
                    ._______________________________________________.
                    Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                    27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                    phone/fax: 905-426-5525