We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38878
    • 255 Posts
    I have some custom tables for which I am writing a CMP to manage. The primary key (id field) in the tables is not named "id" but something else. I have no issue retrieving or creating new records in the tables but cannot update. As you can see below, my id field is called position_id instead of just ID. I read the API docs and thought if I set the $primaryKeyField that would do it throwing a 500 error. My update processor looks like this:

    <?php
    /**
     * @package recroot
     * @subpackage processors
     */
    class PositionUpdateProcessor extends modObjectUpdateProcessor {
        public $classKey = 'rtPositions';
        public $languageTopics = array('recroot:default');
        public $objectType = 'recroot.position';
        public $primaryKeyField = 'position_id'; //<-- this no worky
    
        public function beforeSave() {
            $position_id = $this->getProperty('position_id');
            $title = $this->getProperty('title');
            $company = $this->getProperty('company');
            $type = $this->getProperty('type');
            $source = $this->getProperty('source');
      	$applylink = $this->getProperty('applylink');
            $description = $this->getProperty('description');
            $expireson = $this->getProperty('expireson');
            if (empty($position_id)) {$this->addFieldError('position_id',$this->modx->lexicon('recroot.position_err_ns_position_id'));}
            if (empty($title)) {$this->addFieldError('title',$this->modx->lexicon('recroot.position_err_ns_title'));}
            if (empty($company)) {$this->addFieldError('company',$this->modx->lexicon('recroot.position_err_ns_company'));}
            if (empty($type)) {$this->addFieldError('type',$this->modx->lexicon('recroot.position_err_ns_type'));}
            if (empty($source)) {$this->addFieldError('source',$this->modx->lexicon('recroot.position_err_ns_source'));}
            if (empty($applylink)) {$this->addFieldError('applylink',$this->modx->lexicon('recroot.position_err_ns_applylink'));}
            if (empty($description)) {$this->addFieldError('description',$this->modx->lexicon('recroot.position_err_ns_description'));}
            if (empty($expireson)) {$this->addFieldError('expireson',$this->modx->lexicon('recroot.position_err_ns_expireson'));}
             return parent::beforeSave();
        }
    }
    return 'PositionUpdateProcessor'}


    How do I tell the modObjectUpdateProcessor the primary key field name so it can find the record to update?

    Thanks! [ed. note: harveyev last edited this post 10 years, 11 months ago.]
      • 38878
      • 255 Posts
      Now not throwing any errors (syntax issue). Just returning:
      {"success":false,"message":"The position could not be saved.","total":0,"data":[],"object":[]}

      BTW, this happens in bot update and updatefromgrid processors so I assume its the update processor that is the issue.
        • 3749
        • 24,544 Posts
        You may have to override the save() method.
          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
          • 38878
          • 255 Posts
          Quote from: BobRay at Oct 25, 2015, 04:12 PM
          You may have to override the save() method.

          Thanks Bob. I modified the id name to be id. Just much simpler. All works now;)

          My last two issues are:

          1. how to update mapping table data from within my new and update forms. I have a many to many with a Categories table and am looking for examples on a.) how to render the categories (maybe a checkbox group would work), and b.) then how to update the mapping table.

          2. how to get the grid to render the display values on load for my comboboxes. They are working fine in the forms, and load when I click to edit, but everything I've read a tried doesn't work .
          My combo.store looks like this:
          Recroot.combo.Companies = function(config) {
              config = config || {};
              Ext.applyIf(config,{
              displayField: 'name'
              ,valueField: 'company_id'
              ,mode: 'remote'
              ,store: new Ext.data.JsonStore({
                  url: Recroot.config.connectorUrl,
                  // store configs
                  autoDestroy: false,
                  baseParams: {
                      action: 'mgr/company/getlist',
                      combo: true
                  },
                  storeId: 'companyStore',
                  // reader config
                  root: 'results',
                  idProperty: 'company_id',
                  autoLoad: true,
                  typeAhead: true,
                  valueNotFoundText: 'Entry not found',
                  fields: ['company_id', 'name'],
                  tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><span style="font-weight: bold">{name}</span>'
                      ,' ({code})</div></tpl>')
          
              })
              ,editable: true
              ,emptyText: 'Company...'
              });
              Recroot.combo.Companies.superclass.constructor.call(this,config);
          };
          Ext.extend(Recroot.combo.Companies, MODx.combo.ComboBox);
          Ext.reg('Companies-combo', Recroot.combo.Companies);


          Ad the grid column is set to this:
          {
                      header:_('recroot.position_header_company')
                      ,dataIndex: 'company'
                      ,sortable: true
                      ,width: 50
                      ,hiddenName: 'company'
                      ,editor: { xtype: 'Companies-combo', renderer:'true'}
                  }


          Could this issue also be related to the id not being "id"? The combos do work in the forms. They just display the id in the column in the grid instead of the displaytext.