modx xpdo insert via schema updated. queries now fail

324 Views Asked by At

title is probably not correct but here's the situation.

In modx using migx i've created a custom package for a custom table.

it looked this:

<object class="Orders" table="orders" extends="xPDOSimpleObject">
    <field key="contract_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" />
    <field key="customer_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" />
    <field key="in_datetime" dbtype="timestamp" phptype="timestamp" null="false" default="0000-00-00 00:00:00" />
    <field key="out_datetime" dbtype="timestamp" phptype="timestamp" null="false" default="0000-00-00 00:00:00" />      
    <field key="vehicledata" dbtype="text" phptype="string" null="false" />
    <field key="total_price" dbtype="decimal" precision="10,2" phptype="float" null="false" />
</object>

the code doing the insert was:

    $oOrder -> set('contract_id', (int) $iContractid );
    $oOrder -> set('customer_id', (int) $aProfile['id'] );
    $oOrder -> set('in_datetime', (string) $startdaterev . ' ' . $starttime . ':00' );  
    $oOrder -> set('out_datetime', (string) $enddaterev . ' ' . $endtime . ':00' ); 
    $oOrder -> set('vehicledata', (string) json_encode( $aPostedvehicleprops ) );   

    if( $oOrder -> save() )
    {
        $iOrderid = (int) $oOrder -> get('id') ; // last insert id
        print '<br>orderid:' . $iOrderid ;
    }
    else
    {
        throw new Exception('unable to save order data');
    }

And it worked like a charm.

However, i've added 3 extra fields to the table. integers, unsigned 10.

Updated the schema using migx. It's now:

<object class="Orders" table="orders" extends="xPDOSimpleObject">
    <field key="contract_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" />
    <field key="customer_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" />
    <field key="in_datetime" dbtype="timestamp" phptype="timestamp" null="false" default="0000-00-00 00:00:00" />
    <field key="out_datetime" dbtype="timestamp" phptype="timestamp" null="false" default="0000-00-00 00:00:00" />
    <field key="dropoffplace_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" />
    <field key="pickupplace_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" />
    <field key="storagetype_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" />
    <field key="vehicledata" dbtype="text" phptype="string" null="false" />
    <field key="total_price" dbtype="decimal" precision="10,2" phptype="float" null="false" />
</object>

And the insert query now is:

    $oOrder -> set('contract_id', (int) $iContractid );
    $oOrder -> set('customer_id', (int) $aProfile['id'] );
    $oOrder -> set('in_datetime', (string) $startdaterev . ' ' . $starttime . ':00' );  
    $oOrder -> set('out_datetime', (string) $enddaterev . ' ' . $endtime . ':00' ); 
    $oOrder -> set('dropoffplace_id', (int) $iDropoffid  );
    $oOrder -> set('pickupplace_id', (int) $iPickupid );    
    $oOrder -> set('storagetype_id', (int) $iStoragetypeid );
    $oOrder -> set('vehicledata', (string) json_encode( $aPostedvehicleprops ) );   

    if( $oOrder -> save() )
    {
        $iOrderid = (int) $oOrder -> get('id') ; // last insert id
        print '<br>orderid:' . $iOrderid ;
    }
    else
    {
        throw new Exception('unable to save order data');
    }

And the data for the columns that already existed gets inserted correctly thus no errors are thrown, however the 3 new fields remain empty even-though the variable values are set and of the correct type.

I already deleted the cache folder, recreated the scheme's again and the new fields are in the scheme, even physically on the webserver they are included.

First question of course; WHY are the new fields completely ignored?

Second question, when creating a scheme for a new table the generated scheme also includes all data for all other custom fields with the same custom prefix. Is that supposed to happen? or should the scheme include the freshly generated schema data for a freshly created table only?

1

There are 1 best solutions below

0
On

Never used migx so I'm not sure if it's supposed to do this automatically, but you need to regenerate your class files for the new schema, so;

  • check that new class files were actually created
  • check that the existing class files have the updates code for the new fields

Not sure about Q2 - like I said I've never used migx, IMO building your own schema & build scripts give you a much better chance [insight] at tracking down problems like this.

Developing an Extra in MODX Revolution