We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    This probably isn’t an xpdo problem/question per se, but my brain is too fried to sort it out any further right now.

    I have a ’lastupdated’ field in my table that I’d like populated with the current timestamp when the record is updated. I auto-generated the schema from the table, and it looks like this:
    		<field key="lastUpdated" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
    


    When working with straight php/mysql update statements, fields like this will typically update automatically with each submission. But with this form, it populated the field when the record was first written, but it hasn’t updated it with subsequent updates to the record.

    Is it possible that this has anything to do with using xpdo? Or have I set up my field/table wrong?

      • 22303 MODX Staff
      • 10,725 Posts
      From the modSystemSettings object in the modx schema:
      <field key="editedon" dbtype="timestamp" phptype="timestamp" null="false" attributes="ON UPDATE CURRENT_TIMESTAMP" />
        • 14883 ☆ A M B ☆
        • 450 Posts
        Perfect, thank you.
          • 14883 ☆ A M B ☆
          • 450 Posts
          Maybe I spoke too soon. I changed my schema, and rebuilt the class files... but the field still isn’t being updated with the current timestamp.

          in my classname.map.inc.php file, ’fields’ contains:
          'lastUpdated' => 'ON UPDATE CURRENT_TIMESTAMP'


          and ’fieldMeta’ contains:
              'lastUpdated' => 
              array (
                'dbtype' => 'timestamp',
                'phptype' => 'timestamp',
                'null' => false,
                'default' => 'ON UPDATE CURRENT_TIMESTAMP',
              )
          


          Seems like it should work. But it isn’t.
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: jrotering at Jul 16, 2010, 02:10 PM

            Maybe I spoke too soon. I changed my schema, and rebuilt the class files... but the field still isn’t being updated with the current timestamp.

            in my classname.map.inc.php file, ’fields’ contains:
            'lastUpdated' => 'ON UPDATE CURRENT_TIMESTAMP'


            and ’fieldMeta’ contains:
                'lastUpdated' => 
                array (
                  'dbtype' => 'timestamp',
                  'phptype' => 'timestamp',
                  'null' => false,
                  'default' => 'ON UPDATE CURRENT_TIMESTAMP',
                )
            


            Seems like it should work. But it isn’t.
            Did you recreate the table from the new schema? That is the key.
              • 14883 ☆ A M B ☆
              • 450 Posts
              Ah, that was it. I didn’t recreate from the schema (not used to thinking in that direction yet), but added the ’on update CURRENT_TIMESTAMP’ attribute in phpmyadmin, to match what I had already added to the schema and class files. Now its working.