Skip to content

Commit

Permalink
add im clear function
Browse files Browse the repository at this point in the history
  • Loading branch information
greabock committed Jun 10, 2022
1 parent b6b5298 commit afde4e9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
/vendor/
composer.lock
6 changes: 6 additions & 0 deletions src/IdentityMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,10 @@ public function markTracked($key)
{
return $this->trackedRelations[] = $key;
}

public function clear()
{
$this->trackedRelations = [];
$this->items = [];
}
}
20 changes: 13 additions & 7 deletions src/Populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,25 @@ protected function populateRelation(Model $model, string $relationName, ?array $
private function initRelationPopulators(): void
{
$this->relationPopulators = [
MorphTo::class => new MorphToPopulator($this->resolver, $this->uow, $this),
HasMany::class => new HasManyPopulator($this->resolver, $this->uow, $this),
MorphTo::class => new MorphToPopulator($this->resolver, $this->uow, $this),
HasMany::class => new HasManyPopulator($this->resolver, $this->uow, $this),
BelongsToMany::class => new BelongsToManyPopulator($this->resolver, $this->uow, $this),
BelongsTo::class => new BelongsToPopulator($this->resolver, $this->uow, $this),
HasOne::class => new HasOnePopulator($this->resolver, $this->uow, $this),
MorphOne::class => new MorphOnePopulator($this->resolver, $this->uow, $this),
MorphMany::class => new MorphManyPopulator($this->resolver, $this->uow, $this),
MorphToMany::class => new MorphToManyPopulator($this->resolver, $this->uow, $this),
BelongsTo::class => new BelongsToPopulator($this->resolver, $this->uow, $this),
HasOne::class => new HasOnePopulator($this->resolver, $this->uow, $this),
MorphOne::class => new MorphOnePopulator($this->resolver, $this->uow, $this),
MorphMany::class => new MorphManyPopulator($this->resolver, $this->uow, $this),
MorphToMany::class => new MorphToManyPopulator($this->resolver, $this->uow, $this),
];
}

private function extractRelation(Model $model, string $relationName): Relation
{
return call_user_func([$model, $relationName]);
}


public function clear()
{
$this->clear();
}
}
6 changes: 5 additions & 1 deletion src/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function doDestroy(): void
$model->delete();
}
}
$this->toPersist = [];
$this->toDestroy = [];
}

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

$this->onFlushInstructions = [];
}

public function clear(): void {
$this->map->clear();
}
}

0 comments on commit afde4e9

Please sign in to comment.