mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '4.7' into 4.8
This commit is contained in:
commit
9ccdb8efb2
@ -465,10 +465,9 @@ class DataQuery
|
|||||||
// statement anyway
|
// statement anyway
|
||||||
$statement = $this->getFinalisedQuery();
|
$statement = $this->getFinalisedQuery();
|
||||||
|
|
||||||
// Clear limit, distinct, and order as it's not relevant for an exists query
|
// Clear distinct, and order as it's not relevant for an exists query
|
||||||
$statement->setDistinct(false);
|
$statement->setDistinct(false);
|
||||||
$statement->setOrderBy(null);
|
$statement->setOrderBy(null);
|
||||||
$statement->setLimit(null);
|
|
||||||
|
|
||||||
// We can remove grouping if there's no "having" that might be relying on an aggregate
|
// We can remove grouping if there's no "having" that might be relying on an aggregate
|
||||||
// Additionally, the columns being selected no longer matter
|
// Additionally, the columns being selected no longer matter
|
||||||
|
@ -466,8 +466,50 @@ class DataQueryTest extends SapphireTest
|
|||||||
|
|
||||||
public function testExistsCreatesFunctionalQueries()
|
public function testExistsCreatesFunctionalQueries()
|
||||||
{
|
{
|
||||||
$this->assertTrue(ObjectE::get()->exists());
|
$this->assertTrue(
|
||||||
$this->assertFalse(ObjectE::get()->where(['"Title" = ?' => 'Foo'])->exists());
|
ObjectE::get()->exists(),
|
||||||
$this->assertTrue(ObjectE::get()->dataQuery()->groupby('"SortOrder"')->exists());
|
'Query for ObjectE exists because there\'s more than 1 record'
|
||||||
|
);
|
||||||
|
$this->assertFalse(
|
||||||
|
ObjectE::get()->where(['"Title" = ?' => 'Foo'])->exists(),
|
||||||
|
'Query for ObjectE with Title Foo does NOT exists because there\'s no matching record'
|
||||||
|
);
|
||||||
|
$this->assertTrue(
|
||||||
|
ObjectE::get()->dataQuery()->groupby('"SortOrder"')->exists(),
|
||||||
|
'Existence of query for ObjectE is not affected by group by'
|
||||||
|
);
|
||||||
|
$this->assertTrue(
|
||||||
|
ObjectE::get()->limit(1)->exists(),
|
||||||
|
'Existence of query for ObjectE is not affected by limit if records are returned'
|
||||||
|
);
|
||||||
|
$this->assertFalse(
|
||||||
|
ObjectE::get()->limit(4, 9999)->exists(),
|
||||||
|
'Existence of query for ObjectE is affected by limit if no records are returned'
|
||||||
|
);
|
||||||
|
|
||||||
|
$query = new DataQuery(ObjectE::class);
|
||||||
|
$this->assertTrue(
|
||||||
|
$query->exists(),
|
||||||
|
'exist returns true if query return results'
|
||||||
|
);
|
||||||
|
$query = new DataQuery(ObjectE::class);
|
||||||
|
$this->assertFalse(
|
||||||
|
$query->where(['"Title" = ?' => 'Foo'])->exists(),
|
||||||
|
'exist returns false if there\'s no results'
|
||||||
|
);
|
||||||
|
$query = new DataQuery(ObjectE::class);
|
||||||
|
$this->assertTrue(
|
||||||
|
$query->groupby('"SortOrder"')->exists(),
|
||||||
|
'exist is unaffected by group by'
|
||||||
|
);
|
||||||
|
$query = new DataQuery(ObjectE::class);
|
||||||
|
$this->assertTrue(
|
||||||
|
$query->limit(1)->exists(),
|
||||||
|
'exist is unaffected by limit as long as one recard is returned'
|
||||||
|
);
|
||||||
|
$this->assertFalse(
|
||||||
|
$query->limit(1, 9999)->exists(),
|
||||||
|
'exist is false when a limit returns no results'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user