diff --git a/src/Illuminate/Database/Eloquent/Relations/Pivot.php b/src/Illuminate/Database/Eloquent/Relations/Pivot.php index 4782bc021779..5f7323ce47f7 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Pivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Pivot.php @@ -80,7 +80,7 @@ public static function fromAttributes(Model $parent, $attributes, $table, $exist */ public static function fromRawAttributes(Model $parent, $attributes, $table, $exists = false) { - $instance = static::fromAttributes($parent, $attributes, $table, $exists); + $instance = static::fromAttributes($parent, [], $table, $exists); $instance->setRawAttributes($attributes, true); diff --git a/tests/Database/DatabaseEloquentPivotTest.php b/tests/Database/DatabaseEloquentPivotTest.php index 570239df5a50..fefabe85b999 100755 --- a/tests/Database/DatabaseEloquentPivotTest.php +++ b/tests/Database/DatabaseEloquentPivotTest.php @@ -47,6 +47,16 @@ public function testFromRawAttributesDoesNotDoubleMutate() $this->assertEquals(['name' => 'Taylor'], $pivot->foo); } + public function testFromRawAttributesDoesNotMutate() + { + $parent = m::mock('Illuminate\Database\Eloquent\Model[getConnectionName]'); + $parent->shouldReceive('getConnectionName')->once()->andReturn('connection'); + + $pivot = DatabaseEloquentPivotTestMutatorStub::fromRawAttributes($parent, ['foo' => 'bar'], 'table', true); + + $this->assertFalse($pivot->getMutatorCalled()); + } + public function testPropertiesUnchangedAreNotDirty() { $parent = m::mock('Illuminate\Database\Eloquent\Model[getConnectionName]');