Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3 from sprocketbox/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ollieread authored Jun 28, 2020
2 parents ba29c7c + 63b0fd2 commit 94c0f21
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"laravel/framework": "^7.0"
},
"require-dev": {
"orchestra/testbench": "^4.0"
"orchestra/testbench": "^5.0"
},
"extra": {
"laravel": {
Expand Down
12 changes: 12 additions & 0 deletions src/IdentityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 94c0f21

Please # to comment.