DQL: Multiple related component fetching
This commit is contained in:
parent
5d67e0aaed
commit
95434d723b
@ -254,8 +254,11 @@ class Doctrine_Query extends Doctrine_Access {
|
||||
}
|
||||
$q .= implode(", ",$a);
|
||||
|
||||
if( ! empty($this->parts['join']))
|
||||
$q .= " ".implode(' ', $this->parts["join"]);
|
||||
if( ! empty($this->parts['join'])) {
|
||||
foreach($this->parts['join'] as $part) {
|
||||
$q .= " ".implode(' ', $part);
|
||||
}
|
||||
}
|
||||
|
||||
$this->applyInheritance();
|
||||
if( ! empty($this->parts["where"]))
|
||||
@ -931,10 +934,10 @@ class Doctrine_Query extends Doctrine_Access {
|
||||
|
||||
switch($mark):
|
||||
case ":":
|
||||
$this->parts["join"][$tname] = "INNER JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
|
||||
$this->parts["join"][$tname][] = "INNER JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
|
||||
break;
|
||||
case ".":
|
||||
$this->parts["join"][$tname] = "LEFT JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
|
||||
$this->parts["join"][$tname][] = "LEFT JOIN ".$tname2." ON ".$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
|
||||
break;
|
||||
endswitch;
|
||||
|
||||
|
@ -8,6 +8,73 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
||||
parent::prepareTables();
|
||||
}
|
||||
|
||||
public function testMultipleFetching() {
|
||||
$count = $this->dbh->count();
|
||||
$this->session->getTable('User')->clear();
|
||||
$this->session->getTable('Email')->clear();
|
||||
$this->session->getTable('Phonenumber')->clear();
|
||||
|
||||
$users = $this->query->from("User-l.Phonenumber-i, User-l:Email-i")->execute();
|
||||
$this->assertEqual(($count + 1),$this->dbh->count());
|
||||
$this->assertEqual(count($users), 8);
|
||||
|
||||
$this->assertEqual($users[0]->Phonenumber->count(), 1);
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
$this->assertEqual($users[0]->Phonenumber[0]->phonenumber, "123 123");
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
|
||||
$this->assertEqual($users[1]->Phonenumber->count(), 3);
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
$this->assertEqual($users[1]->Phonenumber[0]->phonenumber, "123 123");
|
||||
$this->assertEqual($users[1]->Phonenumber[1]->phonenumber, "456 456");
|
||||
$this->assertEqual($users[1]->Phonenumber[2]->phonenumber, "789 789");
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
|
||||
$this->assertEqual($users[7]->Phonenumber->count(), 1);
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
$this->assertEqual($users[7]->Phonenumber[0]->phonenumber, "111 567 333");
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
|
||||
$this->assertTrue($users[0]->Email instanceof Email);
|
||||
$this->assertEqual($users[0]->Email->address, "zYne@example.com");
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
$this->assertEqual($users[0]->email_id, $users[0]->Email->id);
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
|
||||
$this->assertTrue($users[1]->Email instanceof Email);
|
||||
$this->assertEqual($users[1]->Email->address, "arnold@example.com");
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
$this->assertEqual($users[1]->email_id, $users[1]->Email->id);
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
}
|
||||
|
||||
public function testForeignKeyRelationFetching() {
|
||||
$count = $this->dbh->count();
|
||||
$users = $this->query->from("User-l.Phonenumber-i")->execute();
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
$this->assertEqual(count($users), 8);
|
||||
|
||||
$this->assertEqual($users[0]->Phonenumber->count(), 1);
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
$this->assertEqual($users[0]->Phonenumber[0]->phonenumber, "123 123");
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
|
||||
$this->assertEqual($users[1]->Phonenumber->count(), 3);
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
$this->assertEqual($users[1]->Phonenumber[0]->phonenumber, "123 123");
|
||||
$this->assertEqual($users[1]->Phonenumber[1]->phonenumber, "456 456");
|
||||
$this->assertEqual($users[1]->Phonenumber[2]->phonenumber, "789 789");
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
|
||||
$this->assertEqual($users[7]->Phonenumber->count(), 1);
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
$this->assertEqual($users[7]->Phonenumber[0]->phonenumber, "111 567 333");
|
||||
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||
|
||||
$this->assertEqual($users[0]->name, "zYne");
|
||||
$this->assertEqual(($count + 2), $this->dbh->count());
|
||||
}
|
||||
|
||||
public function testOneToOneRelationFetching() {
|
||||
|
||||
$count = $this->dbh->count();
|
||||
@ -345,7 +412,8 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
||||
//$this->assertEqual($users[0]->Group[2]->name, "Terminators");
|
||||
//$this->assertEqual(count($users[0]->Group), 3);
|
||||
|
||||
$this->clearCache();
|
||||
$this->session->getTable("User")->clear();
|
||||
$this->session->getTable("Phonenumber")->clear();
|
||||
|
||||
$users = $query->query("FROM User-b.Phonenumber-l WHERE User.Phonenumber.phonenumber LIKE '%123%'");
|
||||
$this->assertEqual(trim($query->getQuery()),
|
||||
@ -449,6 +517,5 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
||||
//$this->assertTrue(isset($values['max']));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
@ -23,7 +23,7 @@ error_reporting(E_ALL);
|
||||
$test = new GroupTest("Doctrine Framework Unit Tests");
|
||||
|
||||
//$test->addTestCase(new Sensei_UnitTestCase());
|
||||
|
||||
/**
|
||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_SessionTestCase());
|
||||
@ -45,7 +45,7 @@ $test->addTestCase(new Doctrine_ConfigurableTestCase());
|
||||
$test->addTestCase(new Doctrine_Collection_OffsetTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_CollectionTestCase());
|
||||
|
||||
*/
|
||||
$test->addTestCase(new Doctrine_QueryTestCase());
|
||||
|
||||
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
||||
|
Loading…
x
Reference in New Issue
Block a user