本文整理汇总了PHP中Doctrine\ORM\Query\ResultSetMappingBuilder::addJoinedEntityFromClassMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP ResultSetMappingBuilder::addJoinedEntityFromClassMetadata方法的具体用法?PHP ResultSetMappingBuilder::addJoinedEntityFromClassMetadata怎么用?PHP ResultSetMappingBuilder::addJoinedEntityFromClassMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Query\ResultSetMappingBuilder
的用法示例。
在下文中一共展示了ResultSetMappingBuilder::addJoinedEntityFromClassMetadata方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUnknownParentAliasThrowsException
/**
* @group PR-39
*/
public function testUnknownParentAliasThrowsException()
{
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u');
$rsm->addJoinedEntityFromClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress', 'a', 'un', 'address', array('id' => 'a_id'));
$query = $this->_em->createNativeQuery('SELECT u.*, a.*, a.id AS a_id FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', $rsm);
$query->setParameter(1, 'romanb');
$this->setExpectedException("Doctrine\\ORM\\Internal\\Hydration\\HydrationException", "The parent object of entity result with alias 'a' was not found. The parent alias is 'un'.");
$users = $query->getResult();
}
示例2: testIssue
public function testIssue()
{
$config = $this->_em->getConfiguration();
$config->addEntityNamespace('MyNamespace', 'Doctrine\\Tests\\ORM\\Functional\\Ticket');
$user = new DDC2256User();
$user->name = 'user';
$group = new DDC2256Group();
$group->name = 'group';
$user->group = $group;
$this->_em->persist($user);
$this->_em->persist($group);
$this->_em->flush();
$this->_em->clear();
$sql = 'SELECT u.id, u.name, g.id as group_id, g.name as group_name FROM ddc2256_users u LEFT JOIN ddc2256_groups g ON u.group_id = g.id';
// Test ResultSetMapping.
$rsm = new ResultSetMapping();
$rsm->addEntityResult('MyNamespace:DDC2256User', 'u');
$rsm->addFieldResult('u', 'id', 'id');
$rsm->addFieldResult('u', 'name', 'name');
$rsm->addJoinedEntityResult('MyNamespace:DDC2256Group', 'g', 'u', 'group');
$rsm->addFieldResult('g', 'group_id', 'id');
$rsm->addFieldResult('g', 'group_name', 'name');
$this->_em->createNativeQuery($sql, $rsm)->getResult();
// Test ResultSetMappingBuilder.
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('MyNamespace:DDC2256User', 'u');
$rsm->addJoinedEntityFromClassMetadata('MyNamespace:DDC2256Group', 'g', 'u', 'group', array('id' => 'group_id', 'name' => 'group_name'));
$this->_em->createNativeQuery($sql, $rsm)->getResult();
}
示例3: testQueryNotCacheableAssociationException
/**
* @expectedException Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Entity association field "Doctrine\Tests\Models\Cache\City#travels" not configured as part of the second-level cache.
*/
public function testQueryNotCacheableAssociationException()
{
$uow = $this->em->getUnitOfWork();
$key = new QueryCacheKey('query.key1', 0);
$rsm = new ResultSetMappingBuilder($this->em);
$cityClass = $this->em->getClassMetadata(City::CLASSNAME);
$city = new City("City 1", null);
$result = array($city);
$cityClass->setFieldValue($city, 'id', 1);
$rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c');
$rsm->addJoinedEntityFromClassMetadata(Travel::CLASSNAME, 't', 'c', 'travels', array('id' => 't_id'));
$uow->registerManaged($city, array('id' => $city->getId()), array('name' => $city->getName(), 'state' => null));
$this->queryCache->put($key, $rsm, $result);
}