Doctrine_Record::refresh PHP Méthode

refresh() public méthode

refresh refresh internal data from the database
public refresh ( boolean $deep = false ) : boolean
$deep boolean If true, fetch also current relations. Caution: this deletes any aggregated values you may have queried beforee
Résultat boolean
    public function refresh($deep = false)
    {
        $id = $this->identifier();
        if (!is_array($id)) {
            $id = array($id);
        }
        if (empty($id)) {
            return false;
        }
        $id = array_values($id);
        $overwrite = $this->getTable()->getAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE);
        $this->getTable()->setAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE, true);
        if ($deep) {
            $query = $this->getTable()->createQuery();
            foreach (array_keys($this->_references) as $name) {
                $query->leftJoin(get_class($this) . '.' . $name);
            }
            $query->where(implode(' = ? AND ', (array) $this->getTable()->getIdentifier()) . ' = ?');
            $this->clearRelated();
            $record = $query->fetchOne($id);
        } else {
            // Use HYDRATE_ARRAY to avoid clearing object relations
            $record = $this->getTable()->find($id, Doctrine_Core::HYDRATE_ARRAY);
            if ($record) {
                $this->hydrate($record);
            }
        }
        $this->getTable()->setAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE, $overwrite);
        if ($record === false) {
            throw new Doctrine_Record_Exception('Failed to refresh. Record does not exist.');
        }
        $this->_resetModified();
        $this->prepareIdentifiers();
        $this->_state = Doctrine_Record::STATE_CLEAN;
        return $this;
    }