Skip to content

Commit

Permalink
syncOriginal on refresh (#21905)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickomeara authored and taylorotwell committed Nov 1, 2017
1 parent e2d178c commit f1584bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,8 @@ public function refresh()

$this->load(collect($this->relations)->except('pivot')->keys()->toArray());

$this->syncOriginal();

return $this;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Integration/Database/EloquentModelRefreshTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ public function it_refreshes_a_soft_deleted_model()

$this->assertTrue($post->trashed());
}

/**
* @test
*/
public function it_syncs_original_on_refresh()
{
$post = Post::create(['title' => 'pat']);

Post::find($post->id)->update(['title' => 'patrick']);

$post->refresh();

$this->assertEmpty($post->getDirty());

$this->assertEquals('patrick', $post->getOriginal('title'));
}
}

class Post extends Model
Expand Down

0 comments on commit f1584bf

Please sign in to comment.