Commit 4992e8fc authored by Jens Segers's avatar Jens Segers

Adding stuff, not tested

parent 459dd836
...@@ -20,6 +20,27 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -20,6 +20,27 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
*/ */
protected $primaryKey = '_id'; protected $primaryKey = '_id';
/**
* Convert a DateTime to a storable string.
*
* @param DateTime $value
* @return MongoDate
*/
protected function fromDateTime(DateTime $value)
{
return new MongoDate($value->getTimestamp());
}
/**
* Get a fresh timestamp for the model.
*
* @return MongoDate
*/
public function freshTimestamp()
{
return new MongoDate;
}
/** /**
* Get a new query builder instance for the connection. * Get a new query builder instance for the connection.
* *
...@@ -28,7 +49,7 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model { ...@@ -28,7 +49,7 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
protected function newBaseQueryBuilder() protected function newBaseQueryBuilder()
{ {
$connection = $this->getConnection(); $connection = $this->getConnection();
return new QueryBuilder($connection, $this->collection); return new QueryBuilder($connection);
} }
} }
\ No newline at end of file
...@@ -32,10 +32,9 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -32,10 +32,9 @@ class Query extends \Illuminate\Database\Query\Builder {
* @param Connection $connection * @param Connection $connection
* @return void * @return void
*/ */
public function __construct(Connection $connection, $collection) public function __construct(Connection $connection)
{ {
$this->connection = $connection; $this->connection = $connection;
$this->collection = $connection->getCollection($collection);
} }
/** /**
...@@ -70,7 +69,22 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -70,7 +69,22 @@ class Query extends \Illuminate\Database\Query\Builder {
if (in_array('*', $this->columns)) $this->columns = array(); if (in_array('*', $this->columns)) $this->columns = array();
// Get Mongo cursor // Get Mongo cursor
$cursor = $this->collection->find($this->compileWheres(), $this->columns); if ($this->distinct)
{
$cursor = $this->collection->distinct($this->columns, $this->compileWheres());
}
else if(count($this->groups))
{
$options = array();
$options['condition'] = $this->compileWheres();
$result = $this->collection->group($this->groups, array(), NULL, $options);
$cursor = $result['retval'];
}
else
{
$cursor = $this->collection->find($this->compileWheres(), $this->columns);
}
// Apply order // Apply order
if ($this->orders) if ($this->orders)
...@@ -174,6 +188,19 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -174,6 +188,19 @@ class Query extends \Illuminate\Database\Query\Builder {
return 0; return 0;
} }
/**
* Set the collection which the query is targeting.
*
* @param string $collection
* @return Builder
*/
public function from($collection)
{
$this->collection = $this->connection->getCollection($collection);
return $this;
}
/** /**
* Compile the where array * Compile the where array
* *
......
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