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

Merge in current changes #3

Merged
merged 4 commits into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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