Skip to content

Commit

Permalink
Remove attribute filling from pivot model
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Mar 6, 2018
1 parent 49770ec commit a738129
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Relations/Pivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

This comment has been minimized.

Copy link
@luchaos

luchaos Apr 19, 2018

Contributor

this breaks Pivot::hasTimestampAttributes() detecting that the model has timestamps when supplying the $using parameter in Model::newPivot() as that check only happens in Pivot::fromAttributes() and raw attributes are populated afterwards.
I was wondering why suddenly my pivot tables, that are updated through a custom Pivot Model, won't update their timestamps anymore.

This comment has been minimized.

Copy link
@staudenmeir

staudenmeir Apr 22, 2018

Author Contributor

Sorry, I missed that.

This comment has been minimized.

Copy link
@luchaos

luchaos Apr 22, 2018

Contributor

no worries! your patch was more important than this. i stated a pull request to fix this comparably minor issue.
#23963


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

Expand Down
13 changes: 3 additions & 10 deletions tests/Database/DatabaseEloquentPivotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public function testMutatorsAreCalledFromConstructor()
$this->assertTrue($pivot->getMutatorCalled());
}

public function testFromRawAttributesDoesNotDoubleMutate()
public function testFromRawAttributesDoesNotMutate()
{
$parent = m::mock('Illuminate\Database\Eloquent\Model[getConnectionName]');
$parent->shouldReceive('getConnectionName')->once()->andReturn('connection');

$pivot = DatabaseEloquentPivotTestJsonCastStub::fromRawAttributes($parent, ['foo' => json_encode(['name' => 'Taylor'])], 'table', true);
$pivot = DatabaseEloquentPivotTestMutatorStub::fromRawAttributes($parent, ['foo' => 'bar'], 'table', true);

$this->assertEquals(['name' => 'Taylor'], $pivot->foo);
$this->assertFalse($pivot->getMutatorCalled());
}

public function testPropertiesUnchangedAreNotDirty()
Expand Down Expand Up @@ -135,10 +135,3 @@ public function getMutatorCalled()
return $this->mutatorCalled;
}
}

class DatabaseEloquentPivotTestJsonCastStub extends \Illuminate\Database\Eloquent\Relations\Pivot
{
protected $casts = [
'foo' => 'json',
];
}

0 comments on commit a738129

Please sign in to comment.