Skip to content

Commit 63748ef

Browse files
committed
fix instance triggers
1 parent 87cca4e commit 63748ef

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/Repository.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff 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;

tests/AnnotationTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@
1313

1414
class 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();

tests/Entity/Person.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)