Skip to content

Commit 89e059b

Browse files
committed
Tweaking id accessor for #108
1 parent 01c4e0a commit 89e059b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Jenssegers/Mongodb/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getIdAttribute($value)
4848
// If there is an actual id attribute, then return that.
4949
if ($value) return $value;
5050

51-
return $this->getKey();
51+
return $this->attributes[$this->getKeyName()];
5252
}
5353

5454
/**

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use DateTime;
77
use Closure;
88

9+
use Illuminate\Database\Query\Expression;
910
use Jenssegers\Mongodb\Connection;
1011

1112
class Builder extends \Illuminate\Database\Query\Builder {
@@ -507,11 +508,19 @@ public function truncate()
507508
*/
508509
public function raw($expression = null)
509510
{
511+
// Execute the closure on the mongodb collection
510512
if ($expression instanceof Closure)
511513
{
512514
return call_user_func($expression, $this->collection);
513515
}
514516

517+
// Create an expression for the given value
518+
else if (!is_null($expression))
519+
{
520+
return new Expression($expression);
521+
}
522+
523+
// Quick access to the mongodb collection
515524
return $this->collection;
516525
}
517526

0 commit comments

Comments
 (0)