Ticket #1326 (closed defect: worksforme)
delete() on an empty query deletes all records but does not return the number of deleted rows
| Reported by: | francois | Owned by: | romanb |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | Query/Hydration | Version: | 1.0.0 |
| Severity: | Keywords: | ||
| Cc: | Has Test: | no | |
| Status: | Pending Core Response | Has Patch: | no |
Description
It seems that delete() called on an empty Doctrine_Query does the deletion of all records but does not return the number of affected rows. Here is a test case:
function createTestData()
{
// Reinitialize all
Doctrine_Query::create()->delete()->from('Article')->execute();
$article1 = new Article();
$article1->setTitle('foo2');
$article1->save();
$article2 = new Article();
$article2->setTitle('foo3');
$article2->save();
}
// Create test data and check count
createTestData();
echo Doctrine_Query::create()->from('Article')->count();
=> 2
// Delete all with no WHERE clause
$nbDeleted = Doctrine_Query::create()->
delete()->
from('Article')->
execute();
echo $nbDeleted
=> 0 // WRONG
// check count
echo Doctrine_Query::create()->from('Article')->count();
=> 0 // But everything is deleted, as requested
// Create test data and check count
createTestData();
echo Doctrine_Query::create()->from('Article')->count();
=> 2
// Delete some with one WHERE clause
$nbDeleted = Doctrine_Query::create()->
delete()->
from('Article')->
where('Title = ?', array('foo2'))->
execute();
echo $nbDeleted
=> 1 // OK
// check count
echo Doctrine_Query::create()->from('Article')->count();
=> 1 // OK
// Create test data and check count
createTestData();
echo Doctrine_Query::create()->from('Article')->count();
=> 2
// Delete all with one always true WHERE clause
$nbDeleted = Doctrine_Query::create()->
delete()->
from('Article')->
where('1 = 1')->
execute();
echo $nbDeleted
=> 2 // OK
// check count
echo Doctrine_Query::create()->from('Article')->count();
=> 0 // OK
Change History
Note: See
TracTickets for help on using
tickets.