Exemplo n.º 1
0
 /**
  * Sets new primary key - if new key not exists in the row you will lose data! luckily key 'id' will reset to old array .)
  * @param $name
  * @return \Gridito\Model\ArrayModel
  */
 public function setPrimaryKey($name)
 {
     if ($name !== $this->getPrimaryKey()) {
         if ($name === 'id') {
             $this->data = $this->_data;
         } else {
             //rebase data on new key
             $data = array();
             foreach ($this->_data as $row) {
                 if (isset($row[$name])) {
                     $data[$row[$name]] = $row;
                 }
             }
             $this->data = $data;
         }
     }
     parent::setPrimaryKey($name);
     return $this;
 }