1
0
mirror of synced 2024-12-14 07:06:04 +03:00

Fixed DDC-1057

This commit is contained in:
Fabio B. Silva 2011-12-07 11:23:15 -02:00
parent eaec259186
commit df19e68a86
2 changed files with 65 additions and 3 deletions

View File

@ -120,6 +120,7 @@ class ResultSetMapping
* results or joined entity results within this ResultSetMapping.
* @param string $resultAlias The result alias with which the entity result should be
* placed in the result structure.
* @return ResultSetMapping This ResultSetMapping instance.
*
* @todo Rename: addRootEntity
*/
@ -131,6 +132,8 @@ class ResultSetMapping
if ($resultAlias !== null) {
$this->isMixed = true;
}
return $this;
}
/**
@ -141,13 +144,16 @@ class ResultSetMapping
* @param string $alias The alias of the entity result or joined entity result the discriminator
* column should be used for.
* @param string $discrColumn The name of the discriminator column in the SQL result set.
*
* @return ResultSetMapping This ResultSetMapping instance.
*
* @todo Rename: addDiscriminatorColumn
*/
public function setDiscriminatorColumn($alias, $discrColumn)
{
$this->discriminatorColumns[$alias] = $discrColumn;
$this->columnOwnerMap[$discrColumn] = $alias;
return $this;
}
/**
@ -155,6 +161,7 @@ class ResultSetMapping
*
* @param string $alias The alias of an entity result or joined entity result.
* @param string $fieldName The name of the field to use for indexing.
* @return ResultSetMapping This ResultSetMapping instance.
*/
public function addIndexBy($alias, $fieldName)
{
@ -168,6 +175,8 @@ class ResultSetMapping
break;
}
return $this;
/* TODO: check if this exception can be put back, for now it's gone because of assumptions made by some ORM internals
if ( ! $found) {
@ -186,11 +195,13 @@ class ResultSetMapping
* Set to index by a scalar result column name
*
* @param $resultColumnName
* @return void
* @return ResultSetMapping This ResultSetMapping instance.
*/
public function addIndexByScalar($resultColumnName)
{
$this->indexByMap['scalars'] = $resultColumnName;
return $this;
}
/**
@ -198,11 +209,13 @@ class ResultSetMapping
*
* @param $alias
* @param $resultColumnName
* @return void
* @return ResultSetMapping This ResultSetMapping instance.
*/
public function addIndexByColumn($alias, $resultColumnName)
{
$this->indexByMap[$alias] = $resultColumnName;
return $this;
}
/**
@ -242,6 +255,7 @@ class ResultSetMapping
* the field $fieldName is defined on a subclass, specify that here.
* If not specified, the field is assumed to belong to the class
* designated by $alias.
* @return ResultSetMapping This ResultSetMapping instance.
* @todo Rename: addField
*/
public function addFieldResult($alias, $columnName, $fieldName, $declaringClass = null)
@ -256,6 +270,8 @@ class ResultSetMapping
if ( ! $this->isMixed && $this->scalarMappings) {
$this->isMixed = true;
}
return $this;
}
/**
@ -265,6 +281,7 @@ class ResultSetMapping
* @param string $alias The unique alias to use for the joined entity.
* @param string $parentAlias The alias of the entity result that is the parent of this joined result.
* @param object $relation The association field that connects the parent entity result with the joined entity result.
* @return ResultSetMapping This ResultSetMapping instance.
* @todo Rename: addJoinedEntity
*/
public function addJoinedEntityResult($class, $alias, $parentAlias, $relation)
@ -272,6 +289,8 @@ class ResultSetMapping
$this->aliasMap[$alias] = $class;
$this->parentAliasMap[$alias] = $parentAlias;
$this->relationMap[$alias] = $relation;
return $this;
}
/**
@ -279,6 +298,7 @@ class ResultSetMapping
*
* @param string $columnName The name of the column in the SQL result set.
* @param string $alias The result alias with which the scalar result should be placed in the result structure.
* @return ResultSetMapping This ResultSetMapping instance.
* @todo Rename: addScalar
*/
public function addScalarResult($columnName, $alias)
@ -288,6 +308,8 @@ class ResultSetMapping
if ( ! $this->isMixed && $this->fieldMappings) {
$this->isMixed = true;
}
return $this;
}
/**
@ -439,6 +461,7 @@ class ResultSetMapping
* @param string $columnName
* @param string $fieldName
* @param bool
* @return ResultSetMapping This ResultSetMapping instance.
*/
public function addMetaResult($alias, $columnName, $fieldName, $isIdentifierColumn = false)
{
@ -448,5 +471,7 @@ class ResultSetMapping
if ($isIdentifierColumn) {
$this->isIdentifierColumn[$alias][$columnName] = true;
}
return $this;
}
}

View File

@ -14,7 +14,14 @@ require_once __DIR__ . '/../../TestInit.php';
*/
class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase
{
/**
* @var ResultSetMapping
*/
private $_rsm;
/**
* @var \Doctrine\ORM\EntityManager
*/
private $_em;
protected function setUp() {
@ -56,5 +63,35 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('username', $this->_rsm->getFieldName('username'));
$this->assertEquals('name', $this->_rsm->getFieldName('name'));
}
/**
* @group DDC-1057
*
* Fluent interface test, not a real result set mapping
*/
public function testFluentInterface()
{
$rms = $this->_rsm;
$rms->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser','u')
->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsPhonenumber','p','u','phonenumbers')
->addFieldResult('u', 'id', 'id')
->addFieldResult('u', 'name', 'name')
->setDiscriminatorColumn('name', 'name')
->addIndexByColumn('id', 'id')
->addIndexBy('username', 'username')
->addIndexByScalar('sclr0')
->addScalarResult('sclr0', 'numPhones')
->addMetaResult('a', 'user_id', 'user_id');
$this->assertTrue($rms->hasIndexBy('id'));
$this->assertTrue($rms->isFieldResult('id'));
$this->assertTrue($rms->isFieldResult('name'));
$this->assertTrue($rms->isScalarResult('sclr0'));
$this->assertTrue($rms->isRelation('p'));
$this->assertTrue($rms->hasParentAlias('p'));
$this->assertTrue($rms->isMixedResult());
}
}