Skip to content

Commit 1722daf

Browse files
committed
Allows an _id attribute of another type than string
1 parent c22670a commit 1722daf

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Jenssegers/Mongodb/Model.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,18 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
4949
*/
5050
public function getIdAttribute($value)
5151
{
52-
if ($value) return (string) $value;
52+
if ($value) {
53+
// Return _id as string
54+
if ($value instanceof MongoId) {
55+
return (string) $value;
56+
}
57+
58+
return $value;
59+
}
5360

54-
// Return _id as string
5561
if (array_key_exists('_id', $this->attributes))
5662
{
63+
// Return _id as string
5764
if ($this->attributes['_id'] instanceof MongoId) {
5865
return (string) $this->attributes['_id'];
5966
}

0 commit comments

Comments
 (0)