Example #1
0
 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;
 }
Example #2
0
 /**
  * Checks if this class exists in the database
  * @return bool
  */
 public function inDatabase()
 {
     return parent::_exists($this->getModelsMetaData(), $this->selectReadConnection());
 }