Skip to content

Commit 1aa438c

Browse files
Add is method for Oid managment
1 parent 070a611 commit 1aa438c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Eloquent/Model.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,4 +771,29 @@ public function refresh()
771771

772772
return $this;
773773
}
774+
775+
/**
776+
* Determine if two models have the same ID and belong to the same table.
777+
*
778+
* @param \Illuminate\Database\Eloquent\Model|null $model
779+
* @return bool
780+
*/
781+
public function is($model)
782+
{
783+
$modelKey = $model?->getKey();
784+
$currentKey = $this->getKey();
785+
786+
if ($modelKey instanceof \MongoDB\BSON\ObjectId) {
787+
$modelKey = (string) $modelKey;
788+
}
789+
790+
if ($currentKey instanceof \MongoDB\BSON\ObjectId) {
791+
$currentKey = (string) $currentKey;
792+
}
793+
794+
return ! is_null($model) &&
795+
$currentKey === $modelKey &&
796+
$this->getTable() === $model->getTable() &&
797+
$this->getConnectionName() === $model->getConnectionName();
798+
}
774799
}

0 commit comments

Comments
 (0)