collect new object parameters
This commit is contained in:
parent
0e60c50c5e
commit
ed89695a8c
3 changed files with 76 additions and 3 deletions
|
@ -118,6 +118,11 @@ class ResultSetMapping
|
||||||
*/
|
*/
|
||||||
public $isIdentifierColumn = array();
|
public $isIdentifierColumn = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array Maps column names in the result set to field names for each new object expression.
|
||||||
|
*/
|
||||||
|
public $newObjectMappings = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an entity result to this ResultSetMapping.
|
* Adds an entity result to this ResultSetMapping.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1222,9 +1222,16 @@ class SqlWalker implements TreeWalker
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ($expr instanceof AST\NewObjectExpression):
|
case ($expr instanceof AST\NewObjectExpression):
|
||||||
$sqlSelectExpressions = array_filter(array_map(array($this, 'walkSelectExpression'), $expr->args));
|
$sqlSelectExpressions = array();
|
||||||
$sql .= implode(', ', $sqlSelectExpressions);
|
$this->_rsm->newObjectMappings['className'] = $expr->className;
|
||||||
|
|
||||||
|
foreach ($expr->args as $e) {
|
||||||
|
$resultAliasMap = $this->scalarResultAliasMap;
|
||||||
|
$sqlSelectExpressions[] = $this->walkSelectExpression($e);
|
||||||
|
$this->_rsm->newObjectMappings['resultAliasMap'][] = array_diff($this->scalarResultAliasMap, $resultAliasMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= implode(', ', $sqlSelectExpressions);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -780,4 +780,65 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[2]);
|
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $users[2]);
|
||||||
$this->assertNull($users[3]);
|
$this->assertNull($users[3]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1574
|
||||||
|
*/
|
||||||
|
public function testSupportsNewOperator()
|
||||||
|
{
|
||||||
|
$u1 = new CmsUser;
|
||||||
|
$u2 = new CmsUser;
|
||||||
|
$u3 = new CmsUser;
|
||||||
|
|
||||||
|
$u1->setEmail(new \Doctrine\Tests\Models\CMS\CmsEmail());
|
||||||
|
$u1->setAddress(new \Doctrine\Tests\Models\CMS\CmsAddress());
|
||||||
|
|
||||||
|
$u2->setEmail(new \Doctrine\Tests\Models\CMS\CmsEmail());
|
||||||
|
$u2->setAddress(new \Doctrine\Tests\Models\CMS\CmsAddress());
|
||||||
|
|
||||||
|
$u3->setEmail(new \Doctrine\Tests\Models\CMS\CmsEmail());
|
||||||
|
$u3->setAddress(new \Doctrine\Tests\Models\CMS\CmsAddress());
|
||||||
|
|
||||||
|
$u1->name = 'Test 1';
|
||||||
|
$u1->username = '1test';
|
||||||
|
$u1->status = 'developer';
|
||||||
|
$u1->email->email = 'email@test1.com';
|
||||||
|
$u1->address->zip = '111111111';
|
||||||
|
$u1->address->city = 'Some City 1';
|
||||||
|
$u1->address->country = 'Some Country 2';
|
||||||
|
|
||||||
|
$u2->name = 'Test 2';
|
||||||
|
$u2->username = '2test';
|
||||||
|
$u2->status = 'developer';
|
||||||
|
$u2->email->email = 'email@test2.com';
|
||||||
|
$u2->address->zip = '111111111';
|
||||||
|
$u2->address->city = 'Some City 2';
|
||||||
|
$u2->address->country = 'Some Country 2';
|
||||||
|
|
||||||
|
$u3->name = 'Fabio Silva';
|
||||||
|
$u3->username = 'FabioBatSilva';
|
||||||
|
$u3->status = 'developer';
|
||||||
|
$u3->email->email = 'fabio.bat.silva@gmail.com';
|
||||||
|
$u3->address->zip = '33333333';
|
||||||
|
$u3->address->city = 'Some City 3';
|
||||||
|
$u3->address->country = 'Some Country 3';
|
||||||
|
|
||||||
|
$this->_em->persist($u1);
|
||||||
|
$this->_em->persist($u2);
|
||||||
|
$this->_em->persist($u3);
|
||||||
|
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$query = $this->_em->createQuery("SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO(u.name, e.email, a.city) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a ORDER BY u.name");
|
||||||
|
$result = $query->getResult();
|
||||||
|
|
||||||
|
$this->assertEquals(3, count($result));
|
||||||
|
|
||||||
|
$this->markTestIncomplete();
|
||||||
|
|
||||||
|
$this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\CMS\CmsUserDTO);
|
||||||
|
$this->assertTrue($result[1] instanceof \Doctrine\Tests\Models\CMS\CmsUserDTO);
|
||||||
|
$this->assertTrue($result[2] instanceof \Doctrine\Tests\Models\CMS\CmsUserDTO);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue