File tree 2 files changed +33
-3
lines changed
tests/Integration/CachedBuilder
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 = '')
114
114
115
115
public function insert (array $ values )
116
116
{
117
- $ this ->checkCooldownAndFlushAfterPersisting ($ this ->model );
118
-
117
+ if (property_exists ($ this , "model " )) {
118
+ $ this ->checkCooldownAndFlushAfterPersisting ($ this ->model );
119
+ }
120
+
119
121
return parent ::insert ($ values );
120
122
}
121
123
@@ -202,7 +204,9 @@ public function sum($column)
202
204
203
205
public function update (array $ values )
204
206
{
205
- $ this ->checkCooldownAndFlushAfterPersisting ($ this ->model );
207
+ if (property_exists ($ this , "model " )) {
208
+ $ this ->checkCooldownAndFlushAfterPersisting ($ this ->model );
209
+ }
206
210
207
211
return parent ::update ($ values );
208
212
}
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