Skip to content

Commit e6f1a57

Browse files
committed
Merge branch 'develop'
2 parents aa01769 + 51b3234 commit e6f1a57

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
"license" : "MIT",
1212
"require": {
1313
"php": ">=5.3.0",
14-
"illuminate/support": "4.0.x",
15-
"illuminate/database": "4.0.x",
16-
"illuminate/events": "4.0.x"
14+
"illuminate/support": "4.1.x",
15+
"illuminate/database": "4.1.x",
16+
"illuminate/events": "4.1.x"
1717
},
1818
"require-dev": {
19-
"illuminate/cache": "4.0.x",
20-
"illuminate/auth": "4.0.x"
19+
"illuminate/cache": "4.1.x",
20+
"illuminate/auth": "4.1.x"
2121
},
2222
"autoload": {
2323
"psr-0": {

src/Jenssegers/Mongodb/Model.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,23 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
204204
* Define a many-to-many relationship.
205205
*
206206
* @param string $related
207-
* @param string $table
207+
* @param string $collection
208208
* @param string $foreignKey
209209
* @param string $otherKey
210+
* @param string $relation
210211
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
211212
*/
212-
public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null)
213+
public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null, $relation = null)
213214
{
214-
$caller = $this->getBelongsToManyCaller();
215+
// If no relationship name was passed, we will pull backtraces to get the
216+
// name of the calling function. We will use that function name as the
217+
// title of this relation since that is a great convention to apply.
218+
if (is_null($relation))
219+
{
220+
$caller = $this->getBelongsToManyCaller();
221+
222+
$name = $caller['function'];
223+
}
215224

216225
// First, we'll need to determine the foreign key and "other key" for the
217226
// relationship. Once we have determined the keys we'll make the query
@@ -235,7 +244,7 @@ public function belongsToMany($related, $collection = null, $foreignKey = null,
235244
// appropriate query constraint and entirely manages the hydrations.
236245
$query = $instance->newQuery();
237246

238-
return new BelongsToMany($query, $this, $collection, $foreignKey, $otherKey, $caller['function']);
247+
return new BelongsToMany($query, $this, $collection, $foreignKey, $otherKey, $relation);
239248
}
240249

241250
/**

src/Jenssegers/Mongodb/Relations/BelongsTo.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
44

55
/**
6-
* Set the base constraints on the relation query.
7-
*
8-
* @return void
9-
*/
6+
* Set the base constraints on the relation query.
7+
*
8+
* @return void
9+
*/
1010
public function addConstraints()
1111
{
1212
if (static::$constraints)
1313
{
1414
// For belongs to relationships, which are essentially the inverse of has one
1515
// or has many relationships, we need to actually query on the primary key
1616
// of the related models matching on the foreign key that's on a parent.
17-
$key = $this->related->getKeyName();
17+
$table = $this->related->getTable();
1818

19-
$this->query->where($key, '=', $this->parent->{$this->foreignKey});
19+
$this->query->where($this->otherKey, '=', $this->parent->{$this->foreignKey});
2020
}
2121
}
2222

@@ -31,9 +31,9 @@ public function addEagerConstraints(array $models)
3131
// We'll grab the primary key name of the related models since it could be set to
3232
// a non-standard name and not "id". We will then construct the constraint for
3333
// our eagerly loading query so it returns the proper models from execution.
34-
$key = $this->related->getKeyName();
34+
$key = $this->otherKey;
3535

3636
$this->query->whereIn($key, $this->getEagerModelKeys($models));
3737
}
3838

39-
}
39+
}

tests/QueryBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,10 @@ public function testDistinct()
265265
));
266266

267267
$items = DB::collection('items')->distinct('name')->get();
268-
$this->assertEquals(array('knife', 'fork', 'spoon'), $items);
268+
$this->assertEquals(3, count($items));
269269

270270
$types = DB::collection('items')->distinct('type')->get();
271-
$this->assertEquals(array('sharp', 'round'), $types);
271+
$this->assertEquals(2, count($types));
272272
}
273273

274274
public function testCustomId()

0 commit comments

Comments
 (0)