diff --git a/laravel/database/eloquent/model.php b/laravel/database/eloquent/model.php index ccdd42d5..32c504c5 100644 --- a/laravel/database/eloquent/model.php +++ b/laravel/database/eloquent/model.php @@ -257,26 +257,21 @@ abstract class Model { { $includes = (array) $includes; - $all_includes = array(); + $this->includes = array(); - foreach($includes as $include) + foreach ($includes as $relationship => $constraints) { - $nested = explode('.', $include); - - $inc = array(); - - foreach($nested as $relation) + // When eager loading relationships, constraints may be set on the eager + // load definition; however, is none are set, we need to swap the key + // and the value of the array since there are no constraints. + if (is_numeric($relationship)) { - $inc[] = $relation; - - $all_includes[] = implode('.', $inc); + list($relationship, $constraints) = array($constraints, null); } + $this->includes[$relationship] = $constraints; } - //remove duplicates and reset the array keys. - $this->includes = array_values(array_unique($all_includes)); - return $this; } diff --git a/laravel/database/eloquent/query.php b/laravel/database/eloquent/query.php index 3aee79c9..56fd15c7 100644 --- a/laravel/database/eloquent/query.php +++ b/laravel/database/eloquent/query.php @@ -217,22 +217,23 @@ class Query { */ protected function model_includes() { - $includes = array(); + $relationships = array_keys($this->model->includes); + $implicits = array(); - foreach ($this->model->includes as $relationship => $constraints) + foreach ($relationships as $relationship) { - // When eager loading relationships, constraints may be set on the eager - // load definition; however, is none are set, we need to swap the key - // and the value of the array since there are no constraints. - if (is_numeric($relationship)) - { - list($relationship, $constraints) = array($constraints, null); - } + $parts = explode('.', $relationship); - $includes[$relationship] = $constraints; + $prefix = ''; + foreach ($parts as $part) + { + $implicits[$prefix.$part] = NULL; + $prefix .= $part.'.'; + } } - return $includes; + // Add all implicit includes to the explicit ones + return $this->model->includes + $implicits; } /**