[2.0] Moved code between Query and AbstractQuery. Added first NativeQuery implementation. Hydration work and code movements for discriminator column usage. Started implementing Single Table Inheritance.
This commit is contained in:
parent
67ba9661c5
commit
ee46dba332
@ -31,8 +31,9 @@ use \ArrayIterator;
|
||||
* A Collection is a thin wrapper around a php array. Think of it as an OO version
|
||||
* of a plain array.
|
||||
*
|
||||
* @author Roman S. Borschel
|
||||
* @author Roman S. Borschel <roman@code-factory.org>
|
||||
* @since 2.0
|
||||
* @todo Consider extending ArrayObject
|
||||
*/
|
||||
class Collection implements Countable, IteratorAggregate, ArrayAccess
|
||||
{
|
||||
|
@ -49,9 +49,8 @@ interface Statement
|
||||
public function bindColumn($column, &$param, $type = null);
|
||||
|
||||
/**
|
||||
* bindValue
|
||||
* Binds a value to a corresponding named or question mark
|
||||
* placeholder in the SQL statement that was use to prepare the statement.
|
||||
* Binds a value to a corresponding named or positional
|
||||
* placeholder in the SQL statement that was used to prepare the statement.
|
||||
*
|
||||
* @param mixed $param Parameter identifier. For a prepared statement using named placeholders,
|
||||
* this will be a parameter name of the form :name. For a prepared statement
|
||||
@ -65,7 +64,6 @@ interface Statement
|
||||
public function bindValue($param, $value, $type = null);
|
||||
|
||||
/**
|
||||
* bindParam
|
||||
* Binds a PHP variable to a corresponding named or question mark placeholder in the
|
||||
* SQL statement that was use to prepare the statement. Unlike PDOStatement->bindValue(),
|
||||
* the variable is bound as a reference and will only be evaluated at the time
|
||||
|
@ -36,7 +36,10 @@ abstract class Type
|
||||
}
|
||||
|
||||
abstract public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform);
|
||||
|
||||
abstract public function getName();
|
||||
|
||||
//abstract public function getTypeCode();
|
||||
|
||||
/**
|
||||
* Factory method to create type instances.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -223,7 +223,7 @@ class EntityManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a query with the specified name.
|
||||
* Creates a DQL query with the specified name.
|
||||
*
|
||||
* @todo Implementation.
|
||||
* @throws DoctrineException If there is no query registered with the given name.
|
||||
@ -234,11 +234,17 @@ class EntityManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implementation.
|
||||
* Creates a native SQL query.
|
||||
*
|
||||
* @param string $sql
|
||||
* @return Query
|
||||
*/
|
||||
public function createNativeQuery($sql = "")
|
||||
public function createNativeQuery($sql, \Doctrine\ORM\Query\ResultSetMapping $rsm)
|
||||
{
|
||||
//...
|
||||
$query = new NativeQuery($this);
|
||||
$query->setSql($sql);
|
||||
$query->setResultSetMapping($rsm);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,8 @@ namespace Doctrine\ORM\Internal\Hydration;
|
||||
use \PDO;
|
||||
|
||||
/**
|
||||
* Base class for all hydrators (ok, we got only 1 currently).
|
||||
* Base class for all hydrators. A hydrator is a class that provides some form
|
||||
* of transformation of an SQL result set into another structure.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
@ -50,11 +51,8 @@ abstract class AbstractHydrator
|
||||
/** @var Statement The statement that provides the data to hydrate. */
|
||||
protected $_stmt;
|
||||
|
||||
/** @var object The ParserResult instance that holds the necessary information for hydration. */
|
||||
protected $_parserResult;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of a class derived from AbstractHydrator.
|
||||
* Initializes a new instance of a class derived from <tt>AbstractHydrator</tt>.
|
||||
*
|
||||
* @param Doctrine\ORM\EntityManager $em The EntityManager to use.
|
||||
*/
|
||||
@ -68,13 +66,14 @@ abstract class AbstractHydrator
|
||||
* Initiates a row-by-row hydration.
|
||||
*
|
||||
* @param object $stmt
|
||||
* @param object $parserResult
|
||||
* @param object $resultSetMapping
|
||||
* @return IterableResult
|
||||
*/
|
||||
public function iterate($stmt, $parserResult)
|
||||
public function iterate($stmt, $resultSetMapping)
|
||||
{
|
||||
$this->_stmt = $stmt;
|
||||
$this->_prepare($parserResult);
|
||||
$this->_resultSetMapping = $resultSetMapping;
|
||||
$this->_prepare();
|
||||
return new IterableResult($this);
|
||||
}
|
||||
|
||||
@ -82,13 +81,14 @@ abstract class AbstractHydrator
|
||||
* Hydrates all rows returned by the passed statement instance at once.
|
||||
*
|
||||
* @param object $stmt
|
||||
* @param object $parserResult
|
||||
* @param object $resultSetMapping
|
||||
* @return mixed
|
||||
*/
|
||||
public function hydrateAll($stmt, $parserResult)
|
||||
public function hydrateAll($stmt, $resultSetMapping)
|
||||
{
|
||||
$this->_stmt = $stmt;
|
||||
$this->_prepare($parserResult);
|
||||
$this->_resultSetMapping = $resultSetMapping;
|
||||
$this->_prepare();
|
||||
$result = $this->_hydrateAll();
|
||||
$this->_cleanup();
|
||||
return $result;
|
||||
@ -115,14 +115,9 @@ abstract class AbstractHydrator
|
||||
/**
|
||||
* Excutes one-time preparation tasks once each time hydration is started
|
||||
* through {@link hydrateAll} or {@link iterate()}.
|
||||
*
|
||||
* @param object $parserResult
|
||||
*/
|
||||
protected function _prepare($parserResult)
|
||||
{
|
||||
$this->_resultSetMapping = $parserResult->getResultSetMapping();
|
||||
$this->_parserResult = $parserResult;
|
||||
}
|
||||
protected function _prepare()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Excutes one-time cleanup tasks at the end of a hydration that was initiated
|
||||
@ -131,7 +126,6 @@ abstract class AbstractHydrator
|
||||
protected function _cleanup()
|
||||
{
|
||||
$this->_resultSetMapping = null;
|
||||
$this->_parserResult = null;
|
||||
$this->_stmt->closeCursor();
|
||||
$this->_stmt = null;
|
||||
}
|
||||
@ -152,8 +146,6 @@ abstract class AbstractHydrator
|
||||
|
||||
/**
|
||||
* Hydrates all rows from the current statement instance at once.
|
||||
*
|
||||
* @param object $parserResult
|
||||
*/
|
||||
abstract protected function _hydrateAll();
|
||||
|
||||
@ -180,21 +172,26 @@ abstract class AbstractHydrator
|
||||
foreach ($data as $key => $value) {
|
||||
// Parse each column name only once. Cache the results.
|
||||
if ( ! isset($cache[$key])) {
|
||||
if ($this->_isIgnoredName($key)) continue;
|
||||
|
||||
if ($this->_resultSetMapping->isScalarResult($key)) {
|
||||
if ($this->_resultSetMapping->isIgnoredColumn($key)) {
|
||||
$cache[$key] = false;
|
||||
} else if ($this->_resultSetMapping->isScalarResult($key)) {
|
||||
$cache[$key]['fieldName'] = $this->_resultSetMapping->getScalarAlias($key);
|
||||
$cache[$key]['isScalar'] = true;
|
||||
} else {
|
||||
} else if ($this->_resultSetMapping->isFieldResult($key)) {
|
||||
$classMetadata = $this->_resultSetMapping->getOwningClass($key);
|
||||
$fieldName = $this->_resultSetMapping->getFieldName($key);
|
||||
$classMetadata = $this->_lookupDeclaringClass($classMetadata, $fieldName);
|
||||
//$fieldName = $classMetadata->getFieldNameForLowerColumnName($columnName);
|
||||
$cache[$key]['fieldName'] = $fieldName;
|
||||
$cache[$key]['isScalar'] = false;
|
||||
$cache[$key]['type'] = $classMetadata->getTypeOfField($fieldName);
|
||||
$cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName);
|
||||
$cache[$key]['dqlAlias'] = $this->_resultSetMapping->getEntityAlias($key);
|
||||
} else {
|
||||
// Discriminator column
|
||||
$cache[$key]['isDiscriminator'] = true;
|
||||
$cache[$key]['isScalar'] = false;
|
||||
$cache[$key]['fieldName'] = $key;
|
||||
$cache[$key]['dqlAlias'] = $this->_resultSetMapping->getEntityAlias($key);
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,6 +204,11 @@ abstract class AbstractHydrator
|
||||
|
||||
$dqlAlias = $cache[$key]['dqlAlias'];
|
||||
|
||||
if (isset($cache[$key]['isDiscriminator'])) {
|
||||
$rowData[$dqlAlias][$fieldName] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($cache[$key]['isIdentifier']) {
|
||||
$id[$dqlAlias] .= '|' . $value;
|
||||
}
|
||||
@ -243,9 +245,10 @@ abstract class AbstractHydrator
|
||||
foreach ($data as $key => $value) {
|
||||
// Parse each column name only once. Cache the results.
|
||||
if ( ! isset($cache[$key])) {
|
||||
if ($this->_isIgnoredName($key)) continue;
|
||||
|
||||
if ($this->_resultSetMapping->isScalarResult($key)) {
|
||||
if ($this->_resultSetMapping->isIgnoredColumn($key)) {
|
||||
$cache[$key] = false;
|
||||
continue;
|
||||
} else if ($this->_resultSetMapping->isScalarResult($key)) {
|
||||
$cache[$key]['fieldName'] = $this->_resultSetMapping->getScalarAlias($key);
|
||||
$cache[$key]['isScalar'] = true;
|
||||
} else {
|
||||
@ -285,19 +288,6 @@ abstract class AbstractHydrator
|
||||
$this->_resultSetMapping->getIndexByField($alias) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a name is ignored. Used during result set parsing to skip
|
||||
* certain elements in the result set that do not have any meaning for the result.
|
||||
* (I.e. ORACLE limit/offset emulation adds doctrine_rownum to the result set).
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
private function _isIgnoredName($name)
|
||||
{
|
||||
return $name == 'doctrine_rownum';
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the field name for a (lowercased) column name.
|
||||
*
|
||||
@ -319,14 +309,12 @@ abstract class AbstractHydrator
|
||||
private function _lookupDeclaringClass($class, $fieldName)
|
||||
{
|
||||
if ($class->hasField($fieldName)) {
|
||||
//return $class->getFieldNameForLowerColumnName($lcColumnName);
|
||||
return $class;
|
||||
}
|
||||
|
||||
foreach ($class->getSubclasses() as $subClass) {
|
||||
$subClassMetadata = $this->_em->getClassMetadata($subClass);
|
||||
if ($subClassMetadata->hasField($fieldName)) {
|
||||
//return $subClassMetadata->getFieldNameForLowerColumnName($lcColumnName);
|
||||
return $subClassMetadata;
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,8 @@ class ArrayHydrator extends AbstractHydrator
|
||||
private $_resultCounter = 0;
|
||||
|
||||
/** @override */
|
||||
protected function _prepare($parserResult)
|
||||
protected function _prepare()
|
||||
{
|
||||
parent::_prepare($parserResult);
|
||||
$this->_isSimpleQuery = $this->_resultSetMapping->getEntityResultCount() <= 1;
|
||||
$this->_identifierMap = array();
|
||||
$this->_resultPointers = array();
|
||||
@ -98,7 +97,7 @@ class ArrayHydrator extends AbstractHydrator
|
||||
|
||||
// Get a reference to the right element in the result tree.
|
||||
// This element will get the associated element attached.
|
||||
if ($this->_parserResult->isMixedQuery() && isset($this->_rootAliases[$parent])) {
|
||||
if ($this->_resultSetMapping->isMixedResult() && isset($this->_rootAliases[$parent])) {
|
||||
$key = key(reset($this->_resultPointers));
|
||||
// TODO: Exception if $key === null ?
|
||||
$baseElement =& $this->_resultPointers[$parent][$key];
|
||||
@ -155,14 +154,14 @@ class ArrayHydrator extends AbstractHydrator
|
||||
if ($this->_isSimpleQuery || ! isset($this->_identifierMap[$dqlAlias][$id[$dqlAlias]])) {
|
||||
$element = $rowData[$dqlAlias];
|
||||
if ($field = $this->_getCustomIndexField($dqlAlias)) {
|
||||
if ($this->_parserResult->isMixedQuery()) {
|
||||
if ($this->_resultSetMapping->isMixedResult()) {
|
||||
$result[] = array($element[$field] => $element);
|
||||
++$this->_resultCounter;
|
||||
} else {
|
||||
$result[$element[$field]] = $element;
|
||||
}
|
||||
} else {
|
||||
if ($this->_parserResult->isMixedQuery()) {
|
||||
if ($this->_resultSetMapping->isMixedResult()) {
|
||||
$result[] = array($element);
|
||||
++$this->_resultCounter;
|
||||
} else {
|
||||
|
@ -33,22 +33,24 @@ use Doctrine\Common\Collections\Collection;
|
||||
*/
|
||||
class ObjectHydrator extends AbstractHydrator
|
||||
{
|
||||
/* TOOD: Consider unifying _collections and _initializedRelations */
|
||||
/** Collections initialized by the hydrator */
|
||||
private $_collections = array();
|
||||
/** Memory for initialized relations */
|
||||
private $_initializedRelations = array();
|
||||
private $_metadataMap = array();
|
||||
|
||||
private $_classMetadatas = array();
|
||||
private $_rootAliases = array();
|
||||
private $_isSimpleQuery = false;
|
||||
private $_identifierMap = array();
|
||||
private $_resultPointers = array();
|
||||
private $_idTemplate = array();
|
||||
private $_resultCounter = 0;
|
||||
private $_discriminatorMap = array();
|
||||
|
||||
/** @override */
|
||||
protected function _prepare($parserResult)
|
||||
protected function _prepare()
|
||||
{
|
||||
parent::_prepare($parserResult);
|
||||
$this->_isSimpleQuery = $this->_resultSetMapping->getEntityResultCount() <= 1;
|
||||
$this->_identifierMap = array();
|
||||
$this->_resultPointers = array();
|
||||
@ -58,6 +60,14 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$this->_identifierMap[$dqlAlias] = array();
|
||||
$this->_resultPointers[$dqlAlias] = array();
|
||||
$this->_idTemplate[$dqlAlias] = '';
|
||||
$this->_classMetadatas[$class->getClassName()] = $class;
|
||||
if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()) {
|
||||
$this->_discriminatorMap[$class->getClassName()][$class->getDiscriminatorValue()] = $class->getClassName();
|
||||
foreach (array_merge($class->getParentClasses(), $class->getSubclasses()) as $className) {
|
||||
$value = $this->_em->getClassMetadata($className)->getDiscriminatorValue();
|
||||
$this->_discriminatorMap[$class->getClassName()][$value] = $className;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +80,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
{
|
||||
$s = microtime(true);
|
||||
|
||||
if ($this->_parserResult->isMixedQuery()) {
|
||||
if ($this->_resultSetMapping->isMixedResult()) {
|
||||
$result = array();
|
||||
} else {
|
||||
$result = new Collection;
|
||||
@ -90,7 +100,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
// Clean up
|
||||
$this->_collections = array();
|
||||
$this->_initializedRelations = array();
|
||||
$this->_metadataMap = array();
|
||||
$this->_classMetadatas = array();
|
||||
|
||||
$e = microtime(true);
|
||||
echo 'Hydration took: ' . ($e - $s) . PHP_EOL;
|
||||
@ -108,7 +118,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
* @param string $dqlAlias
|
||||
* @param boolean $oneToOne Whether it is a single-valued association or not.
|
||||
*/
|
||||
private function updateResultPointer(&$coll, $index, $dqlAlias, $oneToOne)
|
||||
private function updateResultPointer(&$coll, $index, $dqlAlias/*, $oneToOne*/)
|
||||
{
|
||||
if ($coll === null) {
|
||||
unset($this->_resultPointers[$dqlAlias]); // Ticket #1228
|
||||
@ -132,6 +142,12 @@ class ObjectHydrator extends AbstractHydrator
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $component
|
||||
* @return <type>
|
||||
* @todo Consider inlining this method.
|
||||
*/
|
||||
private function getCollection($component)
|
||||
{
|
||||
$coll = new PersistentCollection($this->_em, $component);
|
||||
@ -139,10 +155,16 @@ class ObjectHydrator extends AbstractHydrator
|
||||
return $coll;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $entity
|
||||
* @param <type> $name
|
||||
* @todo Consider inlining this method.
|
||||
*/
|
||||
private function initRelatedCollection($entity, $name)
|
||||
{
|
||||
$oid = spl_object_hash($entity);
|
||||
$classMetadata = $this->_metadataMap[$oid];
|
||||
$classMetadata = $this->_classMetadatas[get_class($entity)];
|
||||
if ( ! isset($this->_initializedRelations[$oid][$name])) {
|
||||
$relation = $classMetadata->getAssociationMapping($name);
|
||||
$relatedClass = $this->_em->getClassMetadata($relation->getTargetEntityName());
|
||||
@ -157,7 +179,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
|
||||
private function isIndexKeyInUse($entity, $assocField, $indexField)
|
||||
{
|
||||
return $this->_metadataMap[spl_object_hash($entity)]
|
||||
return $this->_classMetadatas[get_class($entity)]
|
||||
->getReflectionProperty($assocField)
|
||||
->getValue($entity)
|
||||
->containsKey($indexField);
|
||||
@ -178,9 +200,11 @@ class ObjectHydrator extends AbstractHydrator
|
||||
|
||||
private function getEntity(array $data, $className)
|
||||
{
|
||||
if ($discrColumn = $this->_resultSetMapping->getDiscriminatorColumn($className)) {
|
||||
$className = $this->_discriminatorMap[$className][$data[$discrColumn]];
|
||||
unset($data[$discrColumn]);
|
||||
}
|
||||
$entity = $this->_uow->createEntity($className, $data);
|
||||
$oid = spl_object_hash($entity);
|
||||
$this->_metadataMap[$oid] = $this->_em->getClassMetadata($className);
|
||||
return $entity;
|
||||
}
|
||||
|
||||
@ -191,11 +215,13 @@ class ObjectHydrator extends AbstractHydrator
|
||||
* @param <type> $property
|
||||
* @param <type> $entity2
|
||||
* @param <type> $indexField
|
||||
* @todo Consider inlining this method. It's called only once and inlining can
|
||||
* remove the need for the 2 get_class calls.
|
||||
*/
|
||||
private function addRelatedIndexedEntity($entity1, $property, $entity2, $indexField)
|
||||
{
|
||||
$classMetadata1 = $this->_metadataMap[spl_object_hash($entity1)];
|
||||
$classMetadata2 = $this->_metadataMap[spl_object_hash($entity2)];
|
||||
$classMetadata1 = $this->_classMetadatas[get_class($entity1)];
|
||||
$classMetadata2 = $this->_classMetadatas[get_class($entity2)];
|
||||
$indexValue = $classMetadata2->getReflectionProperty($indexField)->getValue($entity2);
|
||||
$classMetadata1->getReflectionProperty($property)->getValue($entity1)->set($indexValue, $entity2);
|
||||
}
|
||||
@ -209,8 +235,10 @@ class ObjectHydrator extends AbstractHydrator
|
||||
*/
|
||||
private function addRelatedEntity($entity1, $property, $entity2)
|
||||
{
|
||||
$classMetadata1 = $this->_metadataMap[spl_object_hash($entity1)];
|
||||
$classMetadata1->getReflectionProperty($property)->getValue($entity1)->add($entity2);
|
||||
$this->_classMetadatas[get_class($entity1)]
|
||||
->getReflectionProperty($property)
|
||||
->getValue($entity1)
|
||||
->add($entity2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -222,7 +250,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
*/
|
||||
private function isFieldSet($entity, $field)
|
||||
{
|
||||
return $this->_metadataMap[spl_object_hash($entity)]
|
||||
return $this->_classMetadatas[get_class($entity)]
|
||||
->getReflectionProperty($field)
|
||||
->getValue($entity) !== null;
|
||||
}
|
||||
@ -237,12 +265,13 @@ class ObjectHydrator extends AbstractHydrator
|
||||
private function setRelatedElement($entity1, $property, $entity2)
|
||||
{
|
||||
$oid = spl_object_hash($entity1);
|
||||
$classMetadata1 = $this->_metadataMap[$oid];
|
||||
$classMetadata1 = $this->_classMetadatas[get_class($entity1)];
|
||||
$classMetadata1->getReflectionProperty($property)->setValue($entity1, $entity2);
|
||||
$this->_uow->setOriginalEntityProperty($oid, $property, $entity2);
|
||||
$relation = $classMetadata1->getAssociationMapping($property);
|
||||
if ($relation->isOneToOne()) {
|
||||
$targetClass = $this->_em->getClassMetadata($relation->getTargetEntityName());
|
||||
//$targetClass = $this->_em->getClassMetadata($relation->getTargetEntityName());
|
||||
$targetClass = $this->_classMetadatas[$relation->getTargetEntityName()];
|
||||
if ($relation->isOwningSide()) {
|
||||
// If there is an inverse mapping on the target class its bidirectional
|
||||
if ($targetClass->hasInverseAssociationMapping($property)) {
|
||||
@ -291,7 +320,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
|
||||
// Get a reference to the right element in the result tree.
|
||||
// This element will get the associated element attached.
|
||||
if ($this->_parserResult->isMixedQuery() && isset($this->_rootAliases[$parent])) {
|
||||
if ($this->_resultSetMapping->isMixedResult() && isset($this->_rootAliases[$parent])) {
|
||||
$key = key(reset($this->_resultPointers));
|
||||
// TODO: Exception if $key === null ?
|
||||
$baseElement =& $this->_resultPointers[$parent][$key];
|
||||
@ -302,11 +331,11 @@ class ObjectHydrator extends AbstractHydrator
|
||||
continue;
|
||||
}
|
||||
|
||||
$oid = spl_object_hash($baseElement);
|
||||
$parentClass = get_class($baseElement);
|
||||
|
||||
// Check the type of the relation (many or single-valued)
|
||||
if ( ! $relation->isOneToOne()) {
|
||||
$oneToOne = false;
|
||||
//$oneToOne = false;
|
||||
if (isset($nonemptyComponents[$dqlAlias])) {
|
||||
$this->initRelatedCollection($baseElement, $relationAlias);
|
||||
$indexExists = isset($this->_identifierMap[$path][$id[$parent]][$id[$dqlAlias]]);
|
||||
@ -320,9 +349,10 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$this->addRelatedEntity($baseElement, $relationAlias, $element);
|
||||
}
|
||||
$this->_identifierMap[$path][$id[$parent]][$id[$dqlAlias]] = $this->getLastKey(
|
||||
$this->_metadataMap[$oid]
|
||||
$this->_classMetadatas[$parentClass]
|
||||
->getReflectionProperty($relationAlias)
|
||||
->getValue($baseElement));
|
||||
->getValue($baseElement)
|
||||
);
|
||||
}
|
||||
} else if ( ! $this->isFieldSet($baseElement, $relationAlias)) {
|
||||
$coll = new PersistentCollection($this->_em, $entityName);
|
||||
@ -330,7 +360,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$this->setRelatedElement($baseElement, $relationAlias, $coll);
|
||||
}
|
||||
} else {
|
||||
$oneToOne = true;
|
||||
//$oneToOne = true;
|
||||
if ( ! isset($nonemptyComponents[$dqlAlias]) &&
|
||||
! $this->isFieldSet($baseElement, $relationAlias)) {
|
||||
$this->setRelatedElement($baseElement, $relationAlias, null);
|
||||
@ -340,12 +370,12 @@ class ObjectHydrator extends AbstractHydrator
|
||||
}
|
||||
}
|
||||
|
||||
$coll = $this->_metadataMap[$oid]
|
||||
$coll = $this->_classMetadatas[$parentClass]
|
||||
->getReflectionProperty($relationAlias)
|
||||
->getValue($baseElement);
|
||||
|
||||
if ($coll !== null) {
|
||||
$this->updateResultPointer($coll, $index, $dqlAlias, $oneToOne);
|
||||
$this->updateResultPointer($coll, $index, $dqlAlias/*, $oneToOne*/);
|
||||
}
|
||||
} else {
|
||||
// Its a root result element
|
||||
@ -353,24 +383,22 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$this->_rootAliases[$dqlAlias] = true; // Mark as root alias
|
||||
|
||||
if ($this->_isSimpleQuery || ! isset($this->_identifierMap[$dqlAlias][$id[$dqlAlias]])) {
|
||||
$element = $this->_uow->createEntity($entityName, $rowData[$dqlAlias]);
|
||||
$oid = spl_object_hash($element);
|
||||
$this->_metadataMap[$oid] = $this->_em->getClassMetadata($entityName);
|
||||
$element = $this->getEntity($rowData[$dqlAlias], $entityName);
|
||||
if ($field = $this->_getCustomIndexField($dqlAlias)) {
|
||||
if ($this->_parserResult->isMixedQuery()) {
|
||||
if ($this->_resultSetMapping->isMixedResult()) {
|
||||
$result[] = array(
|
||||
$this->_metadataMap[$oid]
|
||||
$this->_classMetadatas[$entityName]
|
||||
->getReflectionProperty($field)
|
||||
->getValue($element) => $element
|
||||
);
|
||||
++$this->_resultCounter;
|
||||
} else {
|
||||
$result->set($element, $this->_metadataMap[$oid]
|
||||
$result->set($element, $this->_classMetadatas[$entityName]
|
||||
->getReflectionProperty($field)
|
||||
->getValue($element));
|
||||
}
|
||||
} else {
|
||||
if ($this->_parserResult->isMixedQuery()) {
|
||||
if ($this->_resultSetMapping->isMixedResult()) {
|
||||
$result[] = array($element);
|
||||
++$this->_resultCounter;
|
||||
} else {
|
||||
@ -381,7 +409,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
} else {
|
||||
$index = $this->_identifierMap[$dqlAlias][$id[$dqlAlias]];
|
||||
}
|
||||
$this->updateResultPointer($result, $index, $dqlAlias, false);
|
||||
$this->updateResultPointer($result, $index, $dqlAlias/*, false*/);
|
||||
//unset($rowData[$dqlAlias]);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,23 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Internal\Hydration;
|
||||
|
||||
@ -9,7 +28,7 @@ use \PDO;
|
||||
* The created result is almost the same as a regular SQL result set, except
|
||||
* that column names are mapped to field names and data type conversions.
|
||||
*
|
||||
* @author robo
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @since 2.0
|
||||
*/
|
||||
class ScalarHydrator extends AbstractHydrator
|
||||
|
@ -273,7 +273,8 @@ final class ClassMetadata
|
||||
* @var array
|
||||
* @see _discriminatorColumn
|
||||
*/
|
||||
private $_discriminatorMap = array();
|
||||
//private $_discriminatorMap = array();
|
||||
private $_discriminatorValue;
|
||||
|
||||
/**
|
||||
* The definition of the descriminator column used in JOINED and SINGLE_TABLE
|
||||
@ -825,6 +826,20 @@ final class ClassMetadata
|
||||
{
|
||||
return isset($this->_columnNames[$fieldName]);
|
||||
}
|
||||
|
||||
public function setValue($entity, $field, $value)
|
||||
{
|
||||
if (isset($this->_reflectionProperties[$field])) {
|
||||
$this->_reflectionProperties[$field]->setValue($entity, $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function setValueIfChanged($entity, $field, $value)
|
||||
{
|
||||
if (isset($this->_reflectionProperties[$field])) {
|
||||
$this->_reflectionProperties[$field]->setValue($entity, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all field mappings.
|
||||
@ -1500,25 +1515,25 @@ final class ClassMetadata
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the dsicriminator map used for mapping discriminator values to class names.
|
||||
* Sets the dsicriminator value used by this class.
|
||||
* Used for JOINED and SINGLE_TABLE inheritance mapping strategies.
|
||||
*
|
||||
* @param array $map
|
||||
*/
|
||||
public function setDiscriminatorMap(array $map)
|
||||
public function setDiscriminatorValue($value)
|
||||
{
|
||||
$this->_discriminatorMap = $map;
|
||||
$this->_discriminatorValue = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the discriminator map that maps discriminator values to class names.
|
||||
* Gets the discriminator value of this class.
|
||||
* Used for JOINED and SINGLE_TABLE inheritance mapping strategies.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDiscriminatorMap()
|
||||
public function getDiscriminatorValue()
|
||||
{
|
||||
return $this->_discriminatorMap;
|
||||
return $this->_discriminatorValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,7 +126,7 @@ class ClassMetadataFactory
|
||||
$class = $this->_newClassMetadataInstance($className);
|
||||
if ($parent) {
|
||||
$class->setInheritanceType($parent->getInheritanceType());
|
||||
$class->setDiscriminatorMap($parent->getDiscriminatorMap());
|
||||
//$class->setDiscriminatorMap($parent->getDiscriminatorMap());
|
||||
$class->setDiscriminatorColumn($parent->getDiscriminatorColumn());
|
||||
$class->setIdGeneratorType($parent->getIdGeneratorType());
|
||||
$this->_addInheritedFields($class, $parent);
|
||||
|
@ -75,11 +75,16 @@ class AnnotationDriver
|
||||
'length' => $discrColumnAnnot->length
|
||||
));
|
||||
}
|
||||
|
||||
/*
|
||||
// Evaluate DoctrineDiscriminatorMap annotation
|
||||
if ($discrMapAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorMap')) {
|
||||
$metadata->setDiscriminatorMap((array)$discrMapAnnot->value);
|
||||
}
|
||||
*/
|
||||
// Evaluate DoctrineDiscriminatorMap annotation
|
||||
if ($discrValueAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorValue')) {
|
||||
$metadata->setDiscriminatorValue($discrValueAnnot->value);
|
||||
}
|
||||
|
||||
// Evaluate DoctrineSubClasses annotation
|
||||
if ($subClassesAnnot = $annotClass->getAnnotation('DoctrineSubClasses')) {
|
||||
|
@ -31,6 +31,7 @@ final class DoctrineDiscriminatorColumn extends \Addendum\Annotation {
|
||||
public $length;
|
||||
}
|
||||
final class DoctrineDiscriminatorMap extends \Addendum\Annotation {}
|
||||
final class DoctrineDiscriminatorValue extends \Addendum\Annotation {}
|
||||
final class DoctrineSubClasses extends \Addendum\Annotation {}
|
||||
final class DoctrineId extends \Addendum\Annotation {}
|
||||
final class DoctrineGeneratedValue extends \Addendum\Annotation {
|
||||
|
@ -1,4 +1,23 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM;
|
||||
|
||||
@ -6,51 +25,60 @@ namespace Doctrine\ORM;
|
||||
* Represents a native SQL query.
|
||||
*
|
||||
* @since 2.0
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class NativeQuery
|
||||
class NativeQuery extends AbstractQuery
|
||||
{
|
||||
private $_sql;
|
||||
private $_conn;
|
||||
private $_params = array();
|
||||
|
||||
public function __construct($sql, Connection $conn)
|
||||
{
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the <tt>NativeQuery</tt> class that is bound
|
||||
* to the given EntityManager.
|
||||
*
|
||||
* @param EntityManager $em
|
||||
*/
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
parent::__construct($em);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SQL of the query.
|
||||
*
|
||||
* @param string $sql
|
||||
*/
|
||||
public function setSql($sql)
|
||||
{
|
||||
$this->_sql = $sql;
|
||||
$this->_conn = $conn;
|
||||
}
|
||||
|
||||
/*public function addScalar()
|
||||
|
||||
/**
|
||||
* Gets the SQL query/queries that correspond to this DQL query.
|
||||
*
|
||||
* @return mixed The built sql query or an array of all sql queries.
|
||||
* @override
|
||||
*/
|
||||
public function getSql()
|
||||
{
|
||||
|
||||
}*/
|
||||
|
||||
public function addEntity($alias, $className)
|
||||
{
|
||||
$this->_entities[$alias] = $className;
|
||||
return $this->_sql;
|
||||
}
|
||||
|
||||
public function addJoin($join)
|
||||
|
||||
/**
|
||||
* Executed the query.
|
||||
*
|
||||
* @param array $params
|
||||
* @return Statement The Statement handle.
|
||||
* @override
|
||||
*/
|
||||
protected function _doExecute(array $params)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function setParameter($key, $value)
|
||||
{
|
||||
$this->_params[$key] = $value;
|
||||
}
|
||||
|
||||
|
||||
public function execute(array $params)
|
||||
{
|
||||
if ($this->_entities) {
|
||||
//...
|
||||
} else {
|
||||
return $this->_conn->execute($this->_sql, array_merge($this->_params, $params));
|
||||
}
|
||||
}
|
||||
|
||||
public function executeUpdate(array $params)
|
||||
{
|
||||
return $this->_conn->exec($this->_sql, array_merge($this->_params, $params));
|
||||
// Assignments for Enums
|
||||
//$this->_setEnumParams($this->_parserResult->getEnumParams());
|
||||
|
||||
// Converting parameters
|
||||
$params = $this->_prepareParams($params);
|
||||
|
||||
// Executing the query and returning statement
|
||||
return $this->_em->getConnection()->execute($this->_sql, $params);
|
||||
}
|
||||
}
|
@ -244,13 +244,5 @@ abstract class AbstractEntityPersister
|
||||
$result[$columnName] = $type->convertToDatabaseValue($newVal, $this->_conn->getDatabasePlatform());
|
||||
}
|
||||
}
|
||||
/*
|
||||
// Populate the discriminator column on insert in JOINED & SINGLE_TABLE inheritance
|
||||
if ($isInsert && ($this->_classMetadata->isInheritanceTypeJoined() ||
|
||||
$this->_classMetadata->isInheritanceTypeSingleTable())) {
|
||||
$discColumn = $this->_classMetadata->getDiscriminatorColumn();
|
||||
$discMap = $this->_classMetadata->getDiscriminatorMap();
|
||||
$result[$discColumn['name']] = array_search($this->_entityName, $discMap);
|
||||
}*/
|
||||
}
|
||||
}
|
@ -18,8 +18,8 @@ class SingleTablePersister extends AbstractEntityPersister
|
||||
// Populate the discriminator column
|
||||
if ($isInsert) {
|
||||
$discColumn = $this->_classMetadata->getDiscriminatorColumn();
|
||||
$discMap = $this->_classMetadata->getDiscriminatorMap();
|
||||
$result[$discColumn['name']] = array_search($this->_entityName, $discMap);
|
||||
//$discMap = $this->_classMetadata->getDiscriminatorMap();
|
||||
$result[$discColumn['name']] = $this->_classMetadata->getDiscriminatorValue(); //array_search($this->_entityName, $discMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -46,31 +46,6 @@ abstract class AbstractResult
|
||||
*/
|
||||
protected $_enumParams = array();
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isMixedQuery = false;
|
||||
|
||||
/**
|
||||
* Gets whether the parsed query selects objects/arrays and scalar values
|
||||
* at the same time.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isMixedQuery()
|
||||
{
|
||||
return $this->_isMixedQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the parsed query selects objects/arrays and scalar values
|
||||
* at the same time.
|
||||
*/
|
||||
public function setMixedQuery($bool)
|
||||
{
|
||||
$this->_isMixedQuery = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enum parameters.
|
||||
*
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.org>.
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Query\Exec;
|
||||
|
@ -112,30 +112,12 @@ class Parser
|
||||
*/
|
||||
private $_query;
|
||||
|
||||
/**
|
||||
* Whether the query is a SELECT query and contains scalar values in the result list
|
||||
* as defined by the SelectExpressions.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_resultContainsScalars = false;
|
||||
|
||||
/**
|
||||
* Whether the query is a SELECT query and contains properties in the result list
|
||||
* as defined by the SelectExpressions.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_resultContainsProperties = false;
|
||||
|
||||
/**
|
||||
* Map of declared classes in the parsed query.
|
||||
* Maps the declared DQL alias (key) to the class name (value).
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
//private $_declaredClasses = array();
|
||||
|
||||
private $_queryComponents = array();
|
||||
|
||||
/**
|
||||
@ -656,10 +638,6 @@ class Parser
|
||||
$peek = $this->_lexer->glimpse();
|
||||
// First we recognize for an IdentificationVariable (DQL class alias)
|
||||
if ($peek['value'] != '.' && $peek['value'] != '(' && $this->_lexer->lookahead['type'] === Lexer::T_IDENTIFIER) {
|
||||
$this->_resultContainsProperties = true;
|
||||
if ($this->_resultContainsScalars) {
|
||||
$this->_parserResult->setMixedQuery(true);
|
||||
}
|
||||
$expression = $this->_IdentificationVariable();
|
||||
} else if (($isFunction = $this->_isFunction()) !== false || $this->_isSubselect()) {
|
||||
if ($isFunction) {
|
||||
@ -680,15 +658,7 @@ class Parser
|
||||
$this->match(Lexer::T_IDENTIFIER);
|
||||
$fieldIdentificationVariable = $this->_lexer->token['value'];
|
||||
}
|
||||
$this->_resultContainsScalars = true;
|
||||
if ($this->_resultContainsProperties) {
|
||||
$this->_parserResult->setMixedQuery(true);
|
||||
}
|
||||
} else {
|
||||
$this->_resultContainsProperties = true;
|
||||
if ($this->_resultContainsScalars) {
|
||||
$this->_parserResult->setMixedQuery(true);
|
||||
}
|
||||
//TODO: If hydration mode is OBJECT throw an exception ("partial object dangerous...")
|
||||
// unless the doctrine.forcePartialLoad query hint is set
|
||||
$expression = $this->_StateFieldPathExpression();
|
||||
|
@ -29,6 +29,8 @@ namespace Doctrine\ORM\Query;
|
||||
*/
|
||||
class ResultSetMapping
|
||||
{
|
||||
/** Whether the result is mixed (contains scalar values together with field values). */
|
||||
private $_isMixed = false;
|
||||
/** Maps alias names to ClassMetadata descriptors. */
|
||||
private $_aliasMap = array();
|
||||
/** Maps alias names to related association mappings. */
|
||||
@ -41,10 +43,12 @@ class ResultSetMapping
|
||||
private $_scalarMappings = array();
|
||||
/** Maps column names in the result set to the alias they belong to. */
|
||||
private $_columnOwnerMap = array();
|
||||
/** Maps discriminator columns in the result set to the class they represent. */
|
||||
private $_discriminatorMap = array();
|
||||
/** List of columns in the result set that are used as discriminator columns. */
|
||||
private $_discriminatorColumns = array();
|
||||
/** Maps alias names to field names that should be used for indexing. */
|
||||
private $_indexByMap = array();
|
||||
/** A list of columns that should be ignored/skipped during hydration. */
|
||||
private $_ignoredColumns = array();
|
||||
|
||||
/**
|
||||
*
|
||||
@ -52,12 +56,21 @@ class ResultSetMapping
|
||||
* @param <type> $alias The alias for this class. The alias must be unique within this ResultSetMapping.
|
||||
* @param <type> $discriminatorColumn
|
||||
*/
|
||||
public function addEntityResult($class, $alias, $discriminatorColumn = null)
|
||||
public function addEntityResult($class, $alias)
|
||||
{
|
||||
$this->_aliasMap[$alias] = $class;
|
||||
if ($discriminatorColumn !== null) {
|
||||
$this->_discriminatorMap[$discriminatorColumn] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
public function setDiscriminatorColumn($className, $alias, $discrColumn)
|
||||
{
|
||||
$this->_discriminatorColumns[$className] = $discrColumn;
|
||||
$this->_columnOwnerMap[$discrColumn] = $alias;
|
||||
}
|
||||
|
||||
public function getDiscriminatorColumn($className)
|
||||
{
|
||||
return isset($this->_discriminatorColumns[$className]) ?
|
||||
$this->_discriminatorColumns[$className] : null;
|
||||
}
|
||||
|
||||
public function addIndexBy($alias, $fieldName)
|
||||
@ -75,30 +88,38 @@ class ResultSetMapping
|
||||
return $this->_indexByMap[$alias];
|
||||
}
|
||||
|
||||
public function isFieldResult($columnName)
|
||||
{
|
||||
return isset($this->_fieldMappings[$columnName]);
|
||||
}
|
||||
|
||||
public function addFieldResult($alias, $columnName, $fieldName)
|
||||
{
|
||||
$this->_fieldMappings[$columnName] = $fieldName;
|
||||
$this->_columnOwnerMap[$columnName] = $alias;
|
||||
if ( ! $this->_isMixed && $this->_scalarMappings) {
|
||||
$this->_isMixed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function addJoinedEntityResult($class, $alias, $parentAlias, $relation, $discriminatorColumn = null)
|
||||
public function addJoinedEntityResult($class, $alias, $parentAlias, $relation)
|
||||
{
|
||||
$this->_aliasMap[$alias] = $class;
|
||||
$this->_parentAliasMap[$alias] = $parentAlias;
|
||||
$this->_relationMap[$alias] = $relation;
|
||||
if ($discriminatorColumn !== null) {
|
||||
$this->_discriminatorMap[$discriminatorColumn] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
public function isDiscriminatorColumn($columnName)
|
||||
/*public function isDiscriminatorColumn($columnName)
|
||||
{
|
||||
return isset($this->_discriminatorMap[$columnName]);
|
||||
}
|
||||
}*/
|
||||
|
||||
public function addScalarResult($columnName, $alias)
|
||||
{
|
||||
$this->_scalarMappings[$columnName] = $alias;
|
||||
if ( ! $this->_isMixed && $this->_fieldMappings) {
|
||||
$this->_isMixed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,9 +136,6 @@ class ResultSetMapping
|
||||
*/
|
||||
public function getClass($alias)
|
||||
{
|
||||
if ( ! isset($this->_aliasMap[$alias])) {
|
||||
var_dump($alias); die();
|
||||
}
|
||||
return $this->_aliasMap[$alias];
|
||||
}
|
||||
|
||||
@ -192,5 +210,20 @@ class ResultSetMapping
|
||||
{
|
||||
return count($this->_aliasMap);
|
||||
}
|
||||
|
||||
public function isMixedResult()
|
||||
{
|
||||
return $this->_isMixed;
|
||||
}
|
||||
|
||||
public function addIgnoredColumn($columnName)
|
||||
{
|
||||
$this->_ignoredColumns[$columnName] = true;
|
||||
}
|
||||
|
||||
public function isIgnoredColumn($columnName)
|
||||
{
|
||||
return isset($this->_ignoredColumns[$columnName]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,20 +64,12 @@ class SqlWalker
|
||||
$this->_em = $query->getEntityManager();
|
||||
$this->_parserResult = $parserResult;
|
||||
$this->_queryComponents = $queryComponents;
|
||||
/*$sqlToDqlAliasMap = array(Parser::SCALAR_QUERYCOMPONENT_ALIAS => Parser::SCALAR_QUERYCOMPONENT_ALIAS);
|
||||
foreach ($parserResult->getQueryComponents() as $dqlAlias => $qComp) {
|
||||
$sqlAlias = $this->generateSqlTableAlias($qComp['metadata']->getTableName());
|
||||
$sqlToDqlAliasMap[$sqlAlias] = $dqlAlias;
|
||||
}
|
||||
// SQL => DQL alias stored in ParserResult, needed for hydration.
|
||||
$parserResult->setTableAliasMap($sqlToDqlAliasMap);*/
|
||||
// DQL => SQL alias stored only locally, needed for SQL construction.
|
||||
//$this->_dqlToSqlAliasMap = array_flip($sqlToDqlAliasMap);
|
||||
|
||||
// In a mixed query we start alias counting for scalars with 1 since
|
||||
// index 0 will hold the object.
|
||||
if ($parserResult->isMixedQuery()) {
|
||||
/*if ($parserResult->isMixedQuery()) {
|
||||
$this->_scalarResultCounter = 1;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public function getConnection()
|
||||
@ -99,7 +91,6 @@ class SqlWalker
|
||||
$sql .= $AST->getHavingClause() ? $this->walkHavingClause($AST->getHavingClause()) : '';
|
||||
$sql .= $AST->getOrderByClause() ? $this->walkOrderByClause($AST->getOrderByClause()) : '';
|
||||
|
||||
//... more clauses
|
||||
return $sql;
|
||||
}
|
||||
|
||||
@ -113,16 +104,6 @@ class SqlWalker
|
||||
$sql = 'SELECT ' . (($selectClause->isDistinct()) ? 'DISTINCT ' : '')
|
||||
. implode(', ', array_map(array($this, 'walkSelectExpression'),
|
||||
$selectClause->getSelectExpressions()));
|
||||
// Append discriminator columns
|
||||
/*if ($this->_query->getHydrationMode() == \Doctrine\ORM\Query::HYDRATE_OBJECT) {
|
||||
foreach ($this->_selectedClasses as $dqlAlias => $class) {
|
||||
if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()) {
|
||||
$tblAlias = $this->_dqlToSqlAliasMap[$dqlAlias];
|
||||
$discrColumn = $class->getDiscriminatorColumn();
|
||||
$sql .= ", $tblAlias." . $discrColumn['name'] . ' AS discr__' . $discrColumn['name'];
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
foreach ($this->_selectedClasses as $dqlAlias => $class) {
|
||||
if ($this->_queryComponents[$dqlAlias]['relation'] === null) {
|
||||
@ -134,6 +115,15 @@ class SqlWalker
|
||||
$this->_queryComponents[$dqlAlias]['relation']
|
||||
);
|
||||
}
|
||||
//if ($this->_query->getHydrationMode() == \Doctrine\ORM\Query::HYDRATE_OBJECT) {
|
||||
if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()) {
|
||||
$tblAlias = $this->getSqlTableAlias($class->getTableName());
|
||||
$discrColumn = $class->getDiscriminatorColumn();
|
||||
$columnAlias = $this->getSqlColumnAlias($discrColumn['name']);
|
||||
$sql .= ", $tblAlias." . $discrColumn['name'] . ' AS ' . $columnAlias;
|
||||
$this->_resultSetMapping->setDiscriminatorColumn($class->getClassName(), $dqlAlias, $columnAlias);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
|
@ -1173,15 +1173,6 @@ class UnitOfWork implements PropertyChangedListener
|
||||
*/
|
||||
public function createEntity($className, array $data, $query = null)
|
||||
{
|
||||
// Infer the correct class to instantiate
|
||||
$class = $this->_em->getClassMetadata($className);
|
||||
$discCol = $class->getDiscriminatorColumn();
|
||||
if ($discCol) {
|
||||
$discMap = $class->getDiscriminatorMap();
|
||||
if (isset($data[$discCol['name']], $discMap[$data[$discCol['name']]])) {
|
||||
$className = $discMap[$data[$discCol['name']]];
|
||||
}
|
||||
}
|
||||
$class = $this->_em->getClassMetadata($className);
|
||||
|
||||
$id = array();
|
||||
@ -1232,15 +1223,17 @@ class UnitOfWork implements PropertyChangedListener
|
||||
private function _mergeData($entity, array $data, $class, $overrideLocalChanges = false) {
|
||||
if ($overrideLocalChanges) {
|
||||
foreach ($data as $field => $value) {
|
||||
$class->getReflectionProperty($field)->setValue($entity, $value);
|
||||
$class->setValue($entity, $field, $value);
|
||||
}
|
||||
} else {
|
||||
$oid = spl_object_hash($entity);
|
||||
foreach ($data as $field => $value) {
|
||||
$currentValue = $class->getReflectionProperty($field)->getValue($entity);
|
||||
if ( ! isset($this->_originalEntityData[$oid][$field]) ||
|
||||
if ($class->hasField($field)) {
|
||||
$currentValue = $class->getReflectionProperty($field)->getValue($entity);
|
||||
if ( ! isset($this->_originalEntityData[$oid][$field]) ||
|
||||
$currentValue == $this->_originalEntityData[$oid][$field]) {
|
||||
$class->getReflectionProperty($field)->setValue($entity, $value);
|
||||
$class->getReflectionProperty($field)->setValue($entity, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,12 +5,6 @@ namespace Doctrine\Tests\Models\Forum;
|
||||
/**
|
||||
* @DoctrineEntity
|
||||
* @DoctrineTable(name="forum_users")
|
||||
* @DoctrineInheritanceType("joined")
|
||||
* @DoctrineDiscriminatorColumn(name="dtype", type="varchar", length=20)
|
||||
* @DoctrineDiscriminatorMap({
|
||||
"user" = "Doctrine\Tests\Models\Forum\ForumUser",
|
||||
"admin" = "Doctrine\Tests\Models\Forum\ForumAdministrator"})
|
||||
* @DoctrineSubclasses({"Doctrine\Tests\Models\Forum\ForumAdministrator"})
|
||||
*/
|
||||
class ForumUser
|
||||
{
|
||||
|
@ -70,8 +70,5 @@ class EntityPersisterTest extends \Doctrine\Tests\OrmTestCase
|
||||
//avatar_id join column
|
||||
$this->assertTrue(isset($inserts['forum_users'][0]['avatar_id']));
|
||||
$this->assertEquals(0, $inserts['forum_users'][0]['avatar_id']);
|
||||
//dtype discriminator column
|
||||
$this->assertTrue(isset($inserts['forum_users'][0]['dtype']));
|
||||
$this->assertEquals('user', $inserts['forum_users'][0]['dtype']);
|
||||
}
|
||||
}
|
@ -20,6 +20,8 @@ class AllTests
|
||||
$suite = new \Doctrine\Tests\OrmFunctionalTestSuite('Doctrine Orm Functional');
|
||||
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\BasicFunctionalTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\NativeQueryTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\SingleTableInheritanceTest');
|
||||
|
||||
return $suite;
|
||||
}
|
||||
|
45
tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php
Normal file
45
tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
/**
|
||||
* NativeQueryTest
|
||||
*
|
||||
* @author robo
|
||||
*/
|
||||
class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp() {
|
||||
$this->useModelSet('cms');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testBasicNativeQuery()
|
||||
{
|
||||
$user = new CmsUser;
|
||||
$user->name = 'Roman';
|
||||
$user->username = 'romanb';
|
||||
$user->status = 'dev';
|
||||
$this->_em->save($user);
|
||||
$this->_em->flush();
|
||||
|
||||
$rsm = new ResultSetMapping;
|
||||
$rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u');
|
||||
$rsm->addFieldResult('u', 'id', 'id');
|
||||
$rsm->addFieldResult('u', 'name', 'name');
|
||||
|
||||
$query = $this->_em->createNativeQuery('SELECT id, name FROM cms_users WHERE username = ?', $rsm);
|
||||
$query->setParameter(1, 'romanb');
|
||||
|
||||
$users = $query->getResultList();
|
||||
|
||||
$this->assertEquals(1, count($users));
|
||||
$this->assertEquals('Roman', $users[0]->name);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
/**
|
||||
* Functional tests for the Single Table Inheritance mapping strategy.
|
||||
*
|
||||
* @author robo
|
||||
*/
|
||||
class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ParentEntity'),
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ChildEntity')
|
||||
));
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
|
||||
$parent = new ParentEntity;
|
||||
$parent->setData('foobar');
|
||||
|
||||
$this->_em->save($parent);
|
||||
|
||||
$child = new ChildEntity;
|
||||
$child->setData('thedata');
|
||||
$child->setNumber(1234);
|
||||
|
||||
$this->_em->save($child);
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$query = $this->_em->createQuery("select e from Doctrine\Tests\ORM\Functional\ParentEntity e");
|
||||
|
||||
$entities = $query->getResultList();
|
||||
|
||||
$this->assertEquals(2, count($entities));
|
||||
$this->assertTrue($entities[0] instanceof ParentEntity);
|
||||
$this->assertTrue($entities[1] instanceof ChildEntity);
|
||||
$this->assertEquals('foobar', $entities[0]->getData());
|
||||
$this->assertEquals('thedata', $entities[1]->getData());
|
||||
$this->assertEquals(1234, $entities[1]->getNumber());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @DoctrineEntity
|
||||
* @DoctrineInheritanceType("singleTable")
|
||||
* @DoctrineDiscriminatorColumn(name="discr", type="varchar")
|
||||
* @DoctrineSubClasses({"Doctrine\Tests\ORM\Functional\ChildEntity"})
|
||||
* @DoctrineDiscriminatorValue("parent")
|
||||
*/
|
||||
class ParentEntity {
|
||||
/**
|
||||
* @DoctrineId
|
||||
* @DoctrineColumn(type="integer")
|
||||
* @DoctrineGeneratedValue(strategy="auto")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @DoctrineColumn(type="varchar")
|
||||
*/
|
||||
private $data;
|
||||
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setData($data) {
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @DoctrineEntity
|
||||
* @DoctrineDiscriminatorValue("child")
|
||||
*/
|
||||
class ChildEntity extends ParentEntity {
|
||||
/**
|
||||
* @DoctrineColumn(type="integer", nullable=true)
|
||||
*/
|
||||
private $number;
|
||||
|
||||
public function getNumber() {
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
public function setNumber($number) {
|
||||
$this->number = $number;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class ArrayHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -78,7 +78,7 @@ class ArrayHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(4, count($result));
|
||||
|
||||
@ -140,7 +140,7 @@ class ArrayHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -192,7 +192,7 @@ class ArrayHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -255,7 +255,7 @@ class ArrayHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -365,7 +365,7 @@ class ArrayHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -505,7 +505,7 @@ class ArrayHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -618,7 +618,7 @@ class ArrayHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -653,7 +653,7 @@ class ArrayHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em);
|
||||
|
||||
$iterableResult = $hydrator->iterate($stmt, $this->_createParserResult($rsm));
|
||||
$iterableResult = $hydrator->iterate($stmt, $rsm);
|
||||
|
||||
$rowNum = 0;
|
||||
while (($row = $iterableResult->next()) !== false) {
|
||||
|
@ -35,7 +35,7 @@ class ObjectHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\CMS\CmsUser);
|
||||
@ -79,7 +79,7 @@ class ObjectHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(4, count($result));
|
||||
|
||||
@ -146,7 +146,7 @@ class ObjectHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -205,7 +205,7 @@ class ObjectHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -270,7 +270,7 @@ class ObjectHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -384,7 +384,7 @@ class ObjectHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -519,7 +519,7 @@ class ObjectHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
@ -626,7 +626,7 @@ class ObjectHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\Forum\ForumCategory);
|
||||
@ -663,7 +663,7 @@ class ObjectHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
|
||||
$iterableResult = $hydrator->iterate($stmt, $this->_createParserResult($rsm));
|
||||
$iterableResult = $hydrator->iterate($stmt, $rsm);
|
||||
|
||||
$rowNum = 0;
|
||||
while (($row = $iterableResult->next()) !== false) {
|
||||
@ -739,6 +739,6 @@ class ObjectHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm, true));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
}
|
||||
}
|
@ -35,7 +35,7 @@ class ScalarHydratorTest extends HydrationTest
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em);
|
||||
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEquals(2, count($result));
|
||||
|
@ -63,14 +63,14 @@ class SingleScalarHydratorTest extends HydrationTest
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\SingleScalarHydrator($this->_em);
|
||||
|
||||
if ($name == 'result1') {
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
$this->assertEquals('romanb', $result);
|
||||
} else if ($name == 'result2') {
|
||||
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult($rsm));
|
||||
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||
$this->assertEquals(1, $result);
|
||||
} else if ($name == 'result3' || $name == 'result4') {
|
||||
try {
|
||||
$result = $hydrator->hydrateall($stmt, $this->_createParserResult($rsm));
|
||||
$result = $hydrator->hydrateall($stmt, $rsm);
|
||||
$this->fail();
|
||||
} catch (\Doctrine\ORM\Internal\Hydration\HydrationException $ex) {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user