File tree Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,6 @@ public function create($data): Entity
5757 }
5858
5959 foreach ($ this ->getMapper ()->getPlugins () as $ plugin ) {
60- $ plugin ->generateKey ($ instance , $ this ->space );
6160 $ plugin ->afterInstantiate ($ instance , $ this ->space );
6261 }
6362
@@ -299,15 +298,15 @@ public function save(Entity $instance): Entity
299298 $ client ->getSpaceById ($ this ->getSpace ()->id )
300299 ->insert ($ tuple );
301300
301+ $ instance ->setOriginalTuple ($ tuple );
302+
302303 foreach ($ this ->getMapper ()->getPlugins () as $ plugin ) {
303304 $ plugin ->afterCreate ($ instance , $ this ->space );
304305 }
305306
306307 if (method_exists ($ instance , 'afterCreate ' )) {
307308 $ instance ->afterCreate ();
308309 }
309-
310- $ instance ->setOriginalTuple ($ tuple );
311310 }
312311
313312 return $ instance ;
Original file line number Diff line number Diff line change 1313
1414class AnnotationTest extends TestCase
1515{
16+ public function testEntityTriggers ()
17+ {
18+ $ mapper = $ this ->createMapper ();
19+ $ this ->clean ($ mapper );
20+ $ mapper ->getPlugin (Sequence::class);
21+
22+ $ mapper ->getPlugin (Annotation::class)
23+ ->register ('Entity \\Person ' )
24+ ->migrate ();
25+
26+ $ person = $ mapper ->getRepository ('person ' )->create ([
27+ 'name ' => 'bazyabushka ' ,
28+ ]);
29+
30+ $ this ->assertNull ($ person ->fullName );
31+ $ this ->assertNull ($ person ->id );
32+
33+ $ person ->save ();
34+
35+ $ this ->assertNotNull ($ person ->id );
36+ $ this ->assertSame ($ person ->fullName , 'bazyabushka!@ ' );
37+ }
38+
1639 public function testMixedClassMap ()
1740 {
1841 $ mapper = $ this ->createMapper ();
Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ class Person extends MapperEntity
2323
2424 public function beforeCreate ()
2525 {
26- $ this ->fullName = $ this ->name .'! ' ;
26+ $ this ->fullName = $ this ->name . '! ' ;
27+ }
28+
29+ public function afterCreate ()
30+ {
31+ $ this ->fullName = $ this ->fullName . '@ ' ;
2732 }
2833}
You can’t perform that action at this time.
0 commit comments