From 3639d2c46f31283604820e3d72ffdb15748cfdaf Mon Sep 17 00:00:00 2001 From: Daniel Bondergaard Date: Mon, 26 Mar 2012 14:17:49 +0200 Subject: [PATCH] Fixed pivot model hydration loading in Eloquent2 Signed-off-by: Daniel Bondergaard --- .../relationships/has_many_and_belongs_to.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php index d21cfac8..225f7eb8 100644 --- a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php +++ b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php @@ -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