lizhen_gitee 1 년 전
부모
커밋
6379f00bd9
1개의 변경된 파일11개의 추가작업 그리고 1개의 파일을 삭제
  1. 11 1
      thinkphp/library/think/model/relation/OneToOne.php

+ 11 - 1
thinkphp/library/think/model/relation/OneToOne.php

@@ -77,11 +77,21 @@ abstract class OneToOne extends Relation
         $joinAlias = $relation;
         $query->via($joinAlias);
 
+        //lizhen
+        if(strpos($this->foreignKey,'.')){
+            $new_foreignKey = $this->foreignKey;
+        }else{
+            $new_foreignKey = $name . '.' . $this->foreignKey;
+        }
+
         if ($this instanceof BelongsTo) {
-            $query->join([$joinTable => $joinAlias], $name . '.' . $this->foreignKey . '=' . $joinAlias . '.' . $this->localKey, $this->joinType);
+            $query->join([$joinTable => $joinAlias], $new_foreignKey . '=' . $joinAlias . '.' . $this->localKey, $this->joinType);
+            //$query->join([$joinTable => $joinAlias], $name . '.' . $this->foreignKey . '=' . $joinAlias . '.' . $this->localKey, $this->joinType);
         } else {
             $query->join([$joinTable => $joinAlias], $name . '.' . $this->localKey . '=' . $joinAlias . '.' . $this->foreignKey, $this->joinType);
         }
+        //lizhen
+        
 
         if ($closure) {
             // 执行闭包查询