Tests for covering the Doctrine_Collection::loadRelated functionality for basic many-to-many relations
This commit is contained in:
parent
1d4a59b772
commit
c5e4f366d4
@ -288,12 +288,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
} elseif($this->relation instanceof Doctrine_Association) {
|
} elseif($this->relation instanceof Doctrine_Association) {
|
||||||
|
|
||||||
$asf = $this->relation->getAssociationFactory();
|
$asf = $this->relation->getAssociationFactory();
|
||||||
$query = "SELECT ".$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented();
|
$query = 'SELECT '.$foreign." FROM ".$asf->getTableName()." WHERE ".$local."=".$this->getIncremented();
|
||||||
|
|
||||||
$table = $fk->getTable();
|
$table = $fk->getTable();
|
||||||
$graph = new Doctrine_Query($table->getConnection());
|
$graph = new Doctrine_Query($table->getConnection());
|
||||||
|
|
||||||
$q = "FROM ".$table->getComponentName()." WHERE ".$table->getComponentName().".".$table->getIdentifier()." IN ($query)";
|
$q = 'FROM ' . $table->getComponentName() . ' WHERE ' . $table->getComponentName() . '.' . $table->getIdentifier()." IN ($query)";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
|
class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
|
||||||
|
public function testLoadRelatedForNormalAssociation() {
|
||||||
|
$resource = new Doctrine_Collection('Resource');
|
||||||
|
$resource[0]->name = 'resource 1';
|
||||||
|
$resource[0]->Type[0]->type = 'type 1';
|
||||||
|
$resource[0]->Type[1]->type = 'type 2';
|
||||||
|
$resource[1]->name = 'resource 2';
|
||||||
|
$resource[1]->Type[0]->type = 'type 3';
|
||||||
|
$resource[1]->Type[1]->type = 'type 4';
|
||||||
|
|
||||||
|
$resource->save();
|
||||||
|
|
||||||
|
$this->connection->clear();
|
||||||
|
|
||||||
|
$resources = $this->connection->query('FROM Resource');
|
||||||
|
|
||||||
|
$count = $this->dbh->count();
|
||||||
|
$resources->loadRelated('Type');
|
||||||
|
|
||||||
|
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||||
|
$this->assertEqual($resources[0]->name, 'resource 1');
|
||||||
|
$this->assertEqual($resource[0]->Type[0]->type, 'type 1');
|
||||||
|
$this->assertEqual($resource[0]->Type[1]->type, 'type 2');
|
||||||
|
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||||
|
|
||||||
|
$this->assertEqual($resource[1]->name, 'resource 2');
|
||||||
|
$this->assertEqual($resource[1]->Type[0]->type, 'type 3');
|
||||||
|
$this->assertEqual($resource[1]->Type[1]->type, 'type 4');
|
||||||
|
$this->assertEqual(($count + 1), $this->dbh->count());
|
||||||
|
}
|
||||||
public function testAdd() {
|
public function testAdd() {
|
||||||
$coll = new Doctrine_Collection($this->objTable);
|
$coll = new Doctrine_Collection($this->objTable);
|
||||||
$coll->add(new User());
|
$coll->add(new User());
|
||||||
|
@ -147,7 +147,7 @@ class Task extends Doctrine_Record {
|
|||||||
|
|
||||||
class Resource extends Doctrine_Record {
|
class Resource extends Doctrine_Record {
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->hasMany("Task as TaskAlias","Assignment.task_id");
|
$this->hasMany("Task as TaskAlias", "Assignment.task_id");
|
||||||
$this->hasMany("ResourceType as Type", "ResourceReference.type_id");
|
$this->hasMany("ResourceType as Type", "ResourceReference.type_id");
|
||||||
}
|
}
|
||||||
public function setTableDefinition() {
|
public function setTableDefinition() {
|
||||||
|
@ -62,7 +62,7 @@ $test->addTestCase(new Doctrine_Filter_TestCase());
|
|||||||
|
|
||||||
$test->addTestCase(new Doctrine_ValueHolder_TestCase());
|
$test->addTestCase(new Doctrine_ValueHolder_TestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_ValidatorTestCase());
|
$test->addTestCase(new Doctrine_ValidatorTestCase());
|
||||||
|
|
||||||
$test->addTestCase(new Doctrine_QueryTestCase());
|
$test->addTestCase(new Doctrine_QueryTestCase());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user