Example #1
0
 /**
  * Fix field value for tinyint(1) types, from integer to string
  * Executes internal hooks before save a record
  *
  * @param \Phalcon\Mvc\Model\MetadataInterface $metaData
  * @param boolean $exists
  * @param string $identityField
  * @return boolean
  */
 protected function _preSave($metaData, $exists, $identityField)
 {
     $dataTypes = $metaData->getDataTypes($this);
     foreach ($dataTypes as $key => $type) {
         if ($type === \Phalcon\Db\Column::TYPE_BOOLEAN) {
             $value = $this->{$key};
             if ((int) $value === $value) {
                 $this->{$key} = (string) $value;
             }
         }
     }
     return parent::_preSave($metaData, $exists, $identityField);
 }
Example #2
0
 protected function _preSave(PhalconModel\MetaDataInterface $metaData, $exists, $identityField)
 {
     // Phalcon prepareSave() Polyfill
     // @codeCoverageIgnoreStart
     if ($_SERVER['PHWOOLCON_PHALCON_VERSION'] < '2001100') {
         $this->prepareSave();
     }
     // @codeCoverageIgnoreEnd
     // Fix phalcon bug: attributeField . " is required" on empty values, it should detect null values instead
     $emptyFields = [];
     foreach ($this->defaultValues() as $k => $v) {
         if (!$v) {
             $emptyFields[$k] = $this->{$k};
             $this->{$k} = 1;
         }
     }
     $result = parent::_preSave($metaData, $exists, $identityField);
     foreach ($emptyFields as $k => $v) {
         $this->{$k} = $v;
     }
     return $result;
 }