Commit fe7a1e85 authored by Jens Segers's avatar Jens Segers

Adding distinct

parent 04053e99
...@@ -89,4 +89,8 @@ Examples ...@@ -89,4 +89,8 @@ Examples
}) })
->get(); ->get();
**Distinct**
$users = Users::distinct('name')->get();
All basis insert, update, delete and select methods should be implemented. Feel free to fork and help completing this library! All basis insert, update, delete and select methods should be implemented. Feel free to fork and help completing this library!
\ No newline at end of file
...@@ -73,7 +73,7 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -73,7 +73,7 @@ class Query extends \Illuminate\Database\Query\Builder {
// Get Mongo cursor // Get Mongo cursor
if ($this->distinct) if ($this->distinct)
{ {
$cursor = $this->collection->distinct($this->columns, $this->compileWheres()); $cursor = $this->collection->distinct($this->distinct, $this->compileWheres());
} }
else if(count($this->groups)) else if(count($this->groups))
{ {
...@@ -204,6 +204,18 @@ class Query extends \Illuminate\Database\Query\Builder { ...@@ -204,6 +204,18 @@ class Query extends \Illuminate\Database\Query\Builder {
return $this; return $this;
} }
/**
* Force the query to only return distinct results.
*
* @return Builder
*/
public function distinct($column = false)
{
$this->distinct = $column;
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