Skip to content

Commit 93b8605

Browse files
committed
Fixed where clause parsing to provide for NotNull
1 parent cb589eb commit 93b8605

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed

src/CachedBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ protected function getWhereClauses() : string
8585
}
8686

8787
$value = $where['type'] === 'Null' ? 'null' : $value;
88+
$value = $where['type'] === 'NotNull' ? 'notnull' : $value;
8889

8990
return "{$carry}-{$where['column']}_{$value}";
9091
}) ?: '';

tests/Fixtures/UncachedBook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
22

3-
use GeneaLabs\LaravelModelCaching\CachedModel;
3+
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Database\Eloquent\Relations\BelongsTo;
55
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
66

7-
class UncachedBook extends CachedModel
7+
class UncachedBook extends Model
88
{
99
protected $dates = [
1010
'published_at',

tests/Fixtures/UncachedProfile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
22

3-
use GeneaLabs\LaravelModelCaching\CachedModel;
3+
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Database\Eloquent\Relations\HasMany;
55
use Illuminate\Database\Eloquent\Relations\BelongsTo;
66

7-
class UncachedProfile extends CachedModel
7+
class UncachedProfile extends Model
88
{
99
protected $fillable = [
1010
'first_name',

tests/Fixtures/UncachedPublisher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
22

3-
use GeneaLabs\LaravelModelCaching\CachedModel;
3+
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Database\Eloquent\Relations\HasMany;
55

6-
class UncachedPublisher extends CachedModel
6+
class UncachedPublisher extends Model
77
{
88
protected $fillable = [
99
'name',

tests/Fixtures/UncachedStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
22

3-
use GeneaLabs\LaravelModelCaching\CachedModel;
3+
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
55

6-
class UncachedStore extends CachedModel
6+
class UncachedStore extends Model
77
{
88
protected $fillable = [
99
'address',

tests/Unit/CachedBuilderTest.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -415,26 +415,20 @@ public function testValueModelResultsCreatesCache()
415415

416416
public function testNestedRelationshipEagerloading()
417417
{
418-
$authors = collect()->push(
419-
(new Author)->with('books.publisher')
420-
->first()
421-
);
418+
$authors = collect([(new Author)->with('books.publisher')
419+
->first()]);
420+
422421
$key = 'genealabslaravelmodelcachingtestsfixturesauthor-books-books.publisher-first';
423422
$tags = [
424423
'genealabslaravelmodelcachingtestsfixturesauthor',
425424
'genealabslaravelmodelcachingtestsfixturesbook',
426425
'genealabslaravelmodelcachingtestsfixturespublisher',
427426
];
428427

429-
$cachedResults = collect()->push(
430-
cache()->tags($tags)
431-
->get($key)
432-
);
433-
434-
$liveResults = collect()->push(
435-
(new UncachedAuthor)->with('books.publisher')
436-
->first()
437-
);
428+
$cachedResults = collect([cache()->tags($tags)
429+
->get($key)]);
430+
$liveResults = collect([(new UncachedAuthor)->with('books.publisher')
431+
->first()]);
438432

439433
$this->assertEmpty($authors->diffAssoc($cachedResults));
440434
$this->assertEmpty($liveResults->diffAssoc($cachedResults));
@@ -443,7 +437,7 @@ public function testNestedRelationshipEagerloading()
443437
public function testLazyLoadedRelationshipResolvesThroughCachedBuilder()
444438
{
445439
$books = (new Author)->first()->books;
446-
$key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1';
440+
$key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1-books.author_id_notnull';
447441
$tags = [
448442
'genealabslaravelmodelcachingtestsfixturesbook',
449443
];
@@ -458,7 +452,7 @@ public function testLazyLoadedRelationshipResolvesThroughCachedBuilder()
458452
public function testLazyLoadingOnResourceIsCached()
459453
{
460454
$books = (new AuthorResource((new Author)->first()))->books;
461-
$key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1';
455+
$key = 'genealabslaravelmodelcachingtestsfixturesbook-books.author_id_1-books.author_id_notnull';
462456
$tags = [
463457
'genealabslaravelmodelcachingtestsfixturesbook',
464458
];

0 commit comments

Comments
 (0)