Commit 71f8e4ac authored by Franz Liedke's avatar Franz Liedke

Fix a bug introduced in pull request #799 that caused eager loading constraints to stop working.

parent 1503aed7
...@@ -257,25 +257,38 @@ abstract class Model { ...@@ -257,25 +257,38 @@ abstract class Model {
{ {
$includes = (array) $includes; $includes = (array) $includes;
$all_includes = array(); $given_includes = array();
foreach($includes as $include) foreach ($includes as $relationship => $constraints)
{ {
$nested = explode('.', $include); // 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);
}
$given_includes[$relationship] = $constraints;
}
$inc = array(); $relationships = array_keys($given_includes);
$implicits = array();
foreach($nested as $relation) foreach ($relationships as $relationship)
{ {
$inc[] = $relation; $parts = explode('.', $relationship);
$all_includes[] = implode('.', $inc); $prefix = '';
foreach ($parts as $part)
{
$implicits[$prefix.$part] = null;
$prefix .= $part.'.';
} }
} }
//remove duplicates and reset the array keys. // Add all implicit includes to the explicit ones
$this->includes = array_values(array_unique($all_includes)); $this->includes = $given_includes + $implicits;
return $this; return $this;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment