Skip to content

Commit

Permalink
Rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Jun 19, 2019
1 parent 35eb06a commit 599b81e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
32 changes: 16 additions & 16 deletions src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', C
}

if ($relation instanceof MorphTo) {
throw new RuntimeException('Please use whereHasPolymorphic() for MorphTo relationships.');
throw new RuntimeException('Please use whereHasMorph() for MorphTo relationships.');
}

// If we only need to check for the existence of the relation, then we can optimize
Expand Down Expand Up @@ -195,7 +195,7 @@ public function orWhereDoesntHave($relation, Closure $callback = null)
* @param \Closure|null $callback
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function hasPolymorphic($relation, $types, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null)
public function hasMorph($relation, $types, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null)
{
$relation = $this->getRelationWithoutConstraints($relation);

Expand Down Expand Up @@ -246,9 +246,9 @@ protected function getBelongsToRelation(MorphTo $relation, $type)
* @param int $count
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function orHasPolymorphic($relation, $types, $operator = '>=', $count = 1)
public function orHasMorph($relation, $types, $operator = '>=', $count = 1)
{
return $this->hasPolymorphic($relation, $types, $operator, $count, 'or');
return $this->hasMorph($relation, $types, $operator, $count, 'or');
}

/**
Expand All @@ -260,9 +260,9 @@ public function orHasPolymorphic($relation, $types, $operator = '>=', $count = 1
* @param \Closure|null $callback
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function doesntHavePolymorphic($relation, $types, $boolean = 'and', Closure $callback = null)
public function doesntHaveMorph($relation, $types, $boolean = 'and', Closure $callback = null)
{
return $this->hasPolymorphic($relation, $types, '<', 1, $boolean, $callback);
return $this->hasMorph($relation, $types, '<', 1, $boolean, $callback);
}

/**
Expand All @@ -272,9 +272,9 @@ public function doesntHavePolymorphic($relation, $types, $boolean = 'and', Closu
* @param string|array $types
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function orDoesntHavePolymorphic($relation, $types)
public function orDoesntHaveMorph($relation, $types)
{
return $this->doesntHavePolymorphic($relation, $types, 'or');
return $this->doesntHaveMorph($relation, $types, 'or');
}

/**
Expand All @@ -287,9 +287,9 @@ public function orDoesntHavePolymorphic($relation, $types)
* @param int $count
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function whereHasPolymorphic($relation, $types, Closure $callback = null, $operator = '>=', $count = 1)
public function whereHasMorph($relation, $types, Closure $callback = null, $operator = '>=', $count = 1)
{
return $this->hasPolymorphic($relation, $types, $operator, $count, 'and', $callback);
return $this->hasMorph($relation, $types, $operator, $count, 'and', $callback);
}

/**
Expand All @@ -302,9 +302,9 @@ public function whereHasPolymorphic($relation, $types, Closure $callback = null,
* @param int $count
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function orWhereHasPolymorphic($relation, $types, Closure $callback = null, $operator = '>=', $count = 1)
public function orWhereHasMorph($relation, $types, Closure $callback = null, $operator = '>=', $count = 1)
{
return $this->hasPolymorphic($relation, $types, $operator, $count, 'or', $callback);
return $this->hasMorph($relation, $types, $operator, $count, 'or', $callback);
}

/**
Expand All @@ -315,9 +315,9 @@ public function orWhereHasPolymorphic($relation, $types, Closure $callback = nul
* @param \Closure|null $callback
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function whereDoesntHavePolymorphic($relation, $types, Closure $callback = null)
public function whereDoesntHaveMorph($relation, $types, Closure $callback = null)
{
return $this->doesntHavePolymorphic($relation, $types, 'and', $callback);
return $this->doesntHaveMorph($relation, $types, 'and', $callback);
}

/**
Expand All @@ -328,9 +328,9 @@ public function whereDoesntHavePolymorphic($relation, $types, Closure $callback
* @param \Closure $callback
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function orWhereDoesntHavePolymorphic($relation, $types, Closure $callback = null)
public function orWhereDoesntHaveMorph($relation, $types, Closure $callback = null)
{
return $this->doesntHavePolymorphic($relation, $types, 'or', $callback);
return $this->doesntHaveMorph($relation, $types, 'or', $callback);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Illuminate\Tests\Integration\Database\EloquentWhereHasPolymorphicTest;
namespace Illuminate\Tests\Integration\Database\EloquentWhereHasMorphTest;

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -13,7 +13,7 @@
/**
* @group integration
*/
class EloquentWhereHasPolymorphicTest extends DatabaseTestCase
class EloquentWhereHasMorphTest extends DatabaseTestCase
{
protected function setUp(): void
{
Expand Down Expand Up @@ -52,36 +52,36 @@ protected function setUp(): void
}
}

public function testWhereHasPolymorphic()
public function testWhereHasMorph()
{
$comments = Comment::whereHasPolymorphic('commentable', [Post::class, Video::class], function (Builder $query) {
$comments = Comment::whereHasMorph('commentable', [Post::class, Video::class], function (Builder $query) {
$query->where('title', 'foo');
})->get();

$this->assertEquals([1, 4], $comments->pluck('id')->all());
}

public function testWhereHasPolymorphicWithWildcard()
public function testWhereHasMorphWithWildcard()
{
// Test newModelQuery() without global scopes.
Comment::where('commentable_type', Video::class)->delete();

$comments = Comment::withTrashed()
->whereHasPolymorphic('commentable', '*', function (Builder $query) {
->whereHasMorph('commentable', '*', function (Builder $query) {
$query->where('title', 'foo');
})->get();

$this->assertEquals([1, 4], $comments->pluck('id')->all());
}

public function testWhereHasPolymorphicWithMorphMap()
public function testWhereHasMorphWithMorphMap()
{
Relation::morphMap(['posts' => Post::class]);

Comment::where('commentable_type', Post::class)->update(['commentable_type' => 'posts']);

try {
$comments = Comment::whereHasPolymorphic('commentable', ['posts', Video::class], function (Builder $query) {
$comments = Comment::whereHasMorph('commentable', ['posts', Video::class], function (Builder $query) {
$query->where('title', 'foo');
})->get();

Expand All @@ -91,16 +91,16 @@ public function testWhereHasPolymorphicWithMorphMap()
}
}

public function testWhereHasPolymorphicWithConstraint()
public function testWhereHasMorphWithConstraint()
{
$comments = Comment::whereHasPolymorphic('commentableWithConstraint', Video::class, function (Builder $query) {
$comments = Comment::whereHasMorph('commentableWithConstraint', Video::class, function (Builder $query) {
$query->where('title', 'like', 'ba%');
})->get();

$this->assertEquals([5], $comments->pluck('id')->all());
}

public function testWhereHasPolymorphicWithOwnerKey()
public function testWhereHasMorphWithOwnerKey()
{
Schema::table('posts', function (Blueprint $table) {
$table->string('slug')->nullable();
Expand All @@ -114,64 +114,64 @@ public function testWhereHasPolymorphicWithOwnerKey()

Comment::where('id', 1)->update(['commentable_id' => 'foo']);

$comments = Comment::whereHasPolymorphic('commentableWithOwnerKey', Post::class, function (Builder $query) {
$comments = Comment::whereHasMorph('commentableWithOwnerKey', Post::class, function (Builder $query) {
$query->where('title', 'foo');
})->get();

$this->assertEquals([1], $comments->pluck('id')->all());
}

public function testHasPolymorphic()
public function testHasMorph()
{
$comments = Comment::hasPolymorphic('commentable', Post::class)->get();
$comments = Comment::hasMorph('commentable', Post::class)->get();

$this->assertEquals([1, 2], $comments->pluck('id')->all());
}

public function testOrHasPolymorphic()
public function testOrHasMorph()
{
$comments = Comment::where('id', 1)->orHasPolymorphic('commentable', Video::class)->get();
$comments = Comment::where('id', 1)->orHasMorph('commentable', Video::class)->get();

$this->assertEquals([1, 4, 5, 6], $comments->pluck('id')->all());
}

public function testDoesntHavePolymorphic()
public function testDoesntHaveMorph()
{
$comments = Comment::doesntHavePolymorphic('commentable', Post::class)->get();
$comments = Comment::doesntHaveMorph('commentable', Post::class)->get();

$this->assertEquals([3], $comments->pluck('id')->all());
}

public function testOrDoesntHavePolymorphic()
public function testOrDoesntHaveMorph()
{
$comments = Comment::where('id', 1)->orDoesntHavePolymorphic('commentable', Post::class)->get();
$comments = Comment::where('id', 1)->orDoesntHaveMorph('commentable', Post::class)->get();

$this->assertEquals([1, 3], $comments->pluck('id')->all());
}

public function testOrWhereHasPolymorphic()
public function testOrWhereHasMorph()
{
$comments = Comment::where('id', 1)
->orWhereHasPolymorphic('commentable', Video::class, function (Builder $query) {
->orWhereHasMorph('commentable', Video::class, function (Builder $query) {
$query->where('title', 'foo');
})->get();

$this->assertEquals([1, 4], $comments->pluck('id')->all());
}

public function testWhereDoesntHavePolymorphic()
public function testWhereDoesntHaveMorph()
{
$comments = Comment::whereDoesntHavePolymorphic('commentable', Post::class, function (Builder $query) {
$comments = Comment::whereDoesntHaveMorph('commentable', Post::class, function (Builder $query) {
$query->where('title', 'foo');
})->get();

$this->assertEquals([2, 3], $comments->pluck('id')->all());
}

public function testOrWhereDoesntHavePolymorphic()
public function testOrWhereDoesntHaveMorph()
{
$comments = Comment::where('id', 1)
->orWhereDoesntHavePolymorphic('commentable', Post::class, function (Builder $query) {
->orWhereDoesntHaveMorph('commentable', Post::class, function (Builder $query) {
$query->where('title', 'foo');
})->get();

Expand Down

0 comments on commit 599b81e

Please sign in to comment.