|
2 | 2 |
|
3 | 3 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author; |
4 | 4 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book; |
| 5 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Comment; |
5 | 6 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile; |
6 | 7 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher; |
7 | 8 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store; |
8 | 9 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor; |
9 | 10 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook; |
| 11 | +use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedComment; |
10 | 12 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile; |
11 | 13 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher; |
12 | 14 | use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore; |
@@ -39,4 +41,24 @@ public function testWithCountUpdatesAfterRecordIsAdded() |
39 | 41 | $this->assertNotEquals($author1->books_count, $author2->books_count); |
40 | 42 | $this->assertEquals($author1->books_count + 1, $author2->books_count); |
41 | 43 | } |
| 44 | + |
| 45 | + public function testWithCountOnMorphManyRelationshipUpdatesAfterRecordIsAdded() |
| 46 | + { |
| 47 | + $book1 = (new Book) |
| 48 | + ->withCount("comments") |
| 49 | + ->first(); |
| 50 | + $comment = factory(Comment::class, 1) |
| 51 | + ->create() |
| 52 | + ->first(); |
| 53 | + |
| 54 | + $book1->comments()->save($comment); |
| 55 | + |
| 56 | + $book2 = (new Book) |
| 57 | + ->withCount("comments") |
| 58 | + ->where("id", $book1->id) |
| 59 | + ->first(); |
| 60 | + |
| 61 | + $this->assertNotEquals($book1->comments_count, $book2->comments_count); |
| 62 | + $this->assertEquals($book1->comments_count + 1, $book2->comments_count); |
| 63 | + } |
42 | 64 | } |
0 commit comments