File tree 3 files changed +39
-1
lines changed
src/Jenssegers/Mongodb/Eloquent
3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public function update(array $values, array $options = [])
44
44
return 1 ;
45
45
}
46
46
47
- return $ this ->query ->update ($ this ->addUpdatedAtColumn ($ values ), $ options );
47
+ return $ this ->toBase () ->update ($ this ->addUpdatedAtColumn ($ values ), $ options );
48
48
}
49
49
50
50
/**
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ public function setUp(): void
21
21
public function tearDown (): void
22
22
{
23
23
User::truncate ();
24
+ Scoped::truncate ();
24
25
parent ::tearDown ();
25
26
}
26
27
@@ -309,4 +310,21 @@ public function testPaginate()
309
310
$ this ->assertEquals (9 , $ results ->total ());
310
311
$ this ->assertEquals (1 , $ results ->currentPage ());
311
312
}
313
+
314
+ public function testUpdate ()
315
+ {
316
+ $ this ->assertEquals (1 , User::where (['name ' => 'John Doe ' ])->update (['name ' => 'Jim Morrison ' ]));
317
+ $ this ->assertEquals (1 , User::where (['name ' => 'Jim Morrison ' ])->count ());
318
+
319
+ Scoped::create (['favorite ' => true ]);
320
+ Scoped::create (['favorite ' => false ]);
321
+
322
+ $ this ->assertCount (1 , Scoped::get ());
323
+ $ this ->assertEquals (1 , Scoped::query ()->update (['name ' => 'Johnny ' ]));
324
+ $ this ->assertCount (1 , Scoped::withoutGlobalScopes ()->where (['name ' => 'Johnny ' ])->get ());
325
+
326
+ $ this ->assertCount (2 , Scoped::withoutGlobalScopes ()->get ());
327
+ $ this ->assertEquals (2 , Scoped::withoutGlobalScopes ()->update (['name ' => 'Jimmy ' ]));
328
+ $ this ->assertCount (2 , Scoped::withoutGlobalScopes ()->where (['name ' => 'Jimmy ' ])->get ());
329
+ }
312
330
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Jenssegers \Mongodb \Eloquent \Model as Eloquent ;
4
+ use Jenssegers \Mongodb \Eloquent \Builder ;
5
+
6
+ class Scoped extends Eloquent
7
+ {
8
+ protected $ connection = 'mongodb ' ;
9
+ protected $ collection = 'scoped ' ;
10
+ protected $ fillable = ['name ' , 'favorite ' ];
11
+
12
+ protected static function boot ()
13
+ {
14
+ parent ::boot ();
15
+
16
+ static ::addGlobalScope ('favorite ' , function (Builder $ builder ) {
17
+ $ builder ->where ('favorite ' , true );
18
+ });
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments