Skip to content

Commit

Permalink
Now using v4.0.x packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Aug 18, 2013
1 parent 3827a51 commit 5493b6b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Everything else works just like the original Eloquent model. Read more about the
Query Builder
-------------

Once selected a mongodb connection, you can execute queries just like the original query builder. The main difference is that we are using `collection` instead of `table` (but table will work as well), and some additional operations like `push` and `pull`.
Once you have selected a mongodb connection, you can execute queries just like the original query builder. The main difference is that we are using `collection` instead of `table` (but table will work as well), and some additional operations like `push` and `pull`.

// With custom connection
$user = DB::connection('mongodb')->collection('users')->get();
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"license" : "MIT",
"require": {
"php": ">=5.3.0",
"illuminate/support": "~4.0",
"illuminate/database": "~4.0",
"illuminate/events": "~4.0"
"illuminate/support": "4.0.x",
"illuminate/database": "4.0.x",
"illuminate/events": "4.0.x"
},
"require-dev": {
"illuminate/cache": "~4.0"
"illuminate/cache": "4.0.x"
},
"autoload": {
"psr-0": {
Expand Down
22 changes: 12 additions & 10 deletions src/Jenssegers/Mongodb/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
*
* @var MongoCollection
*/
public $collection;
protected $collection;

/**
* All of the available operators.
Expand Down Expand Up @@ -495,7 +495,7 @@ protected function performUpdate($query)
*
* @return array
*/
private function compileWheres()
protected function compileWheres()
{
if (!$this->wheres) return array();

Expand All @@ -507,13 +507,15 @@ private function compileWheres()
// Convert id's
if (isset($where['column']) && $where['column'] == '_id')
{
// Multiple values
if (isset($where['values']))
{
foreach ($where['values'] as &$value)
{
$value = ($value instanceof MongoID) ? $value : new MongoID($value);
}
}
// Single value
else
{
$where['value'] = ($where['value'] instanceof MongoID) ? $where['value'] : new MongoID($where['value']);
Expand Down Expand Up @@ -544,7 +546,7 @@ private function compileWheres()
return $wheres;
}

private function compileWhereBasic($where)
protected function compileWhereBasic($where)
{
extract($where);

Expand Down Expand Up @@ -573,44 +575,44 @@ private function compileWhereBasic($where)
return $query;
}

private function compileWhereNested($where)
protected function compileWhereNested($where)
{
extract($where);

return $query->compileWheres();
}

private function compileWhereIn($where)
protected function compileWhereIn($where)
{
extract($where);

return array($column => array('$in' => $values));
}

private function compileWhereNotIn($where)
protected function compileWhereNotIn($where)
{
extract($where);

return array($column => array('$nin' => $values));
}

private function compileWhereNull($where)
protected function compileWhereNull($where)
{
$where['operator'] = '=';
$where['value'] = null;

return $this->compileWhereBasic($where);
}

private function compileWhereNotNull($where)
protected function compileWhereNotNull($where)
{
$where['operator'] = '!=';
$where['value'] = null;

return $this->compileWhereBasic($where);
}

private function compileWhereBetween($where)
protected function compileWhereBetween($where)
{
extract($where);

Expand All @@ -621,7 +623,7 @@ private function compileWhereBetween($where)
);
}

private function compileWhereRaw($where)
protected function compileWhereRaw($where)
{
return $where['sql'];
}
Expand Down
13 changes: 8 additions & 5 deletions src/Jenssegers/Mongodb/Relations/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
*/
public function addConstraints()
{
// For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent.
$key = $this->related->getKeyName();
if (static::$constraints)
{
// For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent.
$key = $this->related->getKeyName();

$this->query->where($key, '=', $this->parent->{$this->foreignKey});
$this->query->where($key, '=', $this->parent->{$this->foreignKey});
}
}

/**
Expand Down

0 comments on commit 5493b6b

Please sign in to comment.