Prechádzať zdrojové kódy

Update: 默认将主键设置为唯一,和更新排除唯一字段

zjh 4 mesiacov pred
rodič
commit
069786554f
2 zmenil súbory, kde vykonal 24 pridanie a 3 odobranie
  1. 6 2
      src/Driver/Entity/Base.php
  2. 18 1
      src/Driver/Entity/Entity.php

+ 6 - 2
src/Driver/Entity/Base.php

@@ -1181,10 +1181,14 @@ class Base {
                 ]
             );
         }
+        $msg = '更新成功';
+        if($affectedRows > 0) {
+            $msg .= ',共更新了'. $affectedRows . '条记录';
+        }
         return Response::Success(static::class .'::'. __FUNCTION__,
             [
-                '_result' => ['code' => Response::DO_SUCCESS, 'msg' => '数据更新成功,总共更新了'. $affectedRows . '条记录', 'body' => $affectedRows],
-                'message' => '数据更新成功,总共更新了'. $affectedRows . '条记录'
+                '_result' => ['code' => Response::DO_SUCCESS, 'msg' => $msg, 'body' => $affectedRows],
+                'message' => $msg
             ]
         );
     }

+ 18 - 1
src/Driver/Entity/Entity.php

@@ -318,7 +318,16 @@ DOC;
      */
     public function uniqueKey(){
         if(\$this->uniqKeys !== null) return \$this->uniqKeys;
+DOC;
+        if($primaryKey) {
+            $next[] = "\t\treturn array('". join("','", $primaryKey). "');";
+        }else {
+
+            $next[] = <<<DOC
         throw new \Exception('请设置`{$tableInfo['table']}`表更新唯一值');
+DOC;
+        }
+            $next[] = <<<DOC
     }
 
     /**
@@ -347,7 +356,15 @@ DOC;
      */
     public function exclude(){
         if(\$this->exclude !== null) return \$this->exclude;
-        return array();
+DOC;
+    if($primaryKey) {
+        $next[] = "\t\treturn array('". join("','", $primaryKey). "');";
+    }else{
+        $next[] = <<<DOC
+    return array();
+DOC;
+    }
+    $next[] = <<<DOC
     }
     /**
      * 添加时验证的字段,自行添加