We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34109
    • 119 Posts
    I have some custom tables. I can create objects with newObject and can save them. I can then load the object and save it and the changes are available to the script, but they're not being written back to the database. Has anyone any advice as to why this might be?

    Thanks

    A section of the schema for the class in question is below:

    	<object class="Listings" table="tcd_provider_lk" extends="xPDOObject">
    		<field key="clientid" dbtype="int" precision="11" phptype="integer" null="false" />
    		<field key="spl_id" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
    		<field key="sponsor_id" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
    		<field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
    		<field key="contact_name" dbtype="varchar" precision="100" phptype="string" null="false" />
    		<field key="position" dbtype="varchar" precision="50" phptype="string" null="false" default="" />
    		<field key="number" dbtype="varchar" precision="40" phptype="string" null="false" />
    		<field key="street" dbtype="varchar" precision="75" phptype="string" null="false" default="" />
    		<field key="suburb" dbtype="varchar" precision="30" phptype="string" null="false" default="" />
    		<field key="town" dbtype="varchar" precision="30" phptype="string" null="false" default="" />
    		<field key="county" dbtype="varchar" precision="25" phptype="string" null="false" default="" />
    		<field key="postcode" dbtype="varchar" precision="8" phptype="string" null="false" default="" />
    		<field key="combined_address" dbtype="varchar" precision="255" phptype="string" null="true" />
    		<field key="lat" dbtype="float" precision="10,6" phptype="float" null="true" />
    		<field key="lng" dbtype="float" precision="10,6" phptype="float" null="true" />
    		<field key="tele1" dbtype="varchar" precision="40" phptype="string" null="false" />
    		<field key="tele2" dbtype="varchar" precision="40" phptype="string" null="false" />
    		<field key="fax" dbtype="varchar" precision="20" phptype="string" null="false" default="" />
    		<field key="email" dbtype="varchar" precision="55" phptype="string" null="false" default="" />
    		<field key="website" dbtype="varchar" precision="150" phptype="string" null="false" />
    		<field key="service_tags" dbtype="text" phptype="string" null="false" />
    		<field key="summary" dbtype="text" phptype="string" null="false" />
    		<field key="objectives" dbtype="text" phptype="string" null="false" />
    		<field key="hours" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
    		<field key="cost" dbtype="varchar" precision="50" phptype="string" null="false" default="" />
    		<field key="adult_child" dbtype="varchar" precision="5" phptype="string" null="false" />
    		<field key="learning_physical" dbtype="varchar" precision="10" phptype="string" null="false" />
    		<field key="nationwide" dbtype="char" precision="1" phptype="string" null="false" default="n" />
    		<field key="potential_sponsor" dbtype="varchar" precision="1" phptype="string" null="false" default="n" />
    		<field key="score_tot" dbtype="int" precision="11" phptype="integer" null="false" />
    		<field key="score_count" dbtype="int" precision="11" phptype="integer" null="false" />
    		<field key="score_ave" dbtype="decimal" precision="3,2" phptype="float" null="false" default="0.00" />
    		<field key="score_tot2" dbtype="int" precision="11" phptype="integer" null="false" />
    		<field key="score_count2" dbtype="int" precision="11" phptype="integer" null="false" />
    		<field key="score_ave2" dbtype="decimal" precision="3,2" phptype="float" null="false" />
    		<field key="pref_rank" dbtype="int" precision="3" phptype="integer" null="false" default="100" />
    		<field key="premium_listing" dbtype="int" precision="1" phptype="integer" null="false" default="0" />
    		<field key="premium_renewal" dbtype="date" phptype="date" null="false" />
    		<field key="creation_date" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
    		<field key="opt_in" dbtype="int" precision="1" phptype="integer" null="false" default="1" />
    		<field key="user_id" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
    		<field key="submission_id" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
    		<field key="researched" dbtype="int" precision="1" phptype="integer" null="false" default="0" />
    		<field key="moderated" dbtype="int" precision="1" phptype="integer" null="false" default="0" />
    		<field key="verified" dbtype="int" precision="1" phptype="integer" null="false" default="0" />
    		<field key="source_lk" dbtype="int" precision="11" phptype="integer" null="false" default="1" />
    		
    		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
    			<column key="clientid" length="" collation="A" null="false" />
    		</index>
    	    <composite alias="Feedback" class="Feedback" local="clientid" foreign="sp_id" cardinality="many" owner="local" />
    	    <composite alias="Categories" class="TcdMain" local="clientid" foreign="clientid" cardinality="many" owner="local" />
    
    	</object>
    

    This question has been answered by [email protected]. See the first response.

      Studio Republic
      http://www.studiorepublic.com
      0845 226 3205
      @christodhunter
      • 34109
      • 119 Posts
      ...here's a sample of code which saves the object but not to the db:

      $listing=$modx->getObject('Listings',1234);
      $listing->set('name','newvalue');
      $listing->save();
      


      Nothing in the error log...
        Studio Republic
        http://www.studiorepublic.com
        0845 226 3205
        @christodhunter
      • discuss.answer
        • 34109
        • 119 Posts
        So a change to the schema did the trick. Even though I'd defined the primary key, I changed the definition of that field as below and it's working fine now:
        		<field key="clientid" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" />
        
          Studio Republic
          http://www.studiorepublic.com
          0845 226 3205
          @christodhunter