protected function _exists(PhalconModel\MetaDataInterface $metaData, AdapterInterface $connection, $table = null) { if ($this->_isNew) { return parent::_exists($metaData, $connection, $table); } // Be able to update primary keys $primaryValues = []; foreach ($metaData->getPrimaryKeyAttributes($this) as $field) { $primaryValues[$field] = [$oldValue = fnGet($this->_snapshot, $field), $this->{$field}]; $this->{$field} = $oldValue; } $result = parent::_exists($metaData, $connection, $table); foreach ($primaryValues as $field => $values) { $this->{$field} = $values[1]; } return $result; }
/** * Checks if this class exists in the database * @return bool */ public function inDatabase() { return parent::_exists($this->getModelsMetaData(), $this->selectReadConnection()); }