Exemplo n.º 1
0
 /**
  * Refresh data from database
  *
  * @return $this
  */
 public function refresh()
 {
     $this->initialize();
     if (!$this->rowExistsInDatabase()) {
         throw new Exception\RuntimeException('Cannot refresh the data not exists in database.');
     }
     $where = $this->processPrimaryKeyWhere();
     $statement = $this->sql->prepareStatement($this->sql->select()->where($where));
     $result = $statement->execute();
     $rowData = $result->current();
     unset($statement, $result);
     // cleanup
     // make sure data and original data are in sync after save
     $this->populate($rowData, true);
     return $this;
 }
 /**
  * get one row
  *
  * @param Where|\Closure|string|array $where
  * @param bool $returnArray
  * @throws Exception\InvalidArgumentException
  * @return null|array|AbstractRow
  */
 public function get($where = null, $returnArray = false)
 {
     $this->initialize();
     $select = $this->sql->select();
     if ($where instanceof \Closure) {
         $where($select);
     } elseif ($where !== null) {
         $select->where($where);
     }
     // prepare and execute
     $statement = $this->sql->prepareStatement($select);
     $result = $statement->execute();
     $rowData = $result->current();
     if (false === $rowData) {
         return null;
     }
     if ($returnArray) {
         return $rowData;
     }
     $row = clone $this->rowPrototype;
     $row->exchangeArray($rowData);
     return $row;
 }