fixed belongs_to eager loading bug.

This commit is contained in:
Taylor Otwell 2011-08-18 22:25:56 -05:00
parent 5895f36bbb
commit 03b58e8ec6
1 changed files with 6 additions and 4 deletions

View File

@ -66,13 +66,15 @@ private static function base($class, $results)
*/ */
private static function eagerly($eloquent, &$parents, $include) private static function eagerly($eloquent, &$parents, $include)
{ {
// We temporarily spoof the belongs_to key to allow the query to be fetched without // We temporarily spoof the query attributes to allow the query to be fetched without
// any problems, since the belongs_to method actually gets the attribute. // any problems, since the belongs_to method actually gets the related attribute.
$eloquent->attributes[$spoof = $include.'_id'] = 0; $first = reset($parents);
$eloquent->attributes = $first->attributes;
$relationship = $eloquent->$include(); $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. // 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. // This will allow us to load a range of related models instead of only one.