Skip to content

Commit

Permalink
Having clauses missing from the generated CacheKey (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-waddell committed Dec 23, 2023
1 parent 650e20d commit 19bcdf2
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/CacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ public function make(
$key .= $this->getIdColumn($idColumn ?: "");
$key .= $this->getQueryColumns($columns);
$key .= $this->getWhereClauses();
$key .= $this->getHavingClauses();
$key .= $this->getWithModels();
$key .= $this->getOrderByClauses();
$key .= $this->getOffsetClause();
$key .= $this->getLimitClause();
$key .= $this->getBindingsSlug();
$key .= $keyDifferentiator;
$key .= $this->macroKey;
// dump($key);

return $key;
}

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

protected function getHavingClauses()
{
return Collection::make($this->query->havings)->reduce(function ($carry, $having) {
$value = $carry;
$value .= $this->getHavingClause($having);

return $value;
});
}

protected function getHavingClause(array $having): string
{
$return = '-having';

foreach ($having as $key => $value) {
$return .= '_' . $key . '_' . str_replace(' ', '_', $value);
}

return $return;
}

protected function getIdColumn(string $idColumn) : string
{
return $idColumn ? "_{$idColumn}" : "";
Expand Down

0 comments on commit 19bcdf2

Please sign in to comment.