Fix Eloquent eager loading matching.
This commit is contained in:
@@ -66,12 +66,11 @@ class Query {
|
||||
* Get all of the model results for the query.
|
||||
*
|
||||
* @param array $columns
|
||||
* @param bool $keyed
|
||||
* @return array
|
||||
*/
|
||||
public function get($columns = array('*'), $keyed = true)
|
||||
public function get($columns = array('*'))
|
||||
{
|
||||
return $this->hydrate($this->model, $this->table->get($columns), $keyed);
|
||||
return $this->hydrate($this->model, $this->table->get($columns));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,10 +99,9 @@ class Query {
|
||||
*
|
||||
* @param Model $model
|
||||
* @param array $results
|
||||
* @param bool $keyed
|
||||
* @return array
|
||||
*/
|
||||
public function hydrate($model, $results, $keyed = true)
|
||||
public function hydrate($model, $results)
|
||||
{
|
||||
$class = get_class($model);
|
||||
|
||||
@@ -128,17 +126,7 @@ class Query {
|
||||
|
||||
$new->original = $new->attributes;
|
||||
|
||||
// Typically, the resulting models are keyed by their primary key, but it
|
||||
// may be useful to not do this in some circumstances such as when we
|
||||
// are eager loading a *-to-* relationships which has duplicates.
|
||||
if ($keyed)
|
||||
{
|
||||
$models[$result[$this->model->key()]] = $new;
|
||||
}
|
||||
else
|
||||
{
|
||||
$models[] = $new;
|
||||
}
|
||||
$models[] = $new;
|
||||
}
|
||||
|
||||
if (count($results) > 0)
|
||||
@@ -199,17 +187,7 @@ class Query {
|
||||
|
||||
$query->initialize($results, $relationship);
|
||||
|
||||
// If we're eager loading a many-to-many relationship we will disable
|
||||
// the primary key indexing on the hydration since there could be
|
||||
// roles shared across users and we don't want to overwrite.
|
||||
if ( ! $query instanceof Has_Many_And_Belongs_To)
|
||||
{
|
||||
$query->match($relationship, $results, $query->get());
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->match($relationship, $results, $query->get(array('*'), false));
|
||||
}
|
||||
$query->match($relationship, $results, $query->get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user