Skip to content

Commit 49a1932

Browse files
authored
fix: avoid unnecessary query when counting relations (#29)
1 parent 72053cf commit 49a1932

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/QueryBuilder/ModelLoader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ public function loadMissing($includePaths): self
123123
*/
124124
public function loadCount($countable): self
125125
{
126-
$counter = new CountableLoader(
127-
$this->schema,
128-
CountablePaths::cast($countable)
129-
);
126+
$paths = CountablePaths::cast($countable);
130127

131-
$this->target->loadCount($counter->getRelations());
128+
if ($paths->isNotEmpty()) {
129+
$counter = new CountableLoader($this->schema, $paths);
130+
$this->target->loadCount($counter->getRelations());
131+
}
132132

133133
return $this;
134134
}

0 commit comments

Comments
 (0)