Skip to content

Commit cb59979

Browse files
committed
Refactor _id attribute getter
1 parent 1722daf commit cb59979

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/Jenssegers/Mongodb/Model.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,16 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
4949
*/
5050
public function getIdAttribute($value)
5151
{
52-
if ($value) {
53-
// Return _id as string
54-
if ($value instanceof MongoId) {
55-
return (string) $value;
56-
}
57-
58-
return $value;
52+
if (!$value && array_key_exists('_id', $this->attributes)) {
53+
$value = $this->attributes['_id'];
5954
}
6055

61-
if (array_key_exists('_id', $this->attributes))
62-
{
63-
// Return _id as string
64-
if ($this->attributes['_id'] instanceof MongoId) {
65-
return (string) $this->attributes['_id'];
66-
}
67-
68-
return $this->attributes['_id'];
56+
// Return _id as string
57+
if ($value instanceof MongoId) {
58+
return (string) $value;
6959
}
60+
61+
return $value;
7062
}
7163

7264
/**

0 commit comments

Comments
 (0)