File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
tests/Integration/CachedBuilder Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -114,8 +114,10 @@ public function inRandomOrder($seed = '')
114114
115115 public function insert (array $ values )
116116 {
117- $ this ->checkCooldownAndFlushAfterPersisting ($ this ->model );
118-
117+ if (property_exists ($ this , "model " )) {
118+ $ this ->checkCooldownAndFlushAfterPersisting ($ this ->model );
119+ }
120+
119121 return parent ::insert ($ values );
120122 }
121123
@@ -202,7 +204,9 @@ public function sum($column)
202204
203205 public function update (array $ values )
204206 {
205- $ this ->checkCooldownAndFlushAfterPersisting ($ this ->model );
207+ if (property_exists ($ this , "model " )) {
208+ $ this ->checkCooldownAndFlushAfterPersisting ($ this ->model );
209+ }
206210
207211 return parent ::update ($ values );
208212 }
Original file line number Diff line number Diff line change 1+ <?php namespace GeneaLabs \LaravelModelCaching \Tests \Integration \CachedBuilder ;
2+
3+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Book ;
4+ use GeneaLabs \LaravelModelCaching \Tests \IntegrationTestCase ;
5+
6+ class UpdateRelationTest extends IntegrationTestCase
7+ {
8+ public function testInRandomOrderCachesResults ()
9+ {
10+ $ book = (new Book )
11+ ->with ("stores " )
12+ ->whereHas ("stores " )
13+ ->first ();
14+ $ book ->stores ()
15+ ->update (["name " => "test store name change " ]);
16+ $ updatedCount = (new Book )
17+ ->with ("stores " )
18+ ->whereHas ("stores " )
19+ ->first ()
20+ ->stores ()
21+ ->where ("name " , "test store name change " )
22+ ->count ();
23+
24+ $ this ->assertEquals (1 , $ updatedCount );
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments