Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having clauses missing from the generated CacheKey #403

Merged
merged 5 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
composer.lock
.phpunit.result.cache
phpunit.xml
.idea
24 changes: 23 additions & 1 deletion src/CacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,39 @@ 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;
}

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