diff --git a/CHANGELOG.md b/CHANGELOG.md index b88953d..0a5ac21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Change `orchestra/testbench` version to match Laravel version. +### Added +- Added a `IdentityManager::flushIdentities()` method to clear the identity map. ## [1.0.0] - 2020-06-24 - Initial release diff --git a/README.md b/README.md index 0d4e76c..183c03a 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ using the Identity Map design pattern ([P of EAA](https://martinfowler.com/eaaCa - [Finding](#finding) - [Hydrating](#hydrating) - [Belongs To](#belongsto) + - [Flushing](#flushing) - [How does it work](#how) - [Why?](#why) @@ -68,6 +69,10 @@ updated, but will retain any changes you'd previously made. If a belongs to relationship is loaded (not belongs to many) without constraints and without `refreshIdentityMap()` being called, the query will skip any model instances that already exist. +### Flushing +If you wish to flush the cached models, call `flushIdentities()` on an instance of `IdentityManager`, or on the `Eloquence` +facade. + ## How The `IdentityManager` stores an array containing all existing model instances and their identity. diff --git a/composer.json b/composer.json index 2d433e9..04ff52a 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "laravel/framework": "^7.0" }, "require-dev": { - "orchestra/testbench": "^4.0" + "orchestra/testbench": "^5.0" }, "extra": { "laravel": { diff --git a/src/IdentityManager.php b/src/IdentityManager.php index a762afe..81c0ea9 100644 --- a/src/IdentityManager.php +++ b/src/IdentityManager.php @@ -94,6 +94,18 @@ public function removeIdentity(ModelIdentity $identity): IdentityManager return $this; } + /** + * Remove all models from the identity map. + * + * @return $this + */ + public function flushIdentities(): IdentityManager + { + $this->models = []; + + return $this; + } + /** * Get all stored identities. *