Commit 03b58e8e authored by Taylor Otwell's avatar Taylor Otwell

fixed belongs_to eager loading bug.

parent 5895f36b
......@@ -66,13 +66,15 @@ class Hydrator {
*/
private static function eagerly($eloquent, &$parents, $include)
{
// We temporarily spoof the belongs_to key to allow the query to be fetched without
// any problems, since the belongs_to method actually gets the attribute.
$eloquent->attributes[$spoof = $include.'_id'] = 0;
// We temporarily spoof the query attributes to allow the query to be fetched without
// any problems, since the belongs_to method actually gets the related attribute.
$first = reset($parents);
$eloquent->attributes = $first->attributes;
$relationship = $eloquent->$include();
unset($eloquent->attributes[$spoof]);
$eloquent->attributes = array();
// Reset the WHERE clause and bindings on the query. We'll add our own WHERE clause soon.
// This will allow us to load a range of related models instead of only one.
......
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