Skip to content

Commit afde4e9

Browse files
committed
add im clear function
1 parent b6b5298 commit afde4e9

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
/vendor/
3+
composer.lock

src/IdentityMap.php

+6
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,10 @@ public function markTracked($key)
9090
{
9191
return $this->trackedRelations[] = $key;
9292
}
93+
94+
public function clear()
95+
{
96+
$this->trackedRelations = [];
97+
$this->items = [];
98+
}
9399
}

src/Populator.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,25 @@ protected function populateRelation(Model $model, string $relationName, ?array $
151151
private function initRelationPopulators(): void
152152
{
153153
$this->relationPopulators = [
154-
MorphTo::class => new MorphToPopulator($this->resolver, $this->uow, $this),
155-
HasMany::class => new HasManyPopulator($this->resolver, $this->uow, $this),
154+
MorphTo::class => new MorphToPopulator($this->resolver, $this->uow, $this),
155+
HasMany::class => new HasManyPopulator($this->resolver, $this->uow, $this),
156156
BelongsToMany::class => new BelongsToManyPopulator($this->resolver, $this->uow, $this),
157-
BelongsTo::class => new BelongsToPopulator($this->resolver, $this->uow, $this),
158-
HasOne::class => new HasOnePopulator($this->resolver, $this->uow, $this),
159-
MorphOne::class => new MorphOnePopulator($this->resolver, $this->uow, $this),
160-
MorphMany::class => new MorphManyPopulator($this->resolver, $this->uow, $this),
161-
MorphToMany::class => new MorphToManyPopulator($this->resolver, $this->uow, $this),
157+
BelongsTo::class => new BelongsToPopulator($this->resolver, $this->uow, $this),
158+
HasOne::class => new HasOnePopulator($this->resolver, $this->uow, $this),
159+
MorphOne::class => new MorphOnePopulator($this->resolver, $this->uow, $this),
160+
MorphMany::class => new MorphManyPopulator($this->resolver, $this->uow, $this),
161+
MorphToMany::class => new MorphToManyPopulator($this->resolver, $this->uow, $this),
162162
];
163163
}
164164

165165
private function extractRelation(Model $model, string $relationName): Relation
166166
{
167167
return call_user_func([$model, $relationName]);
168168
}
169+
170+
171+
public function clear()
172+
{
173+
$this->clear();
174+
}
169175
}

src/UnitOfWork.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function doDestroy(): void
8484
$model->delete();
8585
}
8686
}
87-
$this->toPersist = [];
87+
$this->toDestroy = [];
8888
}
8989

9090
public function onFlush(callable $fn): void
@@ -100,4 +100,8 @@ private function doOnFlush(): void
100100

101101
$this->onFlushInstructions = [];
102102
}
103+
104+
public function clear(): void {
105+
$this->map->clear();
106+
}
103107
}

0 commit comments

Comments
 (0)