Example #1
0
 /**
  * Update a row.
  *  @param Database $db Database reference to use
  *  @param int $parentId Parent row's primary key value
  *  @param string[] $data Data to be set for the join
  *  @private
  */
 private function _update_row($db, $parentId, $data)
 {
     if (isset($this->_join['table'])) {
         // Got a link table, just insert the pkey references
         $db->push($this->_join['table'], array($this->_join['parent'][1] => $parentId, $this->_join['child'][1] => $data[$this->_join['child'][0]]), array($this->_join['parent'][1] => $parentId));
     } else {
         // No link table, just a direct reference
         $set = array($this->_join['child'] => $parentId);
         for ($i = 0; $i < count($this->_fields); $i++) {
             $field = $this->_fields[$i];
             if ($field->apply('set', $data)) {
                 $set[$field->dbField()] = $field->val('set', $data);
             }
         }
         // Add WHERE conditions
         $where = array($this->_join['child'] => $parentId);
         for ($i = 0, $ien = count($this->_where); $i < $ien; $i++) {
             $where[$this->_where[$i]['key']] = $this->_where[$i]['value'];
             // Is there any point in this? Is there any harm?
             if ($this->_whereSet) {
                 $set[$this->_where[$i]['key']] = $this->_where[$i]['value'];
             }
         }
         $db->push($this->_table, $set, $where);
     }
 }