We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20135
    • 188 Posts
    I'm building a CMP with grids that display custom table data and allow edit of some of the elements. However, when I save the data, MODx gives me an alert box with an err_ns message. A bit of searching (http://forums.modx.com/thread/83083/solved-quip-thread-err-ns-when-trying-to-deleted-hidden-childresource) showed that the err_ns message was MODx trying to tell me that the the ID field was missing. However, the ID field of the table is named budgId, not id, and I think that's what's causing this issue.

    How can I convince MODx that budgId is the primary key of the table, so that it proceeds to update the table with the new info? All of the schema and classes and such are present (or else the data wouldn't be displayed in the grid).

    This question has been answered by moniarde. See the first response.

    • discuss.answer
      • 20135
      • 188 Posts
      Solution: it's possible to redefine the primary key field. In the processor file referenced by the 'save_action' line in the modext grid, you can do this:
      class GR8BudgetUpdateFromGridProcessor extends GR8UpdateBudgetsProcessor {
          public function initialize() {
              
      	$data = $this->getProperty('data');
              if (empty($data)) return $this->modx->lexicon('invalid_data');
              $data = $this->modx->fromJSON($data);
      		$data['budgDateCreated'] = strtotime($data['budgDateCreated']);
      		$this->primaryKeyField = 'budgId'; //<----------- HERE'S WHERE TO REDEFINE THE PRIMARY KEY
              if (empty($data)) return $this->modx->lexicon('invalid_data');
              $this->setProperties($data);
              $this->unsetProperty('data');
      
              return parent::initialize();
          }
      
      }
      return 'GR8BudgetUpdateFromGridProcessor';

      This seems to have solved this puzzle.