Browse Source

Fixed hasOne 及 hasMany bugs

朱金辉 5 tháng trước cách đây
mục cha
commit
2f3950f71b
2 tập tin đã thay đổi với 10 bổ sung10 xóa
  1. 3 3
      src/Driver/Entity/Base.php
  2. 7 7
      src/Driver/Entity/Entity.php

+ 3 - 3
src/Driver/Entity/Base.php

@@ -1191,9 +1191,9 @@ class Base {
                 $fields = $with[5];
             }
             $rel = [];
-            foreach ($lists as $v) {
-                if(isset($v[$foreignKey])) {
-                    $rel[] = $v[$foreignKey];
+            foreach ($lists as $v1) {
+                if(isset($v1[$foreignKey])) {
+                    $rel[] = $v1[$foreignKey];
                 }
             }
             // [rel key, where]

+ 7 - 7
src/Driver/Entity/Entity.php

@@ -162,7 +162,6 @@ DOC;
                 $dynamicProperty[$property] = $defaults[$property];
             }
         }
-        if(count($dynamicProperty)) {
             $classAndProperty[] = <<<DOC
         /**
          * 动态变化的日期,初始化的时候赋值
@@ -196,16 +195,17 @@ DOC;
             $classAndProperty[] = "\t */";
             $classAndProperty[] = "\tpublic function defaultFieldsValue(){";
             $classAndProperty[] = "\t\t\$defaultValue = [];";
-            foreach ($dynamicProperty as $property => $dynamic) {
-                if($dynamic == 'CURRENT_TIMESTAMP') {
-                    $classAndProperty[] = "\t\t" . '$defaultValue[\''. $property ."'] = date('Y-m-d H:i:s');";
-                }else{
-                    $classAndProperty[] = "\t\t" . '$defaultValue[\''. $property ."'] = '". str_replace("'", "\\'", $dynamic)."';";
+            if(count($dynamicProperty) > 0) {
+                foreach ($dynamicProperty as $property => $dynamic) {
+                    if($dynamic == 'CURRENT_TIMESTAMP') {
+                        $classAndProperty[] = "\t\t" . '$defaultValue[\''. $property ."'] = date('Y-m-d H:i:s');";
+                    }else{
+                        $classAndProperty[] = "\t\t" . '$defaultValue[\''. $property ."'] = '". str_replace("'", "\\'", $dynamic)."';";
+                    }
                 }
             }
             $classAndProperty[] = "\t\treturn \$defaultValue;";
             $classAndProperty[] = "\t}";
-        }
         //生成 table rules
         $classAndProperty[] = $this->generateRules($tableInfo);
         $classAndProperty[] = '}';