From 6c42ff92161943a8f142980cbc3d2ee6a5dca7ec Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 31 May 2007 18:55:44 +0000 Subject: [PATCH] --- tests/Query/LimitTestCase.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/Query/LimitTestCase.php b/tests/Query/LimitTestCase.php index c45485c60..ba59de964 100644 --- a/tests/Query/LimitTestCase.php +++ b/tests/Query/LimitTestCase.php @@ -68,8 +68,9 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase $q->select('u.id, p.*')->from('User u, u.Phonenumber p')->limit(5); $sql = $q->getQuery(); + $this->assertEqual($q->getQuery(), - 'SELECT e.id AS e__id, p.id AS p__id, p.phonenumber AS p__phonenumber, p.entity_id AS p__entity_id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE e.id IN (SELECT DISTINCT e2.id FROM entity e2 WHERE (e2.type = 0) LIMIT 5) AND (e.type = 0)'); + 'SELECT e.id AS e__id, p.id AS p__id, p.phonenumber AS p__phonenumber, p.entity_id AS p__entity_id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE e.id IN (SELECT DISTINCT e2.id FROM entity e2 LEFT JOIN phonenumber p2 ON e2.id = p2.entity_id WHERE (e2.type = 0) LIMIT 5) AND (e.type = 0)'); $users = $q->execute(); $count = $this->dbh->count(); @@ -165,7 +166,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase $this->assertEqual($count, $this->dbh->count()); $this->assertEqual($q->getQuery(), - 'SELECT e.id AS e__id, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE e.id IN (SELECT DISTINCT e2.id FROM entity e2 WHERE e2.name = ? AND (e2.type = 0) LIMIT 5) AND e.name = ? AND (e.type = 0)'); + 'SELECT e.id AS e__id, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE e.id IN (SELECT DISTINCT e2.id FROM entity e2 LEFT JOIN phonenumber p2 ON e2.id = p2.entity_id WHERE e2.name = ? AND (e2.type = 0) LIMIT 5) AND e.name = ? AND (e.type = 0)'); $q = new Doctrine_Query(); $q->select('u.id, p.id')->from('User u LEFT JOIN u.Phonenumber p'); @@ -181,7 +182,10 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase $this->assertEqual($count, $this->dbh->count()); $this->assertEqual($q->getQuery(), - "SELECT e.id AS e__id, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE e.id IN (SELECT DISTINCT e2.id FROM entity e2 WHERE (e2.name LIKE ? OR e2.name LIKE ?) AND (e2.type = 0) LIMIT 5) AND (e.name LIKE ? OR e.name LIKE ?) AND (e.type = 0)"); + "SELECT e.id AS e__id, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON" + . " e.id = p.entity_id WHERE e.id IN (SELECT DISTINCT e2.id FROM entity e2 LEFT JOIN phonenumber p2" + . " ON e2.id = p2.entity_id WHERE (e2.name LIKE ? OR e2.name LIKE ?) AND (e2.type = 0) LIMIT 5) AND " + . "(e.name LIKE ? OR e.name LIKE ?) AND (e.type = 0)"); } public function testConnectionFlushing() @@ -278,7 +282,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase $this->connection->flush(); $q = new Doctrine_Query(); - $q->from("Photo")->where("Photo.Tag.id = ?")->orderby("Photo.id DESC")->limit(100); + $q->from('Photo')->where('Photo.Tag.id = ?')->orderby('Photo.id DESC')->limit(100); $photos = $q->execute(array(1)); $this->assertEqual($photos->count(), 3); @@ -286,5 +290,15 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase "SELECT p.id AS p__id, p.name AS p__name FROM photo p LEFT JOIN phototag p2 ON p.id = p2.photo_id LEFT JOIN tag t ON t.id = p2.tag_id WHERE p.id IN (SELECT DISTINCT p3.id FROM photo p3 LEFT JOIN phototag p4 ON p3.id = p4.photo_id LEFT JOIN tag t2 ON t2.id = p4.tag_id WHERE t2.id = ? ORDER BY p3.id DESC LIMIT 100) AND t.id = ? ORDER BY p.id DESC"); } + public function testLimitNoticesOrderbyJoins() + { + $q = new Doctrine_Query(); + + $q->from('Photo p') + ->leftJoin('p.Tag t') + ->orderby('t.id DESC')->limit(10); + + $this->assertEqual($q->getSql(), "SELECT p.id AS p__id, p.name AS p__name, t.id AS t__id, t.tag AS t__tag FROM photo p LEFT JOIN phototag p2 ON p.id = p2.photo_id LEFT JOIN tag t ON t.id = p2.tag_id WHERE p.id IN (SELECT DISTINCT p3.id FROM photo p3 LEFT JOIN phototag p4 ON p3.id = p4.photo_id LEFT JOIN tag t2 ON t2.id = p4.tag_id ORDER BY t2.id DESC LIMIT 10) ORDER BY t.id DESC"); + } } ?>