Browse Source

update field

朱金辉 2 months ago
parent
commit
462b6e319d
1 changed files with 8 additions and 4 deletions
  1. 8 4
      src/Driver/Entity/Base.php

+ 8 - 4
src/Driver/Entity/Base.php

@@ -978,8 +978,11 @@ class Base {
      *
      * @return \Qii\Driver\Base
      */
-    public function createQuery() {
-        $query = $this->db()->fields($this->getFields())->where($this->getWhereHooker())->fetchSql($this->calledSQL);
+    public function createQuery($fields = []) {
+        if(empty($fields)) {
+            $fields = $this->getFields();
+        }
+        $query = $this->db()->fields($fields)->where($this->getWhereHooker())->fetchSql($this->calledSQL);
         $or = $this->getOrHooker();
         foreach ($or as $v) {
             $query = $query->orTerms($v);
@@ -1172,7 +1175,8 @@ class Base {
         if(count($this->getFields()) > 0 && !in_array($relKey, $this->getFields())) {
             $fields[] = $relKey;
         }
-        $query = $this->createQuery()->fields($fields, true);
+        $fields = array_unique($fields);
+        $query = $this->createQuery($fields);
         $res = $query->where($args[1])->rs($this->prepareTable());
         $rows = [];
         foreach($res as $v) {
@@ -1200,7 +1204,7 @@ class Base {
         if(count($this->getFields()) > 0 && !in_array($relKey, $this->getFields())) {
             $fields[] = $relKey;
         }
-        $query = $this->createQuery()->fields($fields, true);
+        $query = $this->createQuery($fields);
         $res = $query->where($args[1])->rs($this->prepareTable());
         echo $this->calledSQL;
         $rows = [];