Commit 955b214a authored by Jens Segers's avatar Jens Segers

Fixed issue #8

parent ade145c0
......@@ -268,8 +268,13 @@ class Builder extends \Illuminate\Database\Query\Builder {
if (1 == (int) $result['ok'])
{
if (!$sequence)
{
$sequence = '_id';
}
// Return id as a string
return (string) $values['_id'];
return (string) $values[$sequence];
}
}
......
......@@ -2,6 +2,7 @@
require_once('vendor/autoload.php');
require_once('models/User.php');
require_once('models/Soft.php');
require_once('models/Book.php');
use Jenssegers\Mongodb\Connection;
use Jenssegers\Mongodb\Model;
......@@ -19,6 +20,7 @@ class ModelTest extends PHPUnit_Framework_TestCase {
{
User::truncate();
Soft::truncate();
Book::truncate();
}
public function testNewModel()
......@@ -204,4 +206,24 @@ class ModelTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(1, $all->count());
}
public function testPrimaryKey()
{
$user = new User;
$this->assertEquals('_id', $user->getKeyName());
$book = new Book;
$this->assertEquals('title', $book->getKeyName());
$book->title = "A Game of Thrones";
$book->author = "George R. R. Martin";
$book->save();
$this->assertEquals("A Game of Thrones", $book->getKey());
$check = Book::find("A Game of Thrones");
$this->assertEquals('title', $check->getKeyName());
$this->assertEquals("A Game of Thrones", $check->getKey());
$this->assertEquals("A Game of Thrones", $check->title);
}
}
\ No newline at end of file
<?php
use Jenssegers\Mongodb\Model as Eloquent;
class Book extends Eloquent {
protected $collection = 'books';
protected static $unguarded = true;
protected $primaryKey = 'title';
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment