Skip to content

Commit

Permalink
Update RelationMixin.php
Browse files Browse the repository at this point in the history
  • Loading branch information
biiiiiigmonster authored Dec 22, 2020
1 parent 40cc3a2 commit 3359163
Showing 1 changed file with 0 additions and 16 deletions.
16 changes: 0 additions & 16 deletions src/Database/Eloquent/RelationMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@ public function getRelationInQuery(): Closure
return $query->select($columns);
};
$hasOneOrMany = function (Builder $query, Builder $parentQuery, $columns = ['*'])use($relation): Builder{
/** @var HasOneOrMany $this */
$columns = $columns == ['*'] ? $this->getExistenceCompareKey() : $columns;// getExistenceCompareKey借用Exists 语法用到的id
if ($query->getQuery()->from == $parentQuery->getQuery()->from) {
return $this->getRelationExistenceQueryForSelfRelation($query, $parentQuery, $columns);
}

return $relation($query, $parentQuery, $columns);
};
$morphOneOrMany = function (Builder $query, Builder $parentQuery, $columns = ['*'])use($hasOneOrMany): Builder{
/** @var MorphOneOrMany $this */
$columns = $columns == ['*'] ? $this->getExistenceCompareKey() : $columns;// getExistenceCompareKey借用Exists 语法用到的id
return $hasOneOrMany($query, $parentQuery, $columns)->where(
$query->qualifyColumn($this->getMorphType()), $this->morphClass
);
Expand All @@ -51,20 +44,12 @@ public function getRelationInQuery(): Closure
$belongsTo = function (Builder $query, Builder $parentQuery, $columns = ['*']): Builder{
/** @var BelongsTo $this */
$columns = $columns == ['*'] ? $query->qualifyColumn($this->ownerKey) : $columns;
if ($parentQuery->getQuery()->from == $query->getQuery()->from) {
return $this->getRelationExistenceQueryForSelfRelation($query, $parentQuery, $columns);
}

return $query->select($columns);
};
// BelongsToMany (extend Relation, iteration)
$belongsToMany = function (Builder $query, Builder $parentQuery, $columns = ['*'])use($relation): Builder{
/** @var BelongsToMany $this */
$columns = $columns == ['*'] ? $this->getExistenceCompareKey() : $columns;// getExistenceCompareKey借用Exists 语法用到的id
if ($parentQuery->getQuery()->from == $query->getQuery()->from) {
return $this->getRelationExistenceQueryForSelfJoin($query, $parentQuery, $columns);
}

$this->performJoin($query);

return $relation($query, $parentQuery, $columns);
Expand Down Expand Up @@ -112,7 +97,6 @@ public function getRelationInQuery(): Closure
// MorphToMany (extend BelongsToMany, iteration)
$morphToMany = function (Builder $query, Builder $parentQuery, $columns = ['*'])use($belongsToMany): Builder{
/** @var MorphToMany $this */
$columns = $columns == ['*'] ? $this->getExistenceCompareKey() : $columns;// getExistenceCompareKey借用Exists 语法用到的id
return $belongsToMany($query, $parentQuery, $columns)->where(
$this->table.'.'.$this->morphType, $this->morphClass
);
Expand Down

0 comments on commit 3359163

Please sign in to comment.