Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function match(array $models, Collection $results, $relation)
// link them up with their children using the keyed dictionary to make the
// matching very convenient and easy work. Then we'll just return them.
foreach ($models as $model) {
if (isset($dictionary[$key = $model->getKey()])) {
if (isset($dictionary[$key = $model->getAttribute($this->localKey)])) {
$model->setRelation(
$relation, $this->related->newCollection($dictionary[$key])
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ public function testItLoadsARelationWithCustomIntermediateAndLocalKey()
$this->assertCount(2, $posts);
}

public function testEagerLoadingARelationWithCustomIntermediateAndLocalKey()
{
$this->seedData();
$posts = HasManyThroughIntermediateTestCountry::with('posts')->first()->posts;

$this->assertEquals('A title', $posts[0]->title);
$this->assertCount(2, $posts);
}

/**
* @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
* @expectedExceptionMessage No query results for model [Illuminate\Tests\Database\HasManyThroughTestPost].
Expand Down