new model now supports DQL DELETEs and UPDATEs
This commit is contained in:
parent
44809328f0
commit
4289bdd9ab
@ -162,7 +162,7 @@ class Doctrine_Hydrate2
|
||||
}
|
||||
$this->parts[$name][] = $part;
|
||||
}
|
||||
public function getDeclaration($name)
|
||||
public function getDeclaration($name)
|
||||
{
|
||||
if ( ! isset($this->_aliasMap[$name])) {
|
||||
throw new Doctrine_Hydrate_Exception('Unknown component alias ' . $name);
|
||||
@ -174,8 +174,13 @@ class Doctrine_Hydrate2
|
||||
{
|
||||
if ( ! isset($this->parts[$name])) {
|
||||
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name);
|
||||
}
|
||||
|
||||
if ($name !== 'limit' && $name !== 'offset') {
|
||||
$this->parts[$name] = array($part);
|
||||
} else {
|
||||
$this->parts[$name] = $part;
|
||||
}
|
||||
$this->parts[$name] = array($part);
|
||||
}
|
||||
/**
|
||||
* copyAliases
|
||||
@ -249,16 +254,17 @@ class Doctrine_Hydrate2
|
||||
{
|
||||
$this->tables = array();
|
||||
$this->parts = array(
|
||||
"select" => array(),
|
||||
"from" => array(),
|
||||
"join" => array(),
|
||||
"where" => array(),
|
||||
"groupby" => array(),
|
||||
"having" => array(),
|
||||
"orderby" => array(),
|
||||
"limit" => false,
|
||||
"offset" => false,
|
||||
);
|
||||
'select' => array(),
|
||||
'from' => array(),
|
||||
'set' => array(),
|
||||
'join' => array(),
|
||||
'where' => array(),
|
||||
'groupby' => array(),
|
||||
'having' => array(),
|
||||
'orderby' => array(),
|
||||
'limit' => false,
|
||||
'offset' => false,
|
||||
);
|
||||
$this->inheritanceApplied = false;
|
||||
$this->tableAliases = array();
|
||||
$this->aliasHandler->clear();
|
||||
|
@ -1144,6 +1144,17 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
|
||||
|
||||
return $this->getParser('from')->parse($update);
|
||||
}
|
||||
/**
|
||||
* set
|
||||
* sets the SET part of the query
|
||||
*
|
||||
* @param string $update DQL UPDATE part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
return $this->getParser('set')->parse($key . ' = ' . $value);
|
||||
}
|
||||
/**
|
||||
* from
|
||||
* sets the FROM part of the query
|
||||
|
@ -35,13 +35,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
public function testDeleteAllWithColumnAggregationInheritance()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->parseQuery('DELETE FROM User');
|
||||
|
||||
$this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 0)');
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->delete()->from('User');
|
||||
|
||||
@ -49,13 +49,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
public function testDeleteAll()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->parseQuery('DELETE FROM Entity');
|
||||
|
||||
$this->assertEqual($q->getQuery(), 'DELETE FROM entity');
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->delete()->from('Entity');
|
||||
|
||||
@ -63,13 +63,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
public function testDeleteWithCondition()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->parseQuery('DELETE FROM Entity WHERE id = 3');
|
||||
|
||||
$this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE id = 3');
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->delete()->from('Entity')->where('id = 3');
|
||||
|
||||
@ -77,13 +77,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
public function testDeleteWithLimit()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->parseQuery('DELETE FROM Entity LIMIT 20');
|
||||
|
||||
$this->assertEqual($q->getQuery(), 'DELETE FROM entity LIMIT 20');
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->delete()->from('Entity')->limit(20);
|
||||
|
||||
@ -91,13 +91,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
public function testDeleteWithLimitAndOffset()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->parseQuery('DELETE FROM Entity LIMIT 10 OFFSET 20');
|
||||
|
||||
$this->assertEqual($q->getQuery(), 'DELETE FROM entity LIMIT 10 OFFSET 20');
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->delete()->from('Entity')->limit(10)->offset(20);
|
||||
|
||||
|
@ -35,13 +35,13 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
public function testUpdateAllWithColumnAggregationInheritance()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->parseQuery("UPDATE User u SET u.name = 'someone'");
|
||||
|
||||
$this->assertEqual($q->getQuery(), "UPDATE entity SET name = 'someone' WHERE (type = 0)");
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->update('User u')->set('u.name', "'someone'");
|
||||
|
||||
@ -49,13 +49,13 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
public function testUpdateWorksWithMultipleColumns()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->parseQuery("UPDATE User u SET u.name = 'someone', u.email_id = 5");
|
||||
|
||||
$this->assertEqual($q->getQuery(), "UPDATE entity SET name = 'someone', email_id = 5 WHERE (type = 0)");
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->update('User u')->set('u.name', "'someone'")->set('u.email_id', 5);
|
||||
|
||||
@ -63,7 +63,7 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
public function testUpdateSupportsConditions()
|
||||
{
|
||||
$q = new Doctrine_Query();
|
||||
$q = new Doctrine_Query2();
|
||||
|
||||
$q->parseQuery("UPDATE User u SET u.name = 'someone' WHERE u.id = 5");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user