Skip to content

Commit

Permalink
一对一关联预查寻支持其他关联表字段作为外键
Browse files Browse the repository at this point in the history
  • Loading branch information
augushong authored and liu21st committed Dec 15, 2022
1 parent 958b96c commit 75b8512
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/model/relation/OneToOne.php
Expand Up @@ -91,9 +91,23 @@ public function eagerly(Query $query, string $relation, $field = true, string $j
$query->via($joinAlias);

if ($this instanceof BelongsTo) {
$joinOn = $name . '.' . $this->foreignKey . '=' . $joinAlias . '.' . $this->localKey;

$foreignKeyExp = $this->foreignKey;

if (strpos($foreignKeyExp, '.') === false) {
$foreignKeyExp = $name . '.' . $this->foreignKey;
}

$joinOn = $foreignKeyExp . '=' . $joinAlias . '.' . $this->localKey;
} else {
$joinOn = $name . '.' . $this->localKey . '=' . $joinAlias . '.' . $this->foreignKey;

$foreignKeyExp = $this->foreignKey;

if (strpos($foreignKeyExp, '.') === false) {
$foreignKeyExp = $joinAlias . '.' . $this->foreignKey;
}

$joinOn = $name . '.' . $this->localKey . '=' . $foreignKeyExp;
}

if ($closure) {
Expand Down

0 comments on commit 75b8512

Please sign in to comment.