ORM: Subqueries IN and NOT

This commit is contained in:
yuri
2017-04-26 16:32:24 +03:00
parent 2202b00600
commit 5eaeabe231
4 changed files with 118 additions and 4 deletions
+53
View File
@@ -224,6 +224,59 @@ class QueryTest extends PHPUnit_Framework_TestCase
$this->assertEquals($expectedSql, $sql);
}
public function testSelectWithSubquery()
{
$sql = $this->query->createSelectQuery('Post', array(
'select' => ['id', 'name'],
'whereClause' => array(
'post.id=s' => array(
'entityType' => 'Post',
'selectParams' => array(
'select' => ['id'],
'whereClause' => array(
'name' => 'test'
)
)
)
)
));
$expectedSql = "SELECT post.id AS `id`, post.name AS `name` FROM `post` WHERE post.id IN (SELECT post.id AS `id` FROM `post` WHERE post.name = 'test' AND post.deleted = '0') AND post.deleted = '0'";
$this->assertEquals($expectedSql, $sql);
$sql = $this->query->createSelectQuery('Post', array(
'select' => ['id', 'name'],
'whereClause' => array(
'post.id!=s' => array(
'entityType' => 'Post',
'selectParams' => array(
'select' => ['id'],
'whereClause' => array(
'name' => 'test'
)
)
)
)
));
$expectedSql = "SELECT post.id AS `id`, post.name AS `name` FROM `post` WHERE post.id NOT IN (SELECT post.id AS `id` FROM `post` WHERE post.name = 'test' AND post.deleted = '0') AND post.deleted = '0'";
$this->assertEquals($expectedSql, $sql);
$sql = $this->query->createSelectQuery('Post', array(
'select' => ['id', 'name'],
'whereClause' => array(
'NOT'=> array(
'name' => 'test',
'post.createdById' => '1'
)
)
));
$expectedSql = "SELECT post.id AS `id`, post.name AS `name` FROM `post` WHERE post.id NOT IN (SELECT post.id AS `id` FROM `post` WHERE post.name = 'test' AND post.created_by_id = '1' AND post.deleted = '0') AND post.deleted = '0'";
$this->assertEquals($expectedSql, $sql);
}
public function testOrderBy()
{
$sql = $this->query->createSelectQuery('Comment', array(