Commit acced2b9 authored by zYne's avatar zYne

DQL Limit now works with normal many-to-many relations as well as many-to-many...

DQL Limit now works with normal many-to-many relations as well as many-to-many relations using column aggregation inheritance
parent 7ca53970
......@@ -642,7 +642,10 @@ class Doctrine_Query extends Doctrine_Hydrate {
$asf = $fk->getAssociationFactory();
$assocTableName = $asf->getTableName();
if( ! $loadFields) {
$this->subqueryAliases[] = $assocTableName;
}
$this->parts["join"][$tname][$assocTableName] = $join.$assocTableName." ON ".$tname.".id = ".$assocTableName.".".$fk->getLocal();
$this->parts["join"][$tname][$tname2] = $join.$aliasString." ON ".$tname2.".id = ".$assocTableName.".".$fk->getForeign();
}
......
<?php
class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
public function prepareTables() {
$this->tables[] = "Photo";
$this->tables[] = "Tag";
$this->tables[] = "Phototag";
parent::prepareTables();
}
public function testLimitWithOneToOneLeftJoin() {
$q = new Doctrine_Query($this->session);
$q->from('User(id).Email')->limit(5);
......@@ -144,7 +150,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
$this->session->flush();
}
public function testLimitWithManyToManyLeftJoin() {
public function testLimitWithManyToManyColumnAggInheritanceLeftJoin() {
$q = new Doctrine_Query($this->session);
$q->from("User.Group")->limit(5);
$users = $q->execute();
......@@ -183,7 +189,27 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($users->count(), 3);
}
public function testLimitWithNormalManyToMany() {
$coll = new Doctrine_Collection($this->session->getTable("Photo"));
$tag = new Tag();
$tag->tag = "Some tag";
$coll[0]->Tag[0] = $tag;
$coll[0]->name = "photo 1";
$coll[1]->Tag[0] = $tag;
$coll[1]->name = "photo 2";
$coll[2]->Tag[0] = $tag;
$coll[2]->name = "photo 3";
$coll[3]->Tag[0]->tag = "Other tag";
$coll[3]->name = "photo 4";
$this->session->flush();
$q = new Doctrine_Query();
$q->from("Photo")->where("Photo.Tag.id = ?")->orderby("Photo.id DESC")->limit(100);
$photos = $q->execute(array(1));
$this->assertEqual($photos->count(), 3);
$this->assertEqual($q->getQuery(),
"SELECT photo.id AS photo__id, photo.name AS photo__name FROM photo LEFT JOIN phototag ON photo.id = phototag.photo_id LEFT JOIN tag ON tag.id = phototag.tag_id WHERE photo.id IN (SELECT DISTINCT photo.id FROM photo LEFT JOIN phototag ON photo.id = phototag.photo_id LEFT JOIN tag ON tag.id = phototag.tag_id WHERE tag.id = ? LIMIT 100) AND tag.id = ? ORDER BY photo.id DESC");
}
}
?>
......@@ -386,4 +386,30 @@ class Validator_Test extends Doctrine_Record {
$this->hasColumn("myemail2", "string", 100, "email|notblank");
}
}
class Tag extends Doctrine_Record {
public function setUp() {
$this->hasMany("Photo", "Phototag.photo_id");
}
public function setTableDefinition() {
$this->hasColumn("tag", "string", 100);
}
}
class Photo extends Doctrine_Record {
public function setUp() {
$this->hasMany("Tag", "Phototag.tag_id");
}
public function setTableDefinition() {
$this->hasColumn("name", "string", 100);
}
}
class Phototag extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("photo_id", "integer");
$this->hasColumn("tag_id", "integer");
}
}
?>
......@@ -28,7 +28,7 @@ require_once("QueryLimitTestCase.php");
error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests");
/**
$test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_SessionTestCase());
......@@ -66,7 +66,7 @@ $test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_QueryTestCase());
$test->addTestCase(new Doctrine_RawSql_TestCase());
*/
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment