Compare commits

...

45 Commits
2.3.1 ... 2.3.3

Author SHA1 Message Date
Benjamin Eberlei
b3788c14ee Release 2.3.3 2013-03-24 21:43:58 +01:00
Benjamin Eberlei
3148d8aeac Bump Dbal Dependency to 2.3.3 2013-03-24 20:21:32 +01:00
Benjamin Eberlei
ae1f903080 Merge branch 'DDC-2090' into 2.3 2013-03-17 21:49:24 +01:00
Fabio B. Silva
07482bd624 Fix DDC-2090 2013-03-17 21:48:55 +01:00
Benjamin Eberlei
8d78b90bca Merge branch 'DDC-1666' into 2.3 2013-03-14 23:42:28 +01:00
Benjamin Eberlei
ca93400493 [DDC-1666] Fix bug where orphan removal on one-to-one associations lead to unique constraint errors when replacing an entity with a new one. 2013-03-14 23:42:04 +01:00
Benjamin Eberlei
7152e5f72f Merge branch 'DDC-2300' into 2.3 2013-03-14 23:22:01 +01:00
Benjamin Eberlei
279fcb6c81 [DDC-2300] Fix version xml mapping and serialization of ClassMetadata. 2013-03-14 23:20:46 +01:00
Benjamin Eberlei
7705105c5d Merge branch 'GH-593' into 2.3 2013-03-14 22:59:42 +01:00
Norbert Orzechowicz
cb70a8a8c4 Fix SimpleObjectHydrator behavior when column not exists in fieldMappings, relationMappings and metaMappings 2013-03-14 22:59:20 +01:00
Benjamin Eberlei
8a2d7374b1 Fix bugs in tests 2013-03-14 20:08:37 +01:00
Benjamin Eberlei
563fdb953b Merge branch 'DDC-2340' into 2.3 2013-03-12 22:53:10 +01:00
Benjamin Eberlei
3daf824c9e [DDC-2340] Fix bug with dirty collection matching + ordering. 2013-03-12 22:52:52 +01:00
Jean-Guilhem Rouel
aa4664687f Don't add empty expression to another one 2013-03-12 19:18:07 +01:00
Benjamin Eberlei
550c1cf98c Merge branch 'GH-572' into 2.3 2013-03-12 19:06:02 +01:00
Norbert Orzechowicz
33799d094c [DDC-2282] Fix pagination problem with SQL Server.
ORDER BY removed from all count queries when on SQL Server
Fixed SQLServer ORDER BY problem in paginator CountOutputWalker
Added test to check query with ORDER BY and SQLServerPlatform
2013-03-12 19:05:28 +01:00
Benjamin Eberlei
304acf0a1a Merge branch 'DDC-2310' into 2.3 2013-02-21 19:03:42 +01:00
Benjamin Eberlei
84996e0601 [DDC-2310] Fix regression introduced in SQL Server lock handling. 2013-02-21 19:03:12 +01:00
Benjamin Eberlei
fdd0af34e6 Merge branch 'DDC-2243' into 2.3 2013-01-20 20:35:21 +01:00
Benjamin Eberlei
f0312edb94 [DDC-2243] Fix bug where a bigint identifier would be casted to an integer, causing inconsistency with the string handling. 2013-01-20 20:34:09 +01:00
Benjamin Eberlei
6d25c4e08a Merge remote-tracking branch 'origin/2.3' into 2.3 2013-01-20 20:12:44 +01:00
Benjamin Eberlei
d9f51eb2fa Merge branch 'DDC-2246' into 2.3 2013-01-20 20:12:35 +01:00
Benjamin Eberlei
88cebe1263 [DDC-2246] Fix bug with UnitOfWork#getEntityState() and entities with foreign identifier. 2013-01-20 20:11:40 +01:00
Benjamin Eberlei
6829c464e8 Merge branch 'DDC-2231' into 2.3 2013-01-12 10:32:44 +01:00
Benjamin Eberlei
fc2eebdf75 DDC-2231 - Simplify test 2013-01-12 10:32:24 +01:00
Stefan Kleff
54193e7f82 Added test 2013-01-12 10:32:24 +01:00
Stefan Kleff
8001cad573 fixed indentation
Restored old way of injection to just inject it during a refresh
Added injection for initialized proxies
2013-01-12 10:32:24 +01:00
Stefan Kleff
c4c70d667a The EntityManager was not injected in uninitialized proxys which are ObjectManagerAware.
I ran into that problem while I had two objects in the identitymap while hydrating a collection: one was new a "real" entity and the other one was an uninitialized proxy. For "real" entities the em is injected in line 2427, for new entities it is injected in 2436->2364, but for proxies this is missing. According to the comment "inject ObjectManager into just loaded proxies." the code in line 2427 should do this, but in fact it is just used if it is a "real" entity or an already initialized proxy. Moving the injection to outside of the condition in line 2411 (if the entity is an unitialized proxy) solves this.
2013-01-12 10:32:24 +01:00
Benjamin Eberlei
f5bb8be884 Bump dev version to 2.3.3 2013-01-07 21:05:04 +01:00
Benjamin Eberlei
c5725dd6bb Release 2.3.2 2013-01-07 21:05:04 +01:00
Benjamin Eberlei
b59cd047ff Bump submodule of DBAL to 2.3.2 2013-01-07 21:04:49 +01:00
Benjamin Eberlei
019094655b Merge branch 'DDC-2175' into 2.3 2012-12-24 11:18:12 +01:00
Benjamin Eberlei
88e817660c [DDC-2175] Fix bug in JoinedSubclassPersister 2012-12-24 11:14:18 +01:00
Benjamin Eberlei
aee75d8f25 Merge branch '2.3' of github.com:doctrine/doctrine2 into 2.3 2012-12-23 20:34:54 +01:00
Benjamin Eberlei
50132ddc18 Merge branch 'DDC-2206' into 2.3 2012-12-23 20:34:14 +01:00
Benjamin Eberlei
f05bcbc17c [DDC-2206] Fix Setup::registerAutoloadPEAR() to work with Symfony namespaces from top PEAR directory 2012-12-23 20:33:21 +01:00
Benjamin Eberlei
f94b6c07c7 Fix MySQL test 2012-12-22 21:50:42 +01:00
Benjamin Eberlei
b68c6b3d2d Merge branch 'DDC-1690' into 2.3 2012-12-22 12:46:06 +01:00
Patrick Schwisow
0425e8452d [DDC-1690] Added an empty line as requested. 2012-12-22 12:37:03 +01:00
Patrick Schwisow
c120700d89 [DDC-1690] Created unit test 2012-12-22 12:37:02 +01:00
Patrick Schwisow
22dc20c320 Fix DDC-1690
Added the lines suggested by the original reporter.
2012-12-22 12:37:02 +01:00
Benjamin Eberlei
6d89875306 Merge remote-tracking branch 'origin/2.3' into 2.3 2012-12-16 13:00:27 +01:00
Benjamin Eberlei
b666a62979 Merge branch 'DDC-2199' into 2.3 2012-12-16 12:58:46 +01:00
Benjamin Eberlei
f2f8c4f2dd DDC-2199 / DDC-2192 - Versioned fields didnt work in XML/YAML mapping 2012-12-16 12:58:17 +01:00
Benjamin Eberlei
59aef2ca95 Bump dev version to 2.3.2 2012-12-04 23:04:25 +01:00
35 changed files with 795 additions and 114 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "doctrine/orm",
"type": "library","version":"2.3.1",
"type": "library","version":"2.3.3",
"description": "Object-Relational-Mapper for PHP",
"keywords": ["orm", "database"],
"homepage": "http://www.doctrine-project.org",

View File

@@ -0,0 +1,66 @@
<?php
/*
* 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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM\Id;
use Doctrine\ORM\EntityManager;
/**
* Id generator that obtains IDs from special "identity" columns. These are columns
* that automatically get a database-generated, auto-incremented identifier on INSERT.
* This generator obtains the last insert id after such an insert.
*/
class BigIntegerIdentityGenerator extends AbstractIdGenerator
{
/**
* The name of the sequence to pass to lastInsertId(), if any.
*
* @var string
*/
private $sequenceName;
/**
* Constructor.
*
* @param string|null $seqName The name of the sequence to pass to lastInsertId()
* to obtain the last generated identifier within the current
* database session/connection, if any.
*/
public function __construct($sequenceName = null)
{
$this->sequenceName = $sequenceName;
}
/**
* {@inheritdoc}
*/
public function generate(EntityManager $em, $entity)
{
return (string)$em->getConnection()->lastInsertId($this->sequenceName);
}
/**
* {@inheritdoc}
*/
public function isPostInsertGenerator()
{
return true;
}
}

View File

@@ -28,17 +28,21 @@ use Doctrine\ORM\EntityManager;
*/
class IdentityGenerator extends AbstractIdGenerator
{
/** @var string The name of the sequence to pass to lastInsertId(), if any. */
private $_seqName;
/**
* The name of the sequence to pass to lastInsertId(), if any.
*
* @var string
*/
private $sequenceName;
/**
* @param string $seqName The name of the sequence to pass to lastInsertId()
* to obtain the last generated identifier within the current
* database session/connection, if any.
*/
public function __construct($seqName = null)
public function __construct($sequenceName = null)
{
$this->_seqName = $seqName;
$this->sequenceName = $sequenceName;
}
/**
@@ -46,7 +50,7 @@ class IdentityGenerator extends AbstractIdGenerator
*/
public function generate(EntityManager $em, $entity)
{
return (int)$em->getConnection()->lastInsertId($this->_seqName);
return (int)$em->getConnection()->lastInsertId($this->sequenceName);
}
/**

View File

@@ -178,10 +178,13 @@ class SimpleObjectHydrator extends AbstractHydrator
// One solution is to load the association, but it might require extra efforts.
return array('name' => $column);
default:
case (isset($this->_rsm->metaMappings[$column])):
return array(
'name' => $this->_rsm->metaMappings[$column]
);
default:
return null;
}
}
}

View File

@@ -19,16 +19,17 @@
namespace Doctrine\ORM\Mapping;
use ReflectionException,
Doctrine\ORM\ORMException,
Doctrine\ORM\EntityManager,
Doctrine\DBAL\Platforms,
Doctrine\ORM\Events,
Doctrine\Common\Persistence\Mapping\ReflectionService,
Doctrine\Common\Persistence\Mapping\ClassMetadata as ClassMetadataInterface,
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory,
Doctrine\ORM\Id\IdentityGenerator,
Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use ReflectionException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\EntityManager;
use Doctrine\DBAL\Platforms;
use Doctrine\ORM\Events;
use Doctrine\Common\Persistence\Mapping\ReflectionService;
use Doctrine\Common\Persistence\Mapping\ClassMetadata as ClassMetadataInterface;
use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\ORM\Id\IdentityGenerator;
use Doctrine\ORM\Id\BigIntegerIdentityGenerator;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
/**
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
@@ -418,9 +419,9 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
// <table>_<column>_seq in PostgreSQL for SERIAL columns.
// Not pretty but necessary and the simplest solution that currently works.
$sequenceName = null;
$fieldName = $class->identifier ? $class->getSingleIdentifierFieldName() : null;
if ($this->targetPlatform instanceof Platforms\PostgreSQLPlatform) {
$fieldName = $class->getSingleIdentifierFieldName();
$columnName = $class->getSingleIdentifierColumnName();
$quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']);
$sequenceName = $class->getTableName() . '_' . $columnName . '_seq';
@@ -435,7 +436,12 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
$sequenceName = $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->targetPlatform);
}
$class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($sequenceName));
$generator = ($fieldName && $class->fieldMappings[$fieldName]['type'] === "bigint")
? new BigIntegerIdentityGenerator($sequenceName)
: new IdentityGenerator($sequenceName);
$class->setIdGenerator($generator);
break;
case ClassMetadata::GENERATOR_TYPE_SEQUENCE:

View File

@@ -1421,6 +1421,10 @@ class ClassMetadataInfo implements ClassMetadata
$mapping['orphanRemoval'] = isset($mapping['orphanRemoval']) ? (bool) $mapping['orphanRemoval'] : false;
$mapping['isCascadeRemove'] = $mapping['orphanRemoval'] ? true : $mapping['isCascadeRemove'];
if ($mapping['orphanRemoval']) {
unset($mapping['unique']);
}
if (isset($mapping['id']) && $mapping['id'] === true && !$mapping['isOwningSide']) {
throw MappingException::illegalInverseIdentifierAssocation($this->name, $mapping['fieldName']);
}

View File

@@ -230,12 +230,22 @@ class XmlDriver extends FileDriver
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $fieldMapping) {
$mapping = $this->columnToArray($fieldMapping);
if (isset($mapping['version'])) {
$metadata->setVersionMapping($mapping);
unset($mapping['version']);
}
$metadata->mapField($mapping);
}
}
foreach ($mappings as $mapping) {
$metadata->mapField($mapping);
if (isset($mapping['version'])) {
$metadata->setVersionMapping($mapping);
}
$metadata->mapField($mapping);
}
// Evaluate <id ...> mappings
@@ -653,7 +663,7 @@ class XmlDriver extends FileDriver
}
if (isset($fieldMapping['version']) && $fieldMapping['version']) {
$mapping['version'] = $fieldMapping['version'];
$mapping['version'] = $this->evaluateBoolean($fieldMapping['version']);
}
if (isset($fieldMapping['column-definition'])) {

View File

@@ -297,6 +297,11 @@ class YamlDriver extends FileDriver
}
}
if (isset($mapping['version'])) {
$metadata->setVersionMapping($mapping);
unset($mapping['version']);
}
$metadata->mapField($mapping);
}
}

View File

@@ -805,6 +805,10 @@ final class PersistentCollection implements Collection, Selectable
*/
public function matching(Criteria $criteria)
{
if ($this->isDirty) {
$this->initialize();
}
if ($this->initialized) {
return $this->coll->matching($criteria);
}
@@ -813,16 +817,10 @@ final class PersistentCollection implements Collection, Selectable
throw new \RuntimeException("Matching Criteria on PersistentCollection only works on OneToMany assocations at the moment.");
}
// If there are NEW objects we have to check if any of them matches the criteria
$newObjects = array();
if ($this->isDirty) {
$newObjects = $this->coll->matching($criteria)->toArray();
}
$targetClass = $this->em->getClassMetadata(get_class($this->owner));
$id = $targetClass->getSingleIdReflectionProperty()->getValue($this->owner);
$id = $this->em
->getClassMetadata(get_class($this->owner))
->getSingleIdReflectionProperty()
->getValue($this->owner);
$builder = Criteria::expr();
$ownerExpression = $builder->eq($this->backRefFieldName, $id);
$expression = $criteria->getWhereExpression();
@@ -832,7 +830,7 @@ final class PersistentCollection implements Collection, Selectable
$persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']);
return new ArrayCollection(array_merge($persister->loadCriteria($criteria), $newObjects));
return new ArrayCollection($persister->loadCriteria($criteria));
}
}

View File

@@ -227,8 +227,10 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
// Make sure the table with the version column is updated even if no columns on that
// table were affected.
if ($isVersioned && ! isset($updateData[$versionedTable])) {
$this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass, $this->_platform), array(), true);
if ($isVersioned) {
if ( ! isset($updateData[$versionedTable])) {
$this->_updateTable($entity, $this->quoteStrategy->getTableName($versionedClass, $this->_platform), array(), true);
}
$id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
$this->assignDefaultVersionValue($entity, $id);

View File

@@ -104,19 +104,8 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
$updateSql .= $sqlWalker->walkUpdateItem($updateItem);
//FIXME: parameters can be more deeply nested. traverse the tree.
//FIXME (URGENT): With query cache the parameter is out of date. Move to execute() stage.
if ($newValue instanceof AST\InputParameter) {
$parameterName = $newValue->name;
$parameter = $sqlWalker->getQuery()->getParameter($parameterName);
$value = $sqlWalker->getQuery()->processParameterValue($parameter->getValue());
$type = ($parameter->getValue() === $value)
? $parameter->getType()
: ParameterTypeInferer::inferType($value);
$this->_sqlParameters[$i]['parameters'][] = $value;
$this->_sqlParameters[$i]['types'][] = $type;
$this->_sqlParameters[$i][] = $newValue->name;
++$this->_numParametersInUpdateClause;
}
@@ -168,16 +157,18 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
);
// Execute UPDATE statements
for ($i=0, $count=count($this->_sqlStatements); $i<$count; ++$i) {
$parameters = array();
$types = array();
foreach ($this->_sqlStatements as $key => $statement) {
$paramValues = array();
$paramTypes = array();
if (isset($this->_sqlParameters[$i])) {
$parameters = isset($this->_sqlParameters[$i]['parameters']) ? $this->_sqlParameters[$i]['parameters'] : array();
$types = isset($this->_sqlParameters[$i]['types']) ? $this->_sqlParameters[$i]['types'] : array();
if (isset($this->_sqlParameters[$key])) {
foreach ($this->_sqlParameters[$key] as $parameterKey => $parameterName) {
$paramValues[] = $params[$parameterKey];
$paramTypes[] = isset($types[$parameterKey]) ? $types[$parameterKey] : ParameterTypeInferer::inferType($params[$parameterKey]);
}
}
$conn->executeUpdate($this->_sqlStatements[$i], $parameters, $types);
$conn->executeUpdate($statement, $paramValues, $paramTypes);
}
} catch (\Exception $exception) {
// FAILURE! Drop temporary table to avoid possible collisions

View File

@@ -83,7 +83,7 @@ abstract class Base
*/
public function add($arg)
{
if ( $arg !== null || ($arg instanceof self && $arg->count() > 0) ) {
if ( $arg !== null && (!$arg instanceof self || $arg->count() > 0) ) {
// If we decide to keep Expr\Base instances, we can use this check
if ( ! is_string($arg)) {
$class = get_class($arg);

View File

@@ -750,7 +750,10 @@ class SqlWalker implements TreeWalker
$sqlParts = array();
foreach ($identificationVarDecls as $identificationVariableDecl) {
$sql = $this->walkRangeVariableDeclaration($identificationVariableDecl->rangeVariableDeclaration);
$sql = $this->platform->appendLockHint(
$this->walkRangeVariableDeclaration($identificationVariableDecl->rangeVariableDeclaration),
$this->query->getHint(Query::HINT_LOCK_MODE)
);
foreach ($identificationVariableDecl->joins as $join) {
$sql .= $this->walkJoin($join);
@@ -770,7 +773,7 @@ class SqlWalker implements TreeWalker
}
}
$sqlParts[] = $this->platform->appendLockHint($sql, $this->query->getHint(Query::HINT_LOCK_MODE));
$sqlParts[] = $sql;
}
return ' FROM ' . implode(', ', $sqlParts);
@@ -1367,13 +1370,16 @@ class SqlWalker implements TreeWalker
$sqlParts = array ();
foreach ($identificationVarDecls as $subselectIdVarDecl) {
$sql = $this->walkRangeVariableDeclaration($subselectIdVarDecl->rangeVariableDeclaration);
$sql = $this->platform->appendLockHint(
$this->walkRangeVariableDeclaration($subselectIdVarDecl->rangeVariableDeclaration),
$this->query->getHint(Query::HINT_LOCK_MODE)
);
foreach ($subselectIdVarDecl->joins as $join) {
$sql .= $this->walkJoin($join);
}
$sqlParts[] = $this->platform->appendLockHint($sql, $this->query->getHint(Query::HINT_LOCK_MODE));
$sqlParts[] = $sql;
}
return ' FROM ' . implode(', ', $sqlParts);

View File

@@ -74,6 +74,10 @@ class CountOutputWalker extends SqlWalker
*/
public function walkSelectStatement(SelectStatement $AST)
{
if ($this->platform->getName() === "mssql") {
$AST->orderByClause = null;
}
$sql = parent::walkSelectStatement($AST);
// Find out the SQL alias of the identifier column of the root entity

View File

@@ -63,6 +63,9 @@ class Setup
* Use this method to register all autoloaders for a setup where Doctrine is installed
* though {@link http://pear.doctrine-project.org}.
*
* This method registers autoloaders for both Doctrine and Symfony top
* level namespaces.
*
* @return void
*/
static public function registerAutoloadPEAR()
@@ -74,15 +77,8 @@ class Setup
$loader = new ClassLoader("Doctrine");
$loader->register();
$parts = explode(PATH_SEPARATOR, get_include_path());
foreach ($parts as $includePath) {
if ($includePath != "." && file_exists($includePath . "/Doctrine")) {
$loader = new ClassLoader("Symfony\Component", $includePath . "/Doctrine");
$loader->register();
return;
}
}
$loader = new ClassLoader("Symfony");
$loader->register();
}
/**

View File

@@ -1376,6 +1376,10 @@ class UnitOfWork implements PropertyChangedListener
return self::STATE_NEW;
}
if ($class->containsForeignIdentifier) {
$id = $this->flattenIdentifier($class, $id);
}
switch (true) {
case ($class->isIdentifierNatural());
// Check for a version field, if available, to avoid a db lookup.
@@ -1688,6 +1692,29 @@ class UnitOfWork implements PropertyChangedListener
return $this->doMerge($entity, $visited);
}
/**
* convert foreign identifiers into scalar foreign key values to avoid object to string conversion failures.
*
* @param ClassMetadata $class
* @param array $id
* @return array
*/
private function flattenIdentifier($class, $id)
{
$flatId = array();
foreach ($id as $idField => $idValue) {
if (isset($class->associationMappings[$idField])) {
$targetClassMetadata = $this->em->getClassMetadata($class->associationMappings[$idField]['targetEntity']);
$associatedId = $this->getEntityIdentifier($idValue);
$flatId[$idField] = $associatedId[$targetClassMetadata->identifier[0]];
}
}
return $flatId;
}
/**
* Executes a merge operation on an entity.
*
@@ -1735,19 +1762,9 @@ class UnitOfWork implements PropertyChangedListener
$this->persistNew($class, $managedCopy);
} else {
$flatId = $id;
if ($class->containsForeignIdentifier) {
// convert foreign identifiers into scalar foreign key
// values to avoid object to string conversion failures.
foreach ($id as $idField => $idValue) {
if (isset($class->associationMappings[$idField])) {
$targetClassMetadata = $this->em->getClassMetadata($class->associationMappings[$idField]['targetEntity']);
$associatedId = $this->getEntityIdentifier($idValue);
$flatId[$idField] = $associatedId[$targetClassMetadata->identifier[0]];
}
}
}
$flatId = ($class->containsForeignIdentifier)
? $this->flattenIdentifier($class, $id)
: $id;
$managedCopy = $this->tryGetById($flatId, $class->rootEntityName);
@@ -2415,17 +2432,23 @@ class UnitOfWork implements PropertyChangedListener
if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
// inject ObjectManager into just loaded proxies.
if ($overrideLocalValues && $entity instanceof ObjectManagerAware) {
$entity->injectObjectManager($this->em, $class);
}
} else {
$overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
// If only a specific entity is set to refresh, check that it's the one
if(isset($hints[Query::HINT_REFRESH_ENTITY])) {
$overrideLocalValues = $hints[Query::HINT_REFRESH_ENTITY] === $entity;
}
// inject ObjectManager into just loaded proxies.
if ($overrideLocalValues && $entity instanceof ObjectManagerAware) {
$entity->injectObjectManager($this->em, $class);
}
// inject ObjectManager upon refresh.
if ($overrideLocalValues && $entity instanceof ObjectManagerAware) {
$entity->injectObjectManager($this->em, $class);
}
}
@@ -2571,6 +2594,10 @@ class UnitOfWork implements PropertyChangedListener
$newValueOid = spl_object_hash($newValue);
$this->entityIdentifiers[$newValueOid] = $associatedId;
$this->identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue;
if ($newValue instanceof NotifyPropertyChanged) {
$newValue->addPropertyChangedListener($this);
}
$this->entityStates[$newValueOid] = self::STATE_MANAGED;
// make sure that when an proxy is then finally loaded, $this->originalEntityData is set also!
break;

View File

@@ -36,7 +36,7 @@ class Version
/**
* Current Doctrine Version
*/
const VERSION = '2.3.1';
const VERSION = '2.3.3';
/**
* Compares a Doctrine version with the current one.

View File

@@ -173,14 +173,36 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results);
$this->assertEquals(2, count($results));
}
/**
* @group DDC-2340
*/
public function testMatchingOnDirtyCollection()
{
$this->_createFixture();
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->product->getId());
$thirdFeature = new ECommerceFeature();
$thirdFeature->setDescription('Model writing tutorial');
$features = $product->getFeatures();
$features->add($thirdFeature);
$results = $features->matching(new Criteria(
Criteria::expr()->eq('description', 'Model writing tutorial')
));
$this->assertEquals(2, count($results));
}
public function testMatchingBis()
{
$this->_createFixture();
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->product->getId());
$features = $product->getFeatures();
$thirdFeature = new ECommerceFeature();
$thirdFeature->setDescription('Third feature');
$product->addFeature($thirdFeature);

View File

@@ -461,4 +461,22 @@ class DDC117Test extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals($before + 3, count($data));
}
/**
* @group DDC-2246
*/
public function testGetEntityState()
{
$this->article1 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id());
$this->article2 = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article2->id());
$this->reference = new DDC117Reference($this->article2, $this->article1, "Test-Description");
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($this->reference));
$idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id());
$reference = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria);
$this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($reference));
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsEmail;
/**
* @group DDC-1666
*/
class DDC1666Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('cms');
parent::setUp();
}
public function testGivenOrphanRemovalOneToOne_WhenReplacing_ThenNoUniqueConstraintError()
{
$user = new CmsUser();
$user->name = "Benjamin";
$user->username = "beberlei";
$user->status = "something";
$user->setEmail($email = new CmsEmail());
$email->setEmail("kontakt@beberlei.de");
$this->_em->persist($user);
$this->_em->flush();
$this->assertTrue($this->_em->contains($email));
$user->setEmail($newEmail = new CmsEmail());
$newEmail->setEmail("benjamin.eberlei@googlemail.com");
$this->_em->flush();
$this->assertFalse($this->_em->contains($email));
}
}

View File

@@ -0,0 +1,153 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\NotifyPropertyChanged,
Doctrine\Common\PropertyChangedListener;
require_once __DIR__ . '/../../../TestInit.php';
class DDC1690Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp() {
parent::setUp();
try {
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1690Parent'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1690Child')
));
} catch (\Exception $e) {
// Swallow all exceptions. We do not test the schema tool here.
}
}
public function testChangeTracking()
{
$parent = new DDC1690Parent();
$child = new DDC1690Child();
$parent->setName('parent');
$child->setName('child');
$parent->setChild($child);
$child->setParent($parent);
$this->_em->persist($parent);
$this->_em->persist($child);
$this->assertEquals(1, count($parent->listeners));
$this->assertEquals(1, count($child->listeners));
$this->_em->flush();
$this->_em->clear();
$this->assertEquals(1, count($parent->listeners));
$this->assertEquals(1, count($child->listeners));
$parentId = $parent->getId();
$childId = $child->getId();
unset($parent, $child);
$parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId);
$child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId);
$this->assertEquals(1, count($parent->listeners));
$this->assertEquals(1, count($child->listeners));
unset($parent, $child);
$parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId);
$child = $parent->getChild();
$this->assertEquals(1, count($parent->listeners));
$this->assertEquals(1, count($child->listeners));
unset($parent, $child);
$child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId);
$parent = $child->getParent();
$this->assertEquals(1, count($parent->listeners));
$this->assertEquals(1, count($child->listeners));
}
}
class NotifyBaseEntity implements NotifyPropertyChanged {
public $listeners = array();
public function addPropertyChangedListener(PropertyChangedListener $listener) {
if (!in_array($listener, $this->listeners)) {
$this->listeners[] = $listener;
}
}
protected function onPropertyChanged($propName, $oldValue, $newValue) {
if ($this->listeners) {
foreach ($this->listeners as $listener) {
$listener->propertyChanged($this, $propName, $oldValue, $newValue);
}
}
}
}
/** @Entity @ChangeTrackingPolicy("NOTIFY") */
class DDC1690Parent extends NotifyBaseEntity {
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/** @Column */
private $name;
/** @OneToOne(targetEntity="DDC1690Child") */
private $child;
function getId() {
return $this->id;
}
function getName() {
return $this->name;
}
function setName($name) {
$this->onPropertyChanged('name', $this->name, $name);
$this->name = $name;
}
function setChild($child) {
$this->child = $child;
}
function getChild() {
return $this->child;
}
}
/** @Entity */
class DDC1690Child extends NotifyBaseEntity {
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/** @Column */
private $name;
/** @OneToOne(targetEntity="DDC1690Parent", mappedBy="child") */
private $parent;
function getId() {
return $this->id;
}
function getName() {
return $this->name;
}
function setName($name) {
$this->onPropertyChanged('name', $this->name, $name);
$this->name = $name;
}
function setParent($parent) {
$this->parent = $parent;
}
function getParent() {
return $this->parent;
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\Company\CompanyEmployee;
/**
* @group DDC-2090
*/
class DDC2090Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('company');
parent::setUp();
}
public function testIssue()
{
$className = 'Doctrine\Tests\Models\Company\CompanyEmployee';
$date1 = new \DateTime('2011-11-11 11:11:11');
$date2 = new \DateTime('2012-12-12 12:12:12');
$employee1 = new CompanyEmployee;
$employee2 = new CompanyEmployee;
$employee1->setName("Fabio B. Silva");
$employee1->setStartDate(new \DateTime('yesterday'));
$employee1->setDepartment("R&D");
$employee1->setSalary(100);
$employee2->setName("Doctrine Bot");
$employee1->setStartDate(new \DateTime('yesterday'));
$employee2->setDepartment("QA");
$employee2->setSalary(100);
$this->_em->persist($employee1);
$this->_em->persist($employee2);
$this->_em->flush();
$this->_em->clear();
$this->_em->createQueryBuilder()
->update($className, 'e')
->set('e.startDate', ':date')
->set('e.salary', ':salary')
->where('e = :e')
->setParameters(array(
'e' => $employee1,
'date' => $date1,
'salary' => 101,
))
->getQuery()
->useQueryCache(true)
->execute();
$this->_em->createQueryBuilder()
->update($className, 'e')
->set('e.startDate', ':date')
->set('e.salary', ':salary')
->where('e = :e')
->setParameters(array(
'e' => $employee2,
'date' => $date2,
'salary' => 102,
))
->getQuery()
->useQueryCache(true)
->execute();
$this->_em->clear();
$e1 = $this->_em->find($className, $employee1->getId());
$e2 = $this->_em->find($className, $employee2->getId());
$this->assertEquals(101, $e1->getSalary());
$this->assertEquals(102, $e2->getSalary());
$this->assertEquals($date1, $e1->getStartDate());
$this->assertEquals($date2, $e2->getStartDate());
$this->_em->createQueryBuilder()
->update($className, 'e')
->set('e.startDate', '?1')
->set('e.salary', '?2')
->where('e = ?0')
->setParameters(array($employee1, $date1, 101))
->getQuery()
->useQueryCache(true)
->execute();
$this->_em->createQueryBuilder()
->update($className, 'e')
->set('e.startDate', '?1')
->set('e.salary', '?2')
->where('e = ?0')
->setParameters(array($employee2, $date2, 102))
->getQuery()
->useQueryCache(true)
->execute();
$this->_em->clear();
$e1 = $this->_em->find($className, $employee1->getId());
$e2 = $this->_em->find($className, $employee2->getId());
$this->assertEquals(101, $e1->getSalary());
$this->assertEquals(102, $e2->getSalary());
$this->assertEquals($date1, $e1->getStartDate());
$this->assertEquals($date2, $e2->getStartDate());
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
/**
* @group DDC-2175
*/
class DDC2175Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2175Entity'),
));
}
public function testIssue()
{
$entity = new DDC2175Entity();
$entity->field = "foo";
$this->_em->persist($entity);
$this->_em->flush();
$this->assertEquals(1, $entity->version);
$entity->field = "bar";
$this->_em->flush();
$this->assertEquals(2, $entity->version);
$entity->field = "baz";
$this->_em->flush();
$this->assertEquals(3, $entity->version);
}
}
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorMap({"entity": "DDC2175Entity"})
*/
class DDC2175Entity
{
/**
* @Id @GeneratedValue @Column(type="integer")
*/
public $id;
/**
* @Column(type="string")
*/
public $field;
/**
* @Version
* @Column(type="integer")
*/
public $version;
}

View File

@@ -19,8 +19,8 @@ class DDC2182Test extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2182OptionChild'),
));
$this->assertEquals("CREATE TABLE DDC2182OptionParent (id INT UNSIGNED NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB", $sql[0]);
$this->assertEquals("CREATE TABLE DDC2182OptionChild (id VARCHAR(255) NOT NULL, parent_id INT UNSIGNED DEFAULT NULL, INDEX IDX_B314D4AD727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB", $sql[1]);
$this->assertEquals("CREATE TABLE DDC2182OptionParent (id INT UNSIGNED NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[0]);
$this->assertEquals("CREATE TABLE DDC2182OptionChild (id VARCHAR(255) NOT NULL, parent_id INT UNSIGNED DEFAULT NULL, INDEX IDX_B314D4AD727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB", $sql[1]);
$this->assertEquals("ALTER TABLE DDC2182OptionChild ADD CONSTRAINT FK_B314D4AD727ACA70 FOREIGN KEY (parent_id) REFERENCES DDC2182OptionParent (id)", $sql[2]);
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectManagerAware;
require_once __DIR__ . '/../../../TestInit.php';
/**
* @group DDC-2231
*/
class DDC2231Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2231EntityY'),
));
}
public function testInjectObjectManagerInProxyIfInitializedInUow()
{
$y1 = new DDC2231EntityY;
$this->_em->persist($y1);
$this->_em->flush();
$this->_em->clear();
$y1ref = $this->_em->getReference(get_class($y1), $y1->id);
$this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $y1ref);
$this->assertFalse($y1ref->__isInitialized__);
$id = $y1ref->doSomething();
$this->assertTrue($y1ref->__isInitialized__);
$this->assertEquals($this->_em, $y1ref->om);
}
}
/** @Entity @Table(name="ddc2231_y") */
class DDC2231EntityY implements ObjectManagerAware
{
/**
* @Id @Column(type="integer") @GeneratedValue
*/
public $id;
public $om;
public function injectObjectManager(ObjectManager $objectManager, ClassMetadata $classMetadata)
{
$this->om = $objectManager;
}
public function getId()
{
return $this->id;
}
public function doSomething()
{
}
}

View File

@@ -34,4 +34,28 @@ class SimpleObjectHydratorTest extends HydrationTestCase
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
$hydrator->hydrateAll($stmt, $rsm);
}
public function testExtraFieldInResultSetShouldBeIgnore()
{
$rsm = new ResultSetMapping;
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsAddress', 'a');
$rsm->addFieldResult('a', 'a__id', 'id');
$rsm->addFieldResult('a', 'a__city', 'city');
$resultSet = array(
array(
'a__id' => '1',
'a__city' => 'Cracow',
'doctrine_rownum' => '1'
),
);
$expectedEntity = new \Doctrine\Tests\Models\CMS\CmsAddress();
$expectedEntity->id = 1;
$expectedEntity->city = 'Cracow';
$stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals($result[0], $expectedEntity);
}
}

View File

@@ -139,14 +139,27 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/
public function testFieldMappings($class)
{
$this->assertEquals(3, count($class->fieldMappings));
$this->assertEquals(4, count($class->fieldMappings));
$this->assertTrue(isset($class->fieldMappings['id']));
$this->assertTrue(isset($class->fieldMappings['name']));
$this->assertTrue(isset($class->fieldMappings['email']));
$this->assertTrue(isset($class->fieldMappings['version']));
return $class;
}
/**
* @depends testFieldMappings
* @param ClassMetadata $class
*/
public function testVersionedField($class)
{
$this->assertTrue($class->isVersioned);
$this->assertEquals("version", $class->versionField);
$this->assertFalse(isset($class->fieldMappings['version']['version']));
}
/**
* @depends testEntityTableNameAndInheritance
* @param ClassMetadata $class
@@ -464,24 +477,22 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
/**
* @group DDC-889
* @expectedException Doctrine\ORM\Mapping\MappingException
* @expectedExceptionMessage Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.
*/
public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses()
{
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.');
$this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class');
}
/**
* @group DDC-889
* @expectedException Doctrine\ORM\Mapping\MappingException
* @expectedExceptionMessage No identifier/primary key specified for Entity "Doctrine\Tests\Models\DDC889\DDC889Entity" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass". Every Entity must have an identifier/primary key.
*/
public function testIdentifierRequiredShouldMentionParentClasses()
{
$factory = $this->createClassMetadataFactory();
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException', 'No identifier/primary key specified for Entity "Doctrine\Tests\Models\DDC889\DDC889Entity" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass". Every Entity must have an identifier/primary key.');
$factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Entity');
}
@@ -498,7 +509,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/
public function testNamedNativeQuery()
{
$class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
//named native query
@@ -527,7 +538,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$this->assertArrayHasKey('mapping-count', $class->sqlResultSetMappings);
$this->assertArrayHasKey('mapping-find-all', $class->sqlResultSetMappings);
$this->assertArrayHasKey('mapping-without-fields', $class->sqlResultSetMappings);
$findAllMapping = $class->getSqlResultSetMapping('mapping-find-all');
$this->assertEquals('mapping-find-all', $findAllMapping['name']);
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $findAllMapping['entities'][0]['entityClass']);
@@ -539,7 +550,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('mapping-without-fields', $withoutFieldsMapping['name']);
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $withoutFieldsMapping['entities'][0]['entityClass']);
$this->assertEquals(array(), $withoutFieldsMapping['entities'][0]['fields']);
$countMapping = $class->getSqlResultSetMapping('mapping-count');
$this->assertEquals('mapping-count', $countMapping['name']);
$this->assertEquals(array('name'=>'count'), $countMapping['columns'][0]);
@@ -627,7 +638,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$adminMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Admin');
$guestMetadata = $factory->getMetadataFor('Doctrine\Tests\Models\DDC964\DDC964Guest');
// assert groups association mappings
$this->assertArrayHasKey('groups', $guestMetadata->associationMappings);
$this->assertArrayHasKey('groups', $adminMetadata->associationMappings);
@@ -686,7 +697,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals($guestAddress['isCascadeRefresh'], $adminAddress['isCascadeRefresh']);
$this->assertEquals($guestAddress['isCascadeMerge'], $adminAddress['isCascadeMerge']);
$this->assertEquals($guestAddress['isCascadeDetach'], $adminAddress['isCascadeDetach']);
// assert override
$this->assertEquals('address_id', $guestAddress['joinColumns'][0]['name']);
$this->assertEquals(array('address_id'=>'id'), $guestAddress['sourceToTargetKeyColumns']);
@@ -793,6 +804,12 @@ class User
*/
public $groups;
/**
* @Column(type="integer")
* @Version
*/
public $version;
/**
* @PrePersist
@@ -847,6 +864,9 @@ class User
'columnName' => 'user_email',
'columnDefinition' => 'CHAR(32) NOT NULL',
));
$mapping = array('fieldName' => 'version', 'type' => 'integer');
$metadata->setVersionMapping($mapping);
$metadata->mapField($mapping);
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
$metadata->mapOneToOne(array(
'fieldName' => 'address',
@@ -1051,7 +1071,7 @@ class DDC807Entity
* @GeneratedValue(strategy="NONE")
**/
public $id;
public static function loadMetadata(ClassMetadataInfo $metadata)
{
$metadata->mapField(array(

View File

@@ -35,6 +35,9 @@ $metadata->mapField(array(
'columnName' => 'user_email',
'columnDefinition' => 'CHAR(32) NOT NULL',
));
$mapping = array('fieldName' => 'version', 'type' => 'integer');
$metadata->setVersionMapping($mapping);
$metadata->mapField($mapping);
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
$metadata->mapOneToOne(array(
'fieldName' => 'address',
@@ -121,4 +124,4 @@ $metadata->setSequenceGeneratorDefinition(array(
'sequenceName' => 'tablename_seq',
'allocationSize' => 100,
'initialValue' => 1,
));
));

View File

@@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Doctrine\Tests\ORM\Mapping\User" table="cms_users">
<options>
<option name="foo">bar</option>
@@ -36,7 +36,7 @@
<generator strategy="AUTO"/>
<sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" />
</id>
<field name="name" column="name" type="string" length="50" nullable="true" unique="true">
<options>
<option name="foo">bar</option>
@@ -46,12 +46,14 @@
</options>
</field>
<field name="email" column="user_email" type="string" column-definition="CHAR(32) NOT NULL" />
<field name="version" type="integer" version="true" />
<one-to-one field="address" target-entity="Address" inversed-by="user">
<cascade><cascade-remove /></cascade>
<join-column name="address_id" referenced-column-name="id" on-delete="CASCADE" on-update="CASCADE"/>
</one-to-one>
<one-to-many field="phonenumbers" target-entity="Phonenumber" mapped-by="user" index-by="number" orphan-removal="true">
<cascade>
<cascade-persist/>
@@ -60,7 +62,7 @@
<order-by-field name="number" direction="ASC" />
</order-by>
</one-to-many>
<many-to-many field="groups" target-entity="Group">
<cascade>
<cascade-all/>
@@ -74,7 +76,7 @@
</inverse-join-columns>
</join-table>
</many-to-many>
</entity>
</doctrine-mapping>

View File

@@ -5,4 +5,4 @@ Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType:
generator:
strategy: NONE
fields:
name:
name: ~

View File

@@ -1,7 +1,7 @@
Doctrine\Tests\ORM\Mapping\DDC2069Entity:
type: entity
id:
id:
id: ~
fields:
name:
type: string ( 255 )
@@ -12,4 +12,4 @@ Doctrine\Tests\ORM\Mapping\DDC2069Entity:
columns: name, value
indexes:
0:
columns: value, name
columns: value, name

View File

@@ -30,6 +30,9 @@ Doctrine\Tests\ORM\Mapping\User:
type: string
column: user_email
columnDefinition: CHAR(32) NOT NULL
version:
type: integer
version: true
oneToOne:
address:
targetEntity: Address
@@ -73,4 +76,4 @@ Doctrine\Tests\ORM\Mapping\User:
name_idx:
columns: name
0:
columns: user_email
columns: user_email

View File

@@ -409,4 +409,18 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
$select = new Expr\Select(array('foo', 'bar'));
$this->assertEquals(array('foo', 'bar'), $select->getParts());
}
public function testAddEmpty() {
$andExpr = $this->_expr->andx();
$andExpr->add($this->_expr->andx());
$this->assertEquals(0, $andExpr->count());
}
public function testAddNull() {
$andExpr = $this->_expr->andx();
$andExpr->add(null);
$this->assertEquals(0, $andExpr->count());
}
}

View File

@@ -41,5 +41,22 @@ class CountOutputWalkerTest extends PaginationTestCase
"SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id1 FROM (SELECT count(u0_.id) AS sclr0, g1_.id AS id1, u0_.id AS id2 FROM groups g1_ LEFT JOIN user_group u2_ ON g1_.id = u2_.group_id LEFT JOIN User u0_ ON u0_.id = u2_.user_id GROUP BY g1_.id HAVING sclr0 > 0) dctrn_result) dctrn_table", $query->getSql()
);
}
public function testCountQueryOrderBySqlServer()
{
if ($this->entityManager->getConnection()->getDatabasePlatform()->getName() !== "mssql") {
$this->markTestSkipped('SQLServer only test.');
}
$query = $this->entityManager->createQuery(
'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p ORDER BY p.id');
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
$query->setFirstResult(null)->setMaxResults(null);
$this->assertEquals(
"SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id0 FROM (SELECT b0_.id AS id0, b0_.author_id AS author_id1, b0_.category_id AS category_id2 FROM BlogPost b0_) dctrn_result) dctrn_table",
$query->getSql()
);
}
}