浏览代码

Throw warnings if an ORM instance is unable to update/insert a row

Nathaniel van Diepen 6 年之前
父节点
当前提交
6e06fec289
共有 1 个文件被更改,包括 7 次插入3 次删除
  1. 7 3
      orm.abstract.class.php

+ 7 - 3
orm.abstract.class.php

@@ -317,11 +317,15 @@
 				$pk = static::primary_key();
 				$pk = static::primary_key();
 				$table = static::table();
 				$table = static::table();
 				if($this->has($pk) && !is_null($this->id) && !in_array($pk, $this->_changed)){
 				if($this->has($pk) && !is_null($this->id) && !in_array($pk, $this->_changed)){
-					$table->update($data, [
+					if($table->update($data, [
 						$pk => $this->id
 						$pk => $this->id
-					]);
+					]) === 0){
+						trigger_error("Save of {$this->name} may have failed. No affected rows.", E_USER_WARNING);
+					}
 				}else{
 				}else{
-					$table->insert($data);
+					if($table->insert($data) === 0){
+						trigger_error("First save of {$this->name} may have failed. No affected rows.", E_USER_WARNING);
+					}
 					$this->_data[$pk] = self::$pdo->lastInsertId();
 					$this->_data[$pk] = self::$pdo->lastInsertId();
 				}
 				}
 				foreach($this->_related as $related){
 				foreach($this->_related as $related){