Commit 6cc912f6 authored by Jens Segers's avatar Jens Segers

Merge branch 'master' into develop

parents d1a212cd 4fc8f12f
This diff is collapsed.
......@@ -33,7 +33,7 @@ class Connection extends \Illuminate\Database\Connection {
// Build the connection string
$dsn = $this->getDsn($config);
// You can pass options directly to the MogoClient constructor
// You can pass options directly to the MongoClient constructor
$options = array_get($config, 'options', array());
// Create the connection
......
<?php namespace Jenssegers\Mongodb;
use Illuminate\Database\Eloquent\Collection;
use Jenssegers\Mongodb\DatabaseManager as Resolver;
use Jenssegers\Mongodb\Eloquent\Builder;
use Jenssegers\Mongodb\Query\Builder as QueryBuilder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Jenssegers\Mongodb\Relations\EmbedsOneOrMany;
use Jenssegers\Mongodb\Relations\EmbedsMany;
......
......@@ -715,16 +715,20 @@ class Builder extends QueryBuilder {
*/
public function where($column, $operator = null, $value = null, $boolean = 'and')
{
$params = func_get_args();
// Remove the leading $ from operators.
if (func_num_args() == 3)
{
$operator = &$params[1];
if (starts_with($operator, '$'))
{
$operator = substr($operator, 1);
}
}
return parent::where($column, $operator, $value, $boolean);
return call_user_func_array('parent::where', $params);
}
/**
......@@ -883,14 +887,14 @@ class Builder extends QueryBuilder {
{
extract($where);
return array($column => array('$in' => $values));
return array($column => array('$in' => array_values($values)));
}
protected function compileWhereNotIn($where)
{
extract($where);
return array($column => array('$nin' => $values));
return array($column => array('$nin' => array_values($values)));
}
protected function compileWhereNull($where)
......
......@@ -258,6 +258,25 @@ class RelationsTest extends TestCase {
$this->assertStringStartsWith('synced', $user->clients[1]->name);
}
public function testBelongsToManySync()
{
// create test instances
$user = User::create(array('name' => 'John Doe'));
$client1 = Client::create(array('name' => 'Pork Pies Ltd.'))->_id;
$client2 = Client::create(array('name' => 'Buffet Bar Inc.'))->_id;
// Sync multiple
$user->clients()->sync(array($client1, $client2));
$this->assertCount(2, $user->clients);
// Refresh user
$user = User::where('name', '=', 'John Doe')->first();
// Sync single
$user->clients()->sync(array($client1));
$this->assertCount(1, $user->clients);
}
public function testBelongsToManyCustom()
{
$user = User::create(array('name' => 'John Doe'));
......
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