Skip to content

Commit

Permalink
Fix morphTo
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Dec 20, 2015
1 parent a1769cf commit c9e0739
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
Expand Up @@ -185,7 +185,7 @@ public function morphTo($name = null, $type = null, $id = null)
// use that to get both the class and foreign key that will be utilized.
if (is_null($name))
{
list($current, $caller) = debug_backtrace(false, 2);
list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);

$name = Str::snake($caller['function']);
}
Expand Down
19 changes: 19 additions & 0 deletions src/Jenssegers/Mongodb/Relations/MorphTo.php
Expand Up @@ -18,4 +18,23 @@ public function addConstraints()
}
}

/**
* Get all of the relation results for a type.
*
* @param string $type
* @return \Illuminate\Database\Eloquent\Collection
*/
protected function getResultsByType($type)
{
$instance = $this->createModelByType($type);

$key = $instance->getKeyName();

$query = $instance->newQuery();

$query = $this->useWithTrashed($query);

return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get();
}

}
1 change: 1 addition & 0 deletions test.php
@@ -0,0 +1 @@
<?php require 'vendor/autoload.php';

0 comments on commit c9e0739

Please sign in to comment.