WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 2501cd3

Browse files
author
Josh Ralph
committed
Handled Expressions in min / max methods
1 parent 1d523b9 commit 2501cd3

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/Traits/Buildable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function max($column)
144144
return parent::max($column);
145145
}
146146

147-
$cacheKey = $this->makeCacheKey(["*"], null, "-max_{$column}");
147+
$cacheKey = $this->makeCacheKey(["*"], null, "-max_{$this->expressionToString($column)}");
148148

149149
return $this->cachedValue(func_get_args(), $cacheKey);
150150
}
@@ -155,7 +155,7 @@ public function min($column)
155155
return parent::min($column);
156156
}
157157

158-
$cacheKey = $this->makeCacheKey(["*"], null, "-min_{$column}");
158+
$cacheKey = $this->makeCacheKey(["*"], null, "-min_{$this->expressionToString($column)}");
159159

160160
return $this->cachedValue(func_get_args(), $cacheKey);
161161
}

tests/Integration/CachedBuilderTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,26 @@ public function testMaxModelResultsCreatesCache()
318318
$this->assertEquals($liveResult, $cachedResult);
319319
}
320320

321+
public function testRawMaxModelResultsCreatesCache()
322+
{
323+
$authorId = (new Author)->with('books', 'profile')
324+
->max(new Expression('id + id'));
325+
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-testing:{$this->testingSqlitePath}testing.sqlite:books-testing:{$this->testingSqlitePath}testing.sqlite:profile-max_id + id");
326+
$tags = [
327+
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor",
328+
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook",
329+
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesprofile",
330+
];
331+
332+
$cachedResult = $this->cache()->tags($tags)
333+
->get($key)['value'];
334+
$liveResult = (new UncachedAuthor)->with('books', 'profile')
335+
->max(new Expression('id + id'));
336+
337+
$this->assertEquals($authorId, $cachedResult);
338+
$this->assertEquals($liveResult, $cachedResult);
339+
}
340+
321341
public function testMinModelResultsCreatesCache()
322342
{
323343
$authorId = (new Author)->with('books', 'profile')
@@ -338,6 +358,26 @@ public function testMinModelResultsCreatesCache()
338358
$this->assertEquals($liveResult, $cachedResult);
339359
}
340360

361+
public function testRawMinModelResultsCreatesCache()
362+
{
363+
$authorId = (new Author)->with('books', 'profile')
364+
->min(new Expression('id + id'));
365+
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-testing:{$this->testingSqlitePath}testing.sqlite:books-testing:{$this->testingSqlitePath}testing.sqlite:profile-min_id + id");
366+
$tags = [
367+
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor",
368+
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook",
369+
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesprofile",
370+
];
371+
372+
$cachedResult = $this->cache()->tags($tags)
373+
->get($key)['value'];
374+
$liveResult = (new UncachedAuthor)->with('books', 'profile')
375+
->min(new Expression('id + id'));
376+
377+
$this->assertEquals($authorId, $cachedResult);
378+
$this->assertEquals($liveResult, $cachedResult);
379+
}
380+
341381
public function testPluckModelResultsCreatesCache()
342382
{
343383
$authors = (new Author)->with('books', 'profile')

0 commit comments

Comments
 (0)