From d49baac3173ab0aafc48661573dff8182031f86b Mon Sep 17 00:00:00 2001 From: sheychen Date: Tue, 1 May 2018 16:45:41 +0200 Subject: [PATCH] Fix: not null not checked with type --- src/Model.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Model.php b/src/Model.php index b010906..35a1c7f 100644 --- a/src/Model.php +++ b/src/Model.php @@ -139,6 +139,9 @@ class Model{ protected static function convertField($data, $field){ $options = static::getOptions($field); + if(is_null($data) && isset($options['not_null']) && $options['not_null'] == true) + throw new DatabaseException('Can\'t set null to NOT NULL field : '.$field); + if(isset($options['type'])){ switch(strtolower($options['type'])){ case 'int': @@ -157,9 +160,6 @@ class Model{ } } - if(is_null($data) && isset($options['not_null']) && $options['not_null'] == true) - throw new DatabaseException('Can\'t set null to NOT NULL field : '.$field); - return $data; }