protected function validValue(Entity $entity)
    {
        foreach ($entity->getFields() as $field => $detail) {
            $value = $entity[$field];

            // Convert value type
            if ($value instanceof \DateTimeInterface) {
                $value = $value->format($this->db->getDateFormat());
            }

            if ($value instanceof JsonSerializer) {
                $value = json_encode($value);
            }

            if (\is_object($value) && \is_callable([$value, '__toString'])) {
                $value = (string) $value;
            }

            // Start prepare default value
            if (is_array($value) || is_object($value)) {
                $value = null;
            }

            if ($value === null) {
                // This field is null and the db column is not nullable, use db default value.
                if (strtolower($detail->Null) === 'no') {
                    $entity[$field] = $detail->Default;
                }
            } else {
                // Convert to correct type.
                $dataType = DataType::getInstance($this->db->getName());

                $type = explode(' ', $detail->Type)[0];
                $type = explode('(', $type)[0];

                settype($value, $dataType::getPhpType($type));

                $entity[$field] = $value;
            }
        }

        return $entity;
    }
protected function validValue(Entity $entity)
    {
        foreach ($entity->getFields() as $field => $detail) {
            $value = $entity[$field];

            // Convert value type
            if ($value instanceof \DateTimeInterface) {
                $value = $value->format($this->db->getDateFormat());
            }

            if ($value instanceof JsonSerializer) {
                $value = json_encode($value);
            }

            if (\is_object($value) && \is_callable([$value, '__toString'])) {
                $value = (string) $value;
            }

            // Start prepare default value
            if (is_array($value) || is_object($value)) {
                $value = null;
            }

            if ($value === null) {
                // This field is null and the db column is not nullable, use db default value.
                if (strtolower($detail->Null) === 'no') {
                    $entity[$field] = $detail->Default;
                }
            } else {
                // Convert to correct type.
                $dataType = DataType::getInstance($this->db->getName());

                $type = explode(' ', $detail->Type)[0];
                $type = explode('(', $type)[0];

                settype($value, $dataType::getPhpType($type));

                $entity[$field] = $value;
            }
        }

        return $entity;
    }
protected function validValue ( Entity $ entity ) { foreach ( $ entity -> getFields ( ) as $ field => $ detail ) { $ value = $ entity [ $ field ] ; // Convert value type if ( $ value instanceof \ DateTimeInterface ) { $ value = $ value -> format ( $ this -> db -> getDateFormat ( ) ) ; } if ( $ value instanceof JsonSerializer ) { $ value = json_encode ( $ value ) ; } if ( \ is_object ( $ value ) && \ is_callable ( [ $ value , '__toString' ] ) ) { $ value = ( string ) $ value ; } // Start prepare default value if ( is_array ( $ value ) || is_object ( $ value ) ) { $ value = null ; } if ( $ value === null ) { // This field is null and the db column is not nullable, use db default value. if ( strtolower ( $ detail -> Null ) === 'no' ) { $ entity [ $ field ] = $ detail -> Default ; } } else { // Convert to correct type. $ dataType = DataType :: getInstance ( $ this -> db -> getName ( ) ) ; $ type = explode ( ' ' , $ detail -> Type ) [ 0 ] ; $ type = explode ( '(' , $ type ) [ 0 ] ; settype ( $ value , $ dataType :: getPhpType ( $ type ) ) ; $ entity [ $ field ] = $ value ; } } return $ entity ; }
If creating item or updating with null values, we must check all NOT NULL
fields are using valid default value instead NULL value. This helps us get rid of
this Mysql warning in STRICT_TRANS_TABLE mode.

@param Entity $entity

@return  Entity
If creating item or updating with null values we must check all NOT NULL fields are using valid default value instead NULL value . This helps us get rid of this Mysql warning in STRICT_TRANS_TABLE mode .