Skip to content

Commit

Permalink
Fixed pivot model hydration loading in Eloquent2
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bondergaard <danielboendergard@gmail.com>
  • Loading branch information
Daniel Bondergaard committed Mar 26, 2012
1 parent 263d614 commit 3639d2c
Showing 1 changed file with 6 additions and 8 deletions.
Expand Up @@ -290,19 +290,17 @@ protected function hydrate_pivot(&$results)
// the pivot table that may need to be accessed by the developer.
$pivot = new Pivot($this->joining);

$attributes = array_filter($result->attributes, function($attribute)
{
return starts_with($attribute, 'pivot_');
});

// If the attribute key starts with "pivot_", we know this is a column on
// the pivot table, so we will move it to the Pivot model and purge it
// from the model since it actually belongs to the pivot.
foreach ($attributes as $key => $value)
foreach ($result->attributes as $key => $value)
{
$pivot->{substr($key, 6)} = $value;
if (starts_with($key, 'pivot_'))
{
$pivot->{substr($key, 6)} = $value;

$result->purge($key);
$result->purge($key);
}
}

// Once we have completed hydrating the pivot model instance, we'll set
Expand Down

0 comments on commit 3639d2c

Please sign in to comment.