Skip to content

Commit 19bcdf2

Browse files
Having clauses missing from the generated CacheKey (#403)
1 parent 650e20d commit 19bcdf2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/CacheKey.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ public function make(
5151
$key .= $this->getIdColumn($idColumn ?: "");
5252
$key .= $this->getQueryColumns($columns);
5353
$key .= $this->getWhereClauses();
54+
$key .= $this->getHavingClauses();
5455
$key .= $this->getWithModels();
5556
$key .= $this->getOrderByClauses();
5657
$key .= $this->getOffsetClause();
5758
$key .= $this->getLimitClause();
5859
$key .= $this->getBindingsSlug();
5960
$key .= $keyDifferentiator;
6061
$key .= $this->macroKey;
61-
// dump($key);
62+
6263
return $key;
6364
}
6465

@@ -101,6 +102,27 @@ protected function getCurrentBinding(string $type, $bindingFallback = null)
101102
return data_get($this->query->bindings, "{$type}.{$this->currentBinding}", $bindingFallback);
102103
}
103104

105+
protected function getHavingClauses()
106+
{
107+
return Collection::make($this->query->havings)->reduce(function ($carry, $having) {
108+
$value = $carry;
109+
$value .= $this->getHavingClause($having);
110+
111+
return $value;
112+
});
113+
}
114+
115+
protected function getHavingClause(array $having): string
116+
{
117+
$return = '-having';
118+
119+
foreach ($having as $key => $value) {
120+
$return .= '_' . $key . '_' . str_replace(' ', '_', $value);
121+
}
122+
123+
return $return;
124+
}
125+
104126
protected function getIdColumn(string $idColumn) : string
105127
{
106128
return $idColumn ? "_{$idColumn}" : "";

0 commit comments

Comments
 (0)