-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
167f431
commit 011bfc0
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -491,4 +491,38 @@ protected function getQueryBuilderInstance() | |
|
||
/* Persistance methods **************/ | ||
/************************************/ | ||
|
||
/************************************/ | ||
/** Comparison methods **************/ | ||
|
||
/** | ||
* Is this model equal to another one? | ||
* | ||
* For a model to be equal to another it must: | ||
* - Be loaded | ||
* - Be of the same class | ||
* - Have the same id | ||
* | ||
* @param Ronanchilvers\Orm\Model $model | ||
* @return bool | ||
* @author Ronan Chilvers <[email protected]> | ||
*/ | ||
public function equals(Model $that): bool | ||
{ | ||
if (!$this->isLoaded() || !$that->isLoaded()) { | ||
return false; | ||
} | ||
if (get_class($that) !== get_called_class()) { | ||
return false; | ||
} | ||
$thisId = $this->getAttributes()[static::primaryKey()]; | ||
$thatId = $that->getAttributes()[static::primaryKey()]; | ||
if ($thisId != $thatId) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/************************************/ | ||
} |