diff --git a/src/Illuminate/Database/Eloquent/Relations/Pivot.php b/src/Illuminate/Database/Eloquent/Relations/Pivot.php index 5f7323ce47f7..f6950956c624 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Pivot.php +++ b/src/Illuminate/Database/Eloquent/Relations/Pivot.php @@ -84,6 +84,8 @@ public static function fromRawAttributes(Model $parent, $attributes, $table, $ex $instance->setRawAttributes($attributes, true); + $instance->timestamps = $instance->hasTimestampAttributes(); + return $instance; } diff --git a/tests/Database/DatabaseEloquentPivotTest.php b/tests/Database/DatabaseEloquentPivotTest.php index fefabe85b999..6490b81b1bdc 100755 --- a/tests/Database/DatabaseEloquentPivotTest.php +++ b/tests/Database/DatabaseEloquentPivotTest.php @@ -88,6 +88,14 @@ public function testTimestampPropertyIsSetIfCreatedAtInAttributes() $this->assertFalse($pivot->timestamps); } + public function testTimestampPropertyIsTrueWhenCreatingFromRawAttributes() + { + $parent = m::mock('Illuminate\Database\Eloquent\Model[getConnectionName,getDates]'); + $parent->shouldReceive('getConnectionName')->andReturn('connection'); + $pivot = Pivot::fromRawAttributes($parent, ['foo' => 'bar', 'created_at' => 'foo'], 'table'); + $this->assertTrue($pivot->timestamps); + } + public function testKeysCanBeSetProperly() { $parent = m::mock('Illuminate\Database\Eloquent\Model[getConnectionName]');