Skip to content

Commit

Permalink
Allow models omitted by global scopes to be refreshed (#15282)
Browse files Browse the repository at this point in the history
  • Loading branch information
deefour authored and taylorotwell committed Sep 5, 2016
1 parent 1812e20 commit 95ac0eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public function fresh($with = [])

$key = $this->getKeyName();

return static::with($with)->where($key, $this->getKey())->first();
return static::newQueryWithoutScopes()->with($with)->where($key, $this->getKey())->first();
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Database/DatabaseEloquentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,13 @@ public function testRelationsArePreloadedInGlobalScope()
$this->assertCount(1, $result->getRelations());
}

public function testModelIgnoredByGlobalScopeCanBeRefreshed()
{
$user = EloquentTestUserWithOmittingGlobalScope::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']);

$this->assertNotNull($user->fresh());
}

public function testForPageAfterIdCorrectlyPaginates()
{
EloquentTestUser::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']);
Expand Down Expand Up @@ -978,6 +985,18 @@ public static function boot()
}
}

class EloquentTestUserWithOmittingGlobalScope extends EloquentTestUser
{
public static function boot()
{
parent::boot();

static::addGlobalScope(function ($builder) {
$builder->where('email', '!=', 'taylorotwell@gmail.com');
});
}
}

class EloquentTestPost extends Eloquent
{
protected $table = 'posts';
Expand Down

0 comments on commit 95ac0eb

Please sign in to comment.