Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Rename the method whereNone to whereNotAny in the query builder #52383

Closed
57 changes: 44 additions & 13 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,7 @@ public function orWhereFullText($columns, $value, array $options = [])
/**
* Add a "where" clause to the query for multiple columns with "and" conditions between them.
*
* @param string[] $columns
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @param string $boolean
Expand All @@ -2262,8 +2262,8 @@ public function whereAll($columns, $operator = null, $value = null, $boolean = '
/**
* Add an "or where" clause to the query for multiple columns with "and" conditions between them.
*
* @param string[] $columns
* @param string $operator
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @return $this
*/
Expand All @@ -2275,8 +2275,8 @@ public function orWhereAll($columns, $operator = null, $value = null)
/**
* Add a "where" clause to the query for multiple columns with "or" conditions between them.
*
* @param string[] $columns
* @param string $operator
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return $this
Expand All @@ -2299,8 +2299,8 @@ public function whereAny($columns, $operator = null, $value = null, $boolean = '
/**
* Add an "or where" clause to the query for multiple columns with "or" conditions between them.
*
* @param string[] $columns
* @param string $operator
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @return $this
*/
Expand All @@ -2309,31 +2309,62 @@ public function orWhereAny($columns, $operator = null, $value = null)
return $this->whereAny($columns, $operator, $value, 'or');
}

/**
* Add a "where not" clause to the query for multiple columns with "or" conditions between them.
*
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return $this
*/
public function whereNotAny($columns, $operator = null, $value = null, $boolean = 'and')
{
return $this->whereAny($columns, $operator, $value, $boolean.' not');
}

/**
* Add an "or where not" clause to the query for multiple columns with "or" conditions between them.
*
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @return $this
*/
public function orWhereNotAny($columns, $operator = null, $value = null)
{
return $this->whereNotAny($columns, $operator, $value, 'or');
}

/**
* Add a "where not" clause to the query for multiple columns where none of the conditions should be true.
*
* @param string[] $columns
* @param string $operator
* @deprecated Will be removed in a future Laravel version. Use whereNotAny instead.
*
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return $this
*/
public function whereNone($columns, $operator = null, $value = null, $boolean = 'and')
{
return $this->whereAny($columns, $operator, $value, $boolean.' not');
return $this->whereNotAny($columns, $operator, $value, $boolean);
}

/**
* Add an "or where not" clause to the query for multiple columns where none of the conditions should be true.
*
* @param string[] $columns
* @param string $operator
* @deprecated Will be removed in a future Laravel version. Use orWhereNotAny instead.
*
* @param \Illuminate\Contracts\Database\Query\Expression[]|string[] $columns
* @param mixed $operator
* @param mixed $value
* @return $this
*/
public function orWhereNone($columns, $operator = null, $value = null)
{
return $this->whereNone($columns, $operator, $value, 'or');
return $this->orWhereNotAny($columns, $operator, $value);
}

/**
Expand Down
76 changes: 66 additions & 10 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,11 @@ public function testWhereAll()
$builder->select('*')->from('users')->whereAll(['last_name', 'email'], 'not like', '%Otwell%');
$this->assertSame('select * from "users" where ("last_name" not like ? and "email" not like ?)', $builder->toSql());
$this->assertEquals(['%Otwell%', '%Otwell%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->whereAll(['email_verified_at', 'deleted_at'], null);
$this->assertSame('select * from "users" where ("email_verified_at" is null and "deleted_at" is null)', $builder->toSql());
$this->assertEquals([], $builder->getBindings());
}

public function testOrWhereAll()
Expand All @@ -1343,6 +1348,11 @@ public function testOrWhereAll()
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->orWhereAll(['last_name', 'email'], '%Otwell%');
$this->assertSame('select * from "users" where "first_name" like ? or ("last_name" = ? and "email" = ?)', $builder->toSql());
$this->assertEquals(['%Taylor%', '%Otwell%', '%Otwell%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->whereAll(['email_verified_at', 'deleted_at'], null);
$this->assertSame('select * from "users" where ("email_verified_at" is null and "deleted_at" is null)', $builder->toSql());
$this->assertEquals([], $builder->getBindings());
}

public function testWhereAny()
Expand All @@ -1356,6 +1366,11 @@ public function testWhereAny()
$builder->select('*')->from('users')->whereAny(['last_name', 'email'], '%Otwell%');
$this->assertSame('select * from "users" where ("last_name" = ? or "email" = ?)', $builder->toSql());
$this->assertEquals(['%Otwell%', '%Otwell%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->whereAny(['email_verified_at', 'deleted_at'], null);
$this->assertSame('select * from "users" where ("email_verified_at" is null or "deleted_at" is null)', $builder->toSql());
$this->assertEquals([], $builder->getBindings());
}

public function testOrWhereAny()
Expand All @@ -1374,6 +1389,57 @@ public function testOrWhereAny()
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->orWhereAny(['last_name', 'email'], '%Otwell%');
$this->assertSame('select * from "users" where "first_name" like ? or ("last_name" = ? or "email" = ?)', $builder->toSql());
$this->assertEquals(['%Taylor%', '%Otwell%', '%Otwell%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->orWhereAny(['email_verified_at', 'deleted_at'], null);
$this->assertSame('select * from "users" where "first_name" like ? or ("email_verified_at" is null or "deleted_at" is null)', $builder->toSql());
$this->assertEquals(['%Taylor%'], $builder->getBindings());
}

public function testWhereNotAny()
{
$builder = $this->getBuilder();
$builder->select('*')->from('users')->whereNotAny(['last_name', 'email'], 'like', '%Otwell%');
$this->assertSame('select * from "users" where not ("last_name" like ? or "email" like ?)', $builder->toSql());
$this->assertEquals(['%Otwell%', '%Otwell%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->whereNotAny(['email_verified_at', 'deleted_at'], null);
$this->assertSame('select * from "users" where "first_name" like ? and not ("email_verified_at" is null or "deleted_at" is null)', $builder->toSql());
$this->assertEquals(['%Taylor%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->whereNotAny(['last_name', 'email'], 'like', '%Otwell%');
$this->assertSame('select * from "users" where "first_name" like ? and not ("last_name" like ? or "email" like ?)', $builder->toSql());
$this->assertEquals(['%Taylor%', '%Otwell%', '%Otwell%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->whereNotAny(['email_verified_at', 'deleted_at'], null);
$this->assertSame('select * from "users" where not ("email_verified_at" is null or "deleted_at" is null)', $builder->toSql());
$this->assertEquals([], $builder->getBindings());
}

public function testOrWhereNotAny()
{
$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->orWhereNotAny(['last_name', 'email'], 'like', '%Otwell%');
$this->assertSame('select * from "users" where "first_name" like ? or not ("last_name" like ? or "email" like ?)', $builder->toSql());
$this->assertEquals(['%Taylor%', '%Otwell%', '%Otwell%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->orWhereNotAny(['last_name', 'email'], '%Otwell%');
$this->assertSame('select * from "users" where "first_name" like ? or not ("last_name" = ? or "email" = ?)', $builder->toSql());
$this->assertEquals(['%Taylor%', '%Otwell%', '%Otwell%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->orWhereNotAny(['last_name', 'deleted_at'], null);
$this->assertSame('select * from "users" where "first_name" like ? or not ("last_name" is null or "deleted_at" is null)', $builder->toSql());
$this->assertEquals(['%Taylor%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->whereNotAny(['last_name', 'email'], 'like', '%Otwell%', 'or');
$this->assertSame('select * from "users" where "first_name" like ? or not ("last_name" like ? or "email" like ?)', $builder->toSql());
$this->assertEquals(['%Taylor%', '%Otwell%', '%Otwell%'], $builder->getBindings());
}

public function testWhereNone()
Expand All @@ -1387,11 +1453,6 @@ public function testWhereNone()
$builder->select('*')->from('users')->whereNone(['last_name', 'email'], 'Otwell');
$this->assertSame('select * from "users" where not ("last_name" = ? or "email" = ?)', $builder->toSql());
$this->assertEquals(['Otwell', 'Otwell'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->whereNone(['last_name', 'email'], 'like', '%Otwell%');
$this->assertSame('select * from "users" where "first_name" like ? and not ("last_name" like ? or "email" like ?)', $builder->toSql());
$this->assertEquals(['%Taylor%', '%Otwell%', '%Otwell%'], $builder->getBindings());
}

public function testOrWhereNone()
Expand All @@ -1405,11 +1466,6 @@ public function testOrWhereNone()
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->whereNone(['last_name', 'email'], 'like', '%Otwell%', 'or');
$this->assertSame('select * from "users" where "first_name" like ? or not ("last_name" like ? or "email" like ?)', $builder->toSql());
$this->assertEquals(['%Taylor%', '%Otwell%', '%Otwell%'], $builder->getBindings());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('first_name', 'like', '%Taylor%')->orWhereNone(['last_name', 'email'], '%Otwell%');
$this->assertSame('select * from "users" where "first_name" like ? or not ("last_name" = ? or "email" = ?)', $builder->toSql());
$this->assertEquals(['%Taylor%', '%Otwell%', '%Otwell%'], $builder->getBindings());
}

public function testUnions()
Expand Down