Commit 37fd54b8 authored by Taylor Otwell's avatar Taylor Otwell

Merge pull request #448 from danielboendergaard/patch-1

Fixed problem with Eloquent2 pivot tables
parents 158bc32c 3639d2c4
...@@ -290,20 +290,18 @@ class Has_Many_And_Belongs_To extends Relationship { ...@@ -290,20 +290,18 @@ class Has_Many_And_Belongs_To extends Relationship {
// the pivot table that may need to be accessed by the developer. // the pivot table that may need to be accessed by the developer.
$pivot = new Pivot($this->joining); $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 // 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 // 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. // from the model since it actually belongs to the pivot.
foreach ($attributes as $key => $value) foreach ($result->attributes as $key => $value)
{
if (starts_with($key, 'pivot_'))
{ {
$pivot->{substr($key, 6)} = $value; $pivot->{substr($key, 6)} = $value;
$result->purge($key); $result->purge($key);
} }
}
// Once we have completed hydrating the pivot model instance, we'll set // Once we have completed hydrating the pivot model instance, we'll set
// it on the result model's relationships array so the developer can // it on the result model's relationships array so the developer can
......
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