From 1fd421d09e885ddac9b4ff3471048a7f327c6cbb Mon Sep 17 00:00:00 2001 From: doctrine Date: Sun, 18 Jun 2006 22:45:54 +0000 Subject: [PATCH] Bug fix : Composite delete with aliases, Bug fix : DQL column aggregation inheritance to ANSI SQL compliant --- Doctrine/{Form.class.php => Form.php} | 0 Doctrine/Query.php | 11 ++++++++--- Doctrine/Session.php | 2 +- tests/QueryTestCase.php | 7 ++++--- tests/run.php | 3 ++- 5 files changed, 15 insertions(+), 8 deletions(-) rename Doctrine/{Form.class.php => Form.php} (100%) diff --git a/Doctrine/Form.class.php b/Doctrine/Form.php similarity index 100% rename from Doctrine/Form.class.php rename to Doctrine/Form.php diff --git a/Doctrine/Query.php b/Doctrine/Query.php index 4cd775b59..17e128d4a 100644 --- a/Doctrine/Query.php +++ b/Doctrine/Query.php @@ -381,19 +381,24 @@ class Doctrine_Query extends Doctrine_Access { $str = ""; $c = array(); + $index = 0; foreach($array as $tname => $maps) { $a = array(); foreach($maps as $map) { $b = array(); foreach($map as $field => $value) { - $b[] = $tname.".$field = $value"; //OR $tname.$field IS NULL"; + if($index > 0) + $b[] = "(".$tname.".$field = $value OR $tname.$field IS NULL)"; + else + $b[] = $tname.".$field = $value"; } if( ! empty($b)) $a[] = implode(" AND ",$b); } - if( ! empty($a)) $c[] = implode(" || ",$a); + if( ! empty($a)) $c[] = implode(" AND ",$a); + $index++; } - $str .= implode(" || ",$c); + $str .= implode(" AND ",$c); $this->addWhere($str); $this->inheritanceApplied = true; diff --git a/Doctrine/Session.php b/Doctrine/Session.php index 25f1a8827..04afe1ea3 100644 --- a/Doctrine/Session.php +++ b/Doctrine/Session.php @@ -855,7 +855,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab switch($fk->getType()): case Doctrine_Relation::ONE_COMPOSITE: case Doctrine_Relation::MANY_COMPOSITE: - $obj = $record->get($fk->getTable()->getComponentName()); + $obj = $record->get($record->getTable()->getAlias($fk->getTable()->getComponentName())); $obj->delete(); break; endswitch; diff --git a/tests/QueryTestCase.php b/tests/QueryTestCase.php index 072b16192..6f6f137fe 100644 --- a/tests/QueryTestCase.php +++ b/tests/QueryTestCase.php @@ -86,8 +86,9 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { $this->session->flush(); $users = $query->query("FROM User-b WHERE User.Group.name = 'Action Actors'"); + $this->assertEqual(trim($query->getQuery()), - "SELECT entity.id AS User__id FROM entity LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id WHERE (entity2.name = 'Action Actors') AND (entity.type = 0 || entity2.type = 1)"); + "SELECT entity.id AS User__id FROM entity LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id WHERE (entity2.name = 'Action Actors') AND (entity.type = 0 AND (entity2.type = 1 OR entity2.type IS NULL))"); $this->assertTrue($users instanceof Doctrine_Collection); $this->assertEqual($users->count(),1); @@ -96,7 +97,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { $users = $query->query("FROM User-b WHERE User.Group.Phonenumber.phonenumber LIKE '123 123'"); $this->assertEqual(trim($query->getQuery()), - "SELECT entity.id AS User__id FROM entity LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id LEFT JOIN phonenumber ON entity2.id = phonenumber.entity_id WHERE (phonenumber.phonenumber LIKE '123 123') AND (entity.type = 0 || entity2.type = 1)"); + "SELECT entity.id AS User__id FROM entity LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id LEFT JOIN phonenumber ON entity2.id = phonenumber.entity_id WHERE (phonenumber.phonenumber LIKE '123 123') AND (entity.type = 0 AND (entity2.type = 1 OR entity2.type IS NULL))"); $this->assertTrue($users instanceof Doctrine_Collection); $this->assertEqual($users->count(),1); @@ -112,7 +113,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { $this->assertEqual($count, $this->dbh->count()); } - public function testNestedManyToManyRelations() { $task = new Task(); $task->name = "T1"; @@ -973,5 +973,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { //$this->assertTrue(isset($values['max'])); } + } ?> diff --git a/tests/run.php b/tests/run.php index 7deedf89d..5e8540738 100644 --- a/tests/run.php +++ b/tests/run.php @@ -50,9 +50,10 @@ $test->addTestCase(new Doctrine_PessimisticLockingTestCase()); $test->addTestCase(new Doctrine_ViewTestCase()); +$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase()); + $test->addTestCase(new Doctrine_QueryTestCase()); -$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_SqliteTestCase());