本文整理汇总了PHP中Doctrine\ORM\Query\ResultSetMapping::addMetaResult方法的典型用法代码示例。如果您正苦于以下问题:PHP ResultSetMapping::addMetaResult方法的具体用法?PHP ResultSetMapping::addMetaResult怎么用?PHP ResultSetMapping::addMetaResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Query\ResultSetMapping
的用法示例。
在下文中一共展示了ResultSetMapping::addMetaResult方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBasicNativeQueryWithMetaResult
public function testBasicNativeQueryWithMetaResult()
{
$user = new CmsUser();
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'dev';
$addr = new CmsAddress();
$addr->country = 'germany';
$addr->zip = 10827;
$addr->city = 'Berlin';
$user->setAddress($addr);
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$rsm = new ResultSetMapping();
$rsm->addEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsAddress', 'a');
$rsm->addFieldResult('a', $this->platform->getSQLResultCasing('id'), 'id');
$rsm->addFieldResult('a', $this->platform->getSQLResultCasing('country'), 'country');
$rsm->addFieldResult('a', $this->platform->getSQLResultCasing('zip'), 'zip');
$rsm->addFieldResult('a', $this->platform->getSQLResultCasing('city'), 'city');
$rsm->addMetaResult('a', $this->platform->getSQLResultCasing('user_id'), 'user_id');
$query = $this->_em->createNativeQuery('SELECT a.id, a.country, a.zip, a.city, a.user_id FROM cms_addresses a WHERE a.id = ?', $rsm);
$query->setParameter(1, $addr->id);
$addresses = $query->getResult();
$this->assertEquals(1, count($addresses));
$this->assertTrue($addresses[0] instanceof CmsAddress);
$this->assertEquals($addr->country, $addresses[0]->country);
$this->assertEquals($addr->zip, $addresses[0]->zip);
$this->assertEquals($addr->city, $addresses[0]->city);
$this->assertEquals($addr->street, $addresses[0]->street);
$this->assertTrue($addresses[0]->user instanceof CmsUser);
}
示例2: testIndexByMetadataColumn
/**
* @group DDC-117
*/
public function testIndexByMetadataColumn()
{
$this->_rsm->addEntityResult('Doctrine\\Tests\\Models\\Legacy\\LegacyUser', 'u');
$this->_rsm->addJoinedEntityResult('Doctrine\\Tests\\Models\\Legacy', 'lu', 'u', '_references');
$this->_rsm->addMetaResult('lu', '_source', '_source', true);
$this->_rsm->addMetaResult('lu', '_target', '_target', true);
$this->_rsm->addIndexBy('lu', '_source');
$this->assertTrue($this->_rsm->hasIndexBy('lu'));
}
示例3: testMissingDiscriminatorColumnException
/**
* @group DDC-1470
*
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException
* @expectedExceptionMessage The discriminator column "discr" is missing for "Doctrine\Tests\Models\Company\CompanyPerson" using the DQL alias "p".
*/
public function testMissingDiscriminatorColumnException()
{
$rsm = new ResultSetMapping();
$rsm->addEntityResult('Doctrine\\Tests\\Models\\Company\\CompanyPerson', 'p');
$rsm->addFieldResult('p', 'p__id', 'id');
$rsm->addFieldResult('p', 'p__name', 'name');
$rsm->addMetaResult('p ', 'discr', 'discr');
$rsm->setDiscriminatorColumn('p', 'discr');
$resultSet = array(array('u__id' => '1', 'u__name' => 'Fabio B. Silva'));
$stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
$hydrator->hydrateAll($stmt, $rsm);
}
示例4: testCreatesProxyForLazyLoadingWithForeignKeys
/**
* Select p from \Doctrine\Tests\Models\ECommerce\ECommerceProduct p
*/
public function testCreatesProxyForLazyLoadingWithForeignKeys()
{
$rsm = new ResultSetMapping();
$rsm->addEntityResult('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct', 'p');
$rsm->addFieldResult('p', 'p__id', 'id');
$rsm->addFieldResult('p', 'p__name', 'name');
$rsm->addMetaResult('p', 'p__shipping_id', 'shipping_id');
// Faked result set
$resultSet = array(array('p__id' => '1', 'p__name' => 'Doctrine Book', 'p__shipping_id' => 42));
$proxyInstance = new \Doctrine\Tests\Models\ECommerce\ECommerceShipping();
// mocking the proxy factory
$proxyFactory = $this->getMock('Doctrine\\ORM\\Proxy\\ProxyFactory', array('getProxy'), array(), '', false, false, false);
$proxyFactory->expects($this->once())->method('getProxy')->with($this->equalTo('Doctrine\\Tests\\Models\\ECommerce\\ECommerceShipping'), array('id' => 42))->will($this->returnValue($proxyInstance));
$this->_em->setProxyFactory($proxyFactory);
// configuring lazy loading
$metadata = $this->_em->getClassMetadata('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct');
$metadata->getAssociationMapping('shipping')->fetchMode = AssociationMapping::FETCH_LAZY;
$stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(1, count($result));
$this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\ECommerce\ECommerceProduct);
}
示例5: _getSelectColumnAssociationSQL
protected function _getSelectColumnAssociationSQL($field, $assoc, ClassMetadata $class, $alias = 'r')
{
$columnList = '';
if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) {
foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) {
if ($columnList) {
$columnList .= ', ';
}
$columnAlias = $srcColumn . $this->_sqlAliasCounter++;
$resultColumnName = $this->_platform->getSQLResultCasing($columnAlias);
$columnList .= $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $srcColumn . ' AS ' . $resultColumnName;
$this->_rsm->addMetaResult($alias, $resultColumnName, $srcColumn, isset($assoc['id']) && $assoc['id'] === true);
}
}
return $columnList;
}
示例6: walkSelectClause
/**
* {@inheritdoc}
*/
public function walkSelectClause($selectClause)
{
$sql = 'SELECT ' . ($selectClause->isDistinct ? 'DISTINCT ' : '');
$sqlSelectExpressions = array_filter(array_map(array($this, 'walkSelectExpression'), $selectClause->selectExpressions));
if ($this->query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $selectClause->isDistinct) {
$this->query->setHint(self::HINT_DISTINCT, true);
}
$addMetaColumns = !$this->query->getHint(Query::HINT_FORCE_PARTIAL_LOAD) && $this->query->getHydrationMode() == Query::HYDRATE_OBJECT || $this->query->getHydrationMode() != Query::HYDRATE_OBJECT && $this->query->getHint(Query::HINT_INCLUDE_META_COLUMNS);
foreach ($this->selectedClasses as $selectedClass) {
$class = $selectedClass['class'];
$dqlAlias = $selectedClass['dqlAlias'];
$resultAlias = $selectedClass['resultAlias'];
// Register as entity or joined entity result
if ($this->queryComponents[$dqlAlias]['relation'] === null) {
$this->rsm->addEntityResult($class->name, $dqlAlias, $resultAlias);
} else {
$this->rsm->addJoinedEntityResult($class->name, $dqlAlias, $this->queryComponents[$dqlAlias]['parent'], $this->queryComponents[$dqlAlias]['relation']['fieldName']);
}
if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()) {
// Add discriminator columns to SQL
$rootClass = $this->em->getClassMetadata($class->rootEntityName);
$tblAlias = $this->getSQLTableAlias($rootClass->getTableName(), $dqlAlias);
$discrColumn = $rootClass->discriminatorColumn;
$columnAlias = $this->getSQLColumnAlias($discrColumn['name']);
$sqlSelectExpressions[] = $tblAlias . '.' . $discrColumn['name'] . ' AS ' . $columnAlias;
$this->rsm->setDiscriminatorColumn($dqlAlias, $columnAlias);
$this->rsm->addMetaResult($dqlAlias, $columnAlias, $discrColumn['fieldName']);
}
// Add foreign key columns to SQL, if necessary
if (!$addMetaColumns && !$class->containsForeignIdentifier) {
continue;
}
// Add foreign key columns of class and also parent classes
foreach ($class->associationMappings as $assoc) {
if (!($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) {
continue;
} else {
if (!$addMetaColumns && !isset($assoc['id'])) {
continue;
}
}
$owningClass = isset($assoc['inherited']) ? $this->em->getClassMetadata($assoc['inherited']) : $class;
$sqlTableAlias = $this->getSQLTableAlias($owningClass->getTableName(), $dqlAlias);
foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) {
$columnAlias = $this->getSQLColumnAlias($srcColumn);
$sqlSelectExpressions[] = $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias;
$this->rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn, isset($assoc['id']) && $assoc['id'] === true);
}
}
// Add foreign key columns to SQL, if necessary
if (!$addMetaColumns) {
continue;
}
// Add foreign key columns of subclasses
foreach ($class->subClasses as $subClassName) {
$subClass = $this->em->getClassMetadata($subClassName);
$sqlTableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias);
foreach ($subClass->associationMappings as $assoc) {
// Skip if association is inherited
if (isset($assoc['inherited'])) {
continue;
}
if (!($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) {
continue;
}
foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) {
$columnAlias = $this->getSQLColumnAlias($srcColumn);
$sqlSelectExpressions[] = $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias;
$this->rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn);
}
}
}
}
$sql .= implode(', ', $sqlSelectExpressions);
return $sql;
}
示例7: getSelectColumnAssociationSQL
/**
* Gets the SQL join fragment used when selecting entities from an association.
*
* @param string $field
* @param array $assoc
* @param ClassMetadata $class
* @param string $alias
*
* @return string
*/
protected function getSelectColumnAssociationSQL($field, $assoc, ClassMetadata $class, $alias = 'r')
{
if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) ) {
return '';
}
$columnList = array();
foreach ($assoc['joinColumns'] as $joinColumn) {
$quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);
$resultColumnName = $this->getSQLColumnAlias($joinColumn['name']);
$columnList[] = $this->getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) )
. '.' . $quotedColumn . ' AS ' . $resultColumnName;
$this->rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, isset($assoc['id']) && $assoc['id'] === true);
}
return implode(', ', $columnList);
}
示例8: walkSelectExpression
//.........这里部分代码省略.........
$columnAlias = 'sclr' . $this->_aliasCounter++;
$sql .= $this->walkFunction($expr) . ' AS ' . $columnAlias;
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
} else {
if ($expr instanceof AST\SimpleArithmeticExpression) {
if (!$selectExpression->fieldIdentificationVariable) {
$resultAlias = $this->_scalarResultCounter++;
} else {
$resultAlias = $selectExpression->fieldIdentificationVariable;
}
$columnAlias = 'sclr' . $this->_aliasCounter++;
$sql .= $this->walkSimpleArithmeticExpression($expr) . ' AS ' . $columnAlias;
$this->_scalarResultAliasMap[$resultAlias] = $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addScalarResult($columnAlias, $resultAlias);
} else {
// IdentificationVariable or PartialObjectExpression
if ($expr instanceof AST\PartialObjectExpression) {
$dqlAlias = $expr->identificationVariable;
$partialFieldSet = $expr->partialFieldSet;
} else {
$dqlAlias = $expr;
$partialFieldSet = array();
}
$queryComp = $this->_queryComponents[$dqlAlias];
$class = $queryComp['metadata'];
if (!isset($this->_selectedClasses[$dqlAlias])) {
$this->_selectedClasses[$dqlAlias] = $class;
}
$beginning = true;
// Select all fields from the queried class
foreach ($class->fieldMappings as $fieldName => $mapping) {
if ($partialFieldSet && !in_array($fieldName, $partialFieldSet)) {
continue;
}
if (isset($mapping['inherited'])) {
$tableName = $this->_em->getClassMetadata($mapping['inherited'])->primaryTable['name'];
} else {
$tableName = $class->primaryTable['name'];
}
if ($beginning) {
$beginning = false;
} else {
$sql .= ', ';
}
$sqlTableAlias = $this->getSqlTableAlias($tableName, $dqlAlias);
$columnAlias = $this->getSqlColumnAlias($mapping['columnName']);
$sql .= $sqlTableAlias . '.' . $class->getQuotedColumnName($fieldName, $this->_platform) . ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name);
}
// Add any additional fields of subclasses (excluding inherited fields)
// 1) on Single Table Inheritance: always, since its marginal overhead
// 2) on Class Table Inheritance only if partial objects are disallowed,
// since it requires outer joining subtables.
if ($class->isInheritanceTypeSingleTable() || !$this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) {
foreach ($class->subClasses as $subClassName) {
$subClass = $this->_em->getClassMetadata($subClassName);
$sqlTableAlias = $this->getSqlTableAlias($subClass->primaryTable['name'], $dqlAlias);
foreach ($subClass->fieldMappings as $fieldName => $mapping) {
if (isset($mapping['inherited']) || $partialFieldSet && !in_array($fieldName, $partialFieldSet)) {
continue;
}
if ($beginning) {
$beginning = false;
} else {
$sql .= ', ';
}
$columnAlias = $this->getSqlColumnAlias($mapping['columnName']);
$sql .= $sqlTableAlias . '.' . $subClass->getQuotedColumnName($fieldName, $this->_platform) . ' AS ' . $columnAlias;
$columnAlias = $this->_platform->getSQLResultCasing($columnAlias);
$this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $subClassName);
}
// Add join columns (foreign keys) of the subclass
//TODO: Probably better do this in walkSelectClause to honor the INCLUDE_META_COLUMNS hint
foreach ($subClass->associationMappings as $fieldName => $assoc) {
if ($assoc->isOwningSide && $assoc->isOneToOne() && !isset($subClass->inheritedAssociationFields[$fieldName])) {
foreach ($assoc->targetToSourceKeyColumns as $srcColumn) {
if ($beginning) {
$beginning = false;
} else {
$sql .= ', ';
}
$columnAlias = $this->getSqlColumnAlias($srcColumn);
$sql .= $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias;
$this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn);
}
}
}
}
}
}
}
}
}
}
return $sql;
}
示例9: getResultSetMapping
private function getResultSetMapping()
{
$rsm = new ResultSetMapping();
$rsm->addEntityResult('BackBee\\Bundle\\Registry', 'br');
$rsm->addFieldResult('br', 'id', 'id');
$rsm->addFieldResult('br', 'type', 'type');
$rsm->addMetaResult('br', 'key', 'key');
$rsm->addMetaResult('br', 'value', 'value');
$rsm->addMetaResult('br', 'scope', 'scope');
return $rsm;
}
示例10: getSelectColumnAssociationSQL
/**
* Gets the SQL join fragment used when selecting entities from an association.
*
* @param string $field
* @param array $assoc
* @param ClassMetadata $class
* @param string $alias
*
* @return string
*/
protected function getSelectColumnAssociationSQL($field, $assoc, ClassMetadata $class, $alias = 'r')
{
if (!($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) {
return '';
}
$columnList = array();
$targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
foreach ($assoc['joinColumns'] as $joinColumn) {
$type = null;
$isIdentifier = isset($assoc['id']) && $assoc['id'] === true;
$quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);
$resultColumnName = $this->getSQLColumnAlias($joinColumn['name']);
$columnList[] = $this->getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $quotedColumn . ' AS ' . $resultColumnName;
if (isset($targetClass->fieldNames[$joinColumn['referencedColumnName']])) {
$type = $targetClass->fieldMappings[$targetClass->fieldNames[$joinColumn['referencedColumnName']]]['type'];
}
$this->rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, $isIdentifier, $type);
}
return implode(', ', $columnList);
}
示例11: testMissingDiscriminatorColumnException
/**
* @group DDC-1470
*
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException
* @expectedExceptionMessage The discriminator column "discr" is missing for "Doctrine\Tests\Models\Company\CompanyEmployee" using the DQL alias "e".
*/
public function testMissingDiscriminatorColumnException()
{
$rsm = new ResultSetMapping();
$rsm->addEntityResult('Doctrine\\Tests\\Models\\Company\\CompanyFixContract', 'c');
$rsm->addJoinedEntityResult('Doctrine\\Tests\\Models\\Company\\CompanyEmployee', 'e', 'c', 'salesPerson');
$rsm->addFieldResult('c', 'c__id', 'id');
$rsm->addMetaResult('c', 'c_discr', 'discr');
$rsm->setDiscriminatorColumn('c', 'c_discr');
$rsm->addFieldResult('e', 'e__id', 'id');
$rsm->addFieldResult('e', 'e__name', 'name');
$rsm->addMetaResult('e ', 'e_discr', 'discr');
$rsm->setDiscriminatorColumn('e', 'e_discr');
$resultSet = array(array('c__id' => '1', 'c_discr' => 'fix', 'e__id' => '1', 'e__name' => 'Fabio B. Silva'));
$stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$hydrator->hydrateAll($stmt, $rsm);
}
示例12: testMissingIdForSingleValuedChildEntity
/**
* @group DDC-1358
*/
public function testMissingIdForSingleValuedChildEntity()
{
$rsm = new ResultSetMapping();
$rsm->addEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u');
$rsm->addJoinedEntityResult('Doctrine\\Tests\\Models\\CMS\\CmsAddress', 'a', 'u', 'address');
$rsm->addFieldResult('u', 'u__id', 'id');
$rsm->addFieldResult('u', 'u__status', 'status');
$rsm->addScalarResult('sclr0', 'nameUpper');
$rsm->addFieldResult('a', 'a__id', 'id');
$rsm->addFieldResult('a', 'a__city', 'city');
$rsm->addMetaResult('a', 'user_id', 'user_id');
// Faked result set
$resultSet = array(array('u__id' => '1', 'u__status' => 'developer', 'sclr0' => 'ROMANB', 'a__id' => 1, 'a__city' => 'Berlin'), array('u__id' => '2', 'u__status' => 'developer', 'sclr0' => 'BENJAMIN', 'a__id' => null, 'a__city' => null));
$stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true));
$this->assertEquals(2, count($result));
$this->assertInstanceOf('Doctrine\\Tests\\Models\\CMS\\CmsAddress', $result[0][0]->address);
$this->assertNull($result[1][0]->address);
}
示例13: getTacheCreneau
public function getTacheCreneau($tache_id, $plage_id)
{
$rsm = new ResultSetMapping();
$rsm->addEntityResult('AssoMakerPHPMBundle:Creneau', 'c');
$rsm->addFieldResult('c', 'id', 'id');
$rsm->addFieldResult('c', 'debut', 'debut');
$rsm->addFieldResult('c', 'fin', 'fin');
$rsm->addMetaResult('c', 'did', 'did');
$rsm->addMetaResult('c', 'eid', 'eid');
$rsm->addMetaResult('c', 'oid', 'oid');
$rsm->addJoinedEntityResult('AssoMakerPHPMBundle:PlageHoraire', 'p', 'c', 'plageHoraire');
$rsm->addFieldResult('p', 'pi', 'id');
$rsm->addJoinedEntityResult('AssoMakerPHPMBundle:Tache', 't', 'p', 'tache');
$rsm->addFieldResult('t', 'ti', 'id');
$rsm->addFieldResult('t', 'tn', 'nom');
$rsm->addFieldResult('t', 'tl', 'lieu');
$sql = 'SELECT c.id, c.debut, c.fin, c.disponibilite_id AS did, c.equipeHint_id AS eid, c.orgaHint_id AS oid, p.id AS pi, t.id AS ti, t.nom AS tn, t.lieu AS tl
FROM Creneau c
JOIN PlageHoraire p ON c.plageHoraire_id = p.id
JOIN Tache t ON p.tache_id = t.id
WHERE t.id = ?';
if ($plage_id !== '') {
$pref = json_decode($this->getEntityManager()->getRepository('AssoMakerPHPMBundle:Config')->findOneByField('manifestation_plages')->getValue(), TRUE);
$plage = $pref[$plage_id];
$fin = $plage["fin"];
$debut = $plage["debut"];
$sql .= " AND DATE(c.debut) <= DATE('{$fin}') AND DATE(c.fin) >= DATE('{$debut}')";
}
$sql .= ' GROUP BY c.debut, c.fin, eid, oid, (did IS NOT NULL)';
$query = $this->getEntityManager()->createNativeQuery($sql, $rsm);
$query->setParameter(1, $tache_id);
// PDO \o/
return $query->getArrayResult();
}