Skip to content

Commit f5cd3fe

Browse files
committed
Query optimization
1 parent f814ba8 commit f5cd3fe

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/LaravelSubQuery.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ protected function withSubQuery($relations, $type, $orderType = null)
124124
// to the developer for further constraint chaining that needs to take place on it.
125125
$column = $alias ?? Str::snake($name.'_'.$column.'_'.$type);
126126

127-
$this->selectSub($query, $column);
127+
if (strpos($this->toSql(), $query->toSql()) === false) {
128+
$this->selectSub($query, $column);
129+
}
128130

129131
// Add sorting
130132
if ($orderType) {

0 commit comments

Comments
 (0)