Skip to content

Commit

Permalink
check for timestamps when creating pivot model from raw attributes as…
Browse files Browse the repository at this point in the history
… well (#23963)

fixes #23601
  • Loading branch information
luchaos authored and taylorotwell committed Apr 25, 2018
1 parent 128fcba commit fca815e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/Pivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public static function fromRawAttributes(Model $parent, $attributes, $table, $ex

$instance->setRawAttributes($attributes, true);

$instance->timestamps = $instance->hasTimestampAttributes();

return $instance;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Database/DatabaseEloquentPivotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]');
Expand Down

0 comments on commit fca815e

Please sign in to comment.