Refactorings. Started with new hydrator for 2.0.
This commit is contained in:
parent
ff11220961
commit
ab65ad5b4d
File diff suppressed because it is too large
Load Diff
@ -449,7 +449,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
}
|
||||
} else {
|
||||
// @todo does not take composite keys into account
|
||||
$list[] = $record->getIncremented();
|
||||
$ids = $record->identifier();
|
||||
$list[] = count($ids) > 0 ? array_pop($ids) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -564,7 +565,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
|
||||
if ( ! isset($name)) {
|
||||
foreach ($this->data as $record) {
|
||||
$value = $record->getIncremented();
|
||||
// FIXME: composite key support
|
||||
$ids = $record->identifier();
|
||||
$value = count($ids) > 0 ? array_pop($ids) : null;
|
||||
if ($value !== null) {
|
||||
$list[] = $value;
|
||||
}
|
||||
@ -583,7 +586,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
}
|
||||
} else {
|
||||
foreach ($this->data as $record) {
|
||||
$value = $record->getIncremented();
|
||||
$ids = $record->identifier();
|
||||
$value = count($ids) > 0 ? array_pop($ids) : null;
|
||||
if ($value !== null) {
|
||||
$list[] = $value;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -20,7 +20,23 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Doctrine_Connection_UnitOfWork
|
||||
* The UnitOfWork is responsible for writing out changes to the database at
|
||||
* the correct time and in the correct order.
|
||||
*
|
||||
* Some terminology:
|
||||
*
|
||||
* <b>New entity</b>: From the point of view of the unitOfWork is an entity that
|
||||
* already has an identity but is not yet persisted into the database. This
|
||||
* is usually the case for all newly saved entities that use a SEQUENCE id
|
||||
* generator. Entities with an IDENTITY id generator get persisted as soon
|
||||
* as they're saved in order to obtain the identifier. Therefore entities that
|
||||
* use an IDENTITY id generator never appear in the list of new entities of the UoW.
|
||||
*
|
||||
* <b>Dirty entity</b>: ...
|
||||
*
|
||||
* <b>Removed entity</b>: ...
|
||||
*
|
||||
* <b>Clean entity</b>: ...
|
||||
*
|
||||
* @package Doctrine
|
||||
* @subpackage Connection
|
||||
@ -105,12 +121,19 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
*/
|
||||
public function registerNew(Doctrine_Record $entity)
|
||||
{
|
||||
if (isset($this->_dirtyEntities[$entity->getOid()])) {
|
||||
throw new Doctrine_Connection_Exception("Dirty object can't be registered as new.");
|
||||
} else if (isset($this->_removedEntities[$entity->getOid()])) {
|
||||
throw new Doctrine_Connection_Exception("Removed object can't be registered as new.");
|
||||
if ( ! $entity->identifier()) {
|
||||
throw new Doctrine_Connection_Exception("Entity without identity "
|
||||
. "can't be registered as new.");
|
||||
}
|
||||
$this->_newEntities[$entity->getOid()] = $entity;
|
||||
$oid = $entity->getOid();
|
||||
if (isset($this->_dirtyEntities[$oid])) {
|
||||
throw new Doctrine_Connection_Exception("Dirty object can't be registered as new.");
|
||||
} else if (isset($this->_removedEntities[$oid])) {
|
||||
throw new Doctrine_Connection_Exception("Removed object can't be registered as new.");
|
||||
} else if (isset($this->_newEntities[$oid])) {
|
||||
throw new Doctrine_Connection_Exception("Object already registered as new. Can't register twice.");
|
||||
}
|
||||
$this->_newEntities[$oid] = $entity;
|
||||
}
|
||||
|
||||
public function isRegisteredNew(Doctrine_Record $entity)
|
||||
@ -131,12 +154,17 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
*/
|
||||
public function registerDirty(Doctrine_Record $entity)
|
||||
{
|
||||
if ( ! $entity->identifier()) {
|
||||
throw new Doctrine_Connection_Exception("Entity without identity "
|
||||
. "can't be registered as dirty.");
|
||||
}
|
||||
$oid = $entity->getOid();
|
||||
if (isset($this->_removedEntities[$entity->getOid()])) {
|
||||
throw new Doctrine_Connection_Exception("Removed object can't be registered as dirty.");
|
||||
} else if (isset($this->_newEntities[$entity->getOid()])) {
|
||||
throw new Doctrine_Connection_Exception("");
|
||||
}
|
||||
$this->_dirtyEntities[$entity->getOid()] = $entity;
|
||||
if ( ! isset($this->_dirtyEntities[$oid], $this->_newEntities[$oid])) {
|
||||
$this->_dirtyEntities[$entity->getOid()] = $entity;
|
||||
}
|
||||
}
|
||||
|
||||
public function isRegisteredDirty(Doctrine_Record $entity)
|
||||
@ -149,8 +177,21 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
|
||||
*/
|
||||
public function registerRemoved(Doctrine_Record $entity)
|
||||
{
|
||||
if ($entity->isTransient()) {
|
||||
return;
|
||||
}
|
||||
$this->unregisterIdentity($entity);
|
||||
$this->_removedEntities[$entity->getOid()] = $entity;
|
||||
$oid = $entity->getOid();
|
||||
if (isset($this->_newEntities[$oid])) {
|
||||
unset($this->_newEntities[$oid]);
|
||||
return;
|
||||
}
|
||||
if (isset($this->_dirtyEntities[$oid])) {
|
||||
unset($this->_dirtyEntities[$oid]);
|
||||
}
|
||||
if ( ! isset($this->_removedEntities[$oid])) {
|
||||
$this->_removedEntities[$oid] = $entity;
|
||||
}
|
||||
}
|
||||
|
||||
public function isRegisteredRemoved(Doctrine_Record $entity)
|
||||
|
225
lib/Doctrine/EntityRepository.php
Normal file
225
lib/Doctrine/EntityRepository.php
Normal file
@ -0,0 +1,225 @@
|
||||
<?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.phpdoctrine.org>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for all custom user-defined repositories.
|
||||
* Provides basic finder methods, common to all repositories.
|
||||
*
|
||||
* @package Doctrine
|
||||
* @subpackage EntityRepository
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.phpdoctrine.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
* @todo package:orm
|
||||
*/
|
||||
class Doctrine_EntityRepository
|
||||
{
|
||||
protected $_entityName;
|
||||
protected $_conn;
|
||||
protected $_classMetadata;
|
||||
|
||||
public function __construct($entityName, Doctrine_ClassMetadata $classMetadata)
|
||||
{
|
||||
$this->_entityName = $entityName;
|
||||
$this->_conn = $classMetadata->getConnection();
|
||||
$this->_classMetadata = $classMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* createQuery
|
||||
* creates a new Doctrine_Query object and adds the component name
|
||||
* of this table as the query 'from' part
|
||||
*
|
||||
* @param string Optional alias name for component aliasing.
|
||||
*
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
protected function _createQuery($alias = '')
|
||||
{
|
||||
if ( ! empty($alias)) {
|
||||
$alias = ' ' . trim($alias);
|
||||
}
|
||||
return Doctrine_Query::create($this->_conn)->from($this->_entityName . $alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear
|
||||
* clears the first level cache (identityMap)
|
||||
*
|
||||
* @return void
|
||||
* @todo what about a more descriptive name? clearIdentityMap?
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->_conn->unitOfWork->clearIdentitiesForEntity($this->_classMetadata->getRootClassName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an entity by its primary key.
|
||||
*
|
||||
* @param $id database row id
|
||||
* @param int $hydrationMode Doctrine::HYDRATE_ARRAY or Doctrine::HYDRATE_RECORD
|
||||
* @return mixed Array or Doctrine_Record or false if no result
|
||||
* @todo Remove. Move to EntityRepository.
|
||||
*/
|
||||
public function find($id, $hydrationMode = null)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_array($id) && count($id) > 1) {
|
||||
// it's a composite key. keys = field names, values = values.
|
||||
$values = array_values($id);
|
||||
$keys = array_keys($id);
|
||||
} else {
|
||||
$values = is_array($id) ? array_values($id) : array($id);
|
||||
$keys = $this->_classMetadata->getIdentifier();
|
||||
}
|
||||
|
||||
return $this->_createQuery()
|
||||
->where(implode(' = ? AND ', $keys) . ' = ?')
|
||||
->fetchOne($values, $hydrationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all entities of the mapper's class.
|
||||
* Use with care.
|
||||
*
|
||||
* @param int $hydrationMode Doctrine::HYDRATE_ARRAY or Doctrine::HYDRATE_RECORD
|
||||
* @return Doctrine_Collection
|
||||
*/
|
||||
public function findAll($hydrationMode = null)
|
||||
{
|
||||
return $this->_createQuery()->execute(array(), $hydrationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* findBy
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $value
|
||||
* @param string $hydrationMode
|
||||
* @return void
|
||||
*/
|
||||
protected function findBy($fieldName, $value, $hydrationMode = null)
|
||||
{
|
||||
return $this->_createQuery()->where($fieldName . ' = ?')->execute(array($value), $hydrationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* findOneBy
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $value
|
||||
* @param string $hydrationMode
|
||||
* @return void
|
||||
*/
|
||||
protected function findOneBy($fieldName, $value, $hydrationMode = null)
|
||||
{
|
||||
$results = $this->_createQuery()->where($fieldName . ' = ?')->limit(1)->execute(
|
||||
array($value), $hydrationMode);
|
||||
return $hydrationMode === Doctrine::HYDRATE_ARRAY ? array_shift($results) : $results->getFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* findBySql
|
||||
* finds records with given SQL where clause
|
||||
* returns a collection of records
|
||||
*
|
||||
* @param string $dql DQL after WHERE clause
|
||||
* @param array $params query parameters
|
||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
||||
* @return Doctrine_Collection
|
||||
*
|
||||
* @todo This actually takes DQL, not SQL, but it requires column names
|
||||
* instead of field names. This should be fixed to use raw SQL instead.
|
||||
*/
|
||||
public function findBySql($dql, array $params = array(), $hydrationMode = null)
|
||||
{
|
||||
return $this->_createQuery()->where($dql)->execute($params, $hydrationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* findByDql
|
||||
* finds records with given DQL where clause
|
||||
* returns a collection of records
|
||||
*
|
||||
* @param string $dql DQL after WHERE clause
|
||||
* @param array $params query parameters
|
||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
||||
* @return Doctrine_Collection
|
||||
*/
|
||||
public function findByDql($dql, array $params = array(), $hydrationMode = null)
|
||||
{
|
||||
$query = new Doctrine_Query($this->_conn);
|
||||
$component = $this->getComponentName();
|
||||
$dql = 'FROM ' . $component . ' WHERE ' . $dql;
|
||||
|
||||
return $query->query($dql, $params, $hydrationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds support for magic finders.
|
||||
* findByColumnName, findByRelationAlias
|
||||
* findById, findByContactId, etc.
|
||||
*
|
||||
* @return void
|
||||
* @throws Doctrine_Mapper_Exception If the method called is an invalid find* method
|
||||
* or no find* method at all and therefore an invalid
|
||||
* method call.
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
if (substr($method, 0, 6) == 'findBy') {
|
||||
$by = substr($method, 6, strlen($method));
|
||||
$method = 'findBy';
|
||||
} else if (substr($method, 0, 9) == 'findOneBy') {
|
||||
$by = substr($method, 9, strlen($method));
|
||||
$method = 'findOneBy';
|
||||
} else {
|
||||
throw new Doctrine_Mapper_Exception("Undefined method '$method'.");
|
||||
}
|
||||
|
||||
if (isset($by)) {
|
||||
if ( ! isset($arguments[0])) {
|
||||
throw new Doctrine_Mapper_Exception('You must specify the value to findBy.');
|
||||
}
|
||||
|
||||
$fieldName = Doctrine::tableize($by);
|
||||
$hydrationMode = isset($arguments[1]) ? $arguments[1]:null;
|
||||
|
||||
if ($this->_classMetadata->hasField($fieldName)) {
|
||||
return $this->$method($fieldName, $arguments[0], $hydrationMode);
|
||||
} else if ($this->_classMetadata->hasRelation($by)) {
|
||||
$relation = $this->_classMetadata->getRelation($by);
|
||||
if ($relation['type'] === Doctrine_Relation::MANY) {
|
||||
throw new Doctrine_Mapper_Exception('Cannot findBy many relationship.');
|
||||
}
|
||||
return $this->$method($relation['local'], $arguments[0], $hydrationMode);
|
||||
} else {
|
||||
throw new Doctrine_Mapper_Exception('Cannot find by: ' . $by . '. Invalid field or relationship alias.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -52,13 +52,14 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
||||
* 'table' => Table object,
|
||||
* 'parent' => Parent DQL alias (if any),
|
||||
* 'relation' => Relation object (if any),
|
||||
* 'map' => Custom index to use as the key in the result (if any)
|
||||
* 'map' => Custom index to use as the key in the result (if any),
|
||||
* 'agg' => List of aggregate values (sql alias => dql alias)
|
||||
* )
|
||||
* )
|
||||
* @return mixed The created object/array graph.
|
||||
*/
|
||||
public function hydrateResultSet($stmt, $tableAliases, $hydrationMode = null)
|
||||
{
|
||||
{
|
||||
if ($hydrationMode === null) {
|
||||
$hydrationMode = $this->_hydrationMode;
|
||||
}
|
||||
@ -82,7 +83,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
||||
// Used variables during hydration
|
||||
reset($this->_queryComponents);
|
||||
$rootAlias = key($this->_queryComponents);
|
||||
$rootComponentName = $this->_queryComponents[$rootAlias]['mapper']->getComponentName();
|
||||
$rootComponentName = $this->_queryComponents[$rootAlias]['table']->getComponentName();
|
||||
// if only one component is involved we can make our lives easier
|
||||
$isSimpleQuery = count($this->_queryComponents) <= 1;
|
||||
// Holds hydration listeners that get called during hydration
|
||||
@ -110,7 +111,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
||||
foreach ($this->_queryComponents as $dqlAlias => $component) {
|
||||
// disable lazy-loading of related elements during hydration
|
||||
$component['table']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
|
||||
$componentName = $component['mapper']->getComponentName();
|
||||
$componentName = $component['table']->getClassName();
|
||||
$listeners[$componentName] = $component['table']->getRecordListener();
|
||||
$identifierMap[$dqlAlias] = array();
|
||||
$prev[$dqlAlias] = array();
|
||||
@ -127,9 +128,8 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
||||
//
|
||||
// hydrate the data of the root entity from the current row
|
||||
//
|
||||
$table = $this->_queryComponents[$rootAlias]['table'];
|
||||
$mapper = $this->_queryComponents[$rootAlias]['mapper'];
|
||||
$componentName = $mapper->getComponentName();
|
||||
$class = $this->_queryComponents[$rootAlias]['table'];
|
||||
$componentName = $class->getComponentName();
|
||||
|
||||
// just event stuff
|
||||
$event->set('data', $rowData[$rootAlias]);
|
||||
@ -175,9 +175,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
||||
foreach ($rowData as $dqlAlias => $data) {
|
||||
$index = false;
|
||||
$map = $this->_queryComponents[$dqlAlias];
|
||||
$table = $map['table'];
|
||||
$mapper = $map['mapper'];
|
||||
$componentName = $mapper->getComponentName();
|
||||
$componentName = $map['table']->getComponentName();
|
||||
|
||||
// just event stuff
|
||||
$event->set('data', $data);
|
||||
@ -186,7 +184,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
||||
|
||||
$parent = $map['parent'];
|
||||
$relation = $map['relation'];
|
||||
$relationAlias = $map['relation']->getAlias();
|
||||
$relationAlias = $relation->getAlias();
|
||||
|
||||
$path = $parent . '.' . $dqlAlias;
|
||||
|
||||
@ -195,16 +193,19 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
||||
}
|
||||
|
||||
// check the type of the relation
|
||||
if ( ! $relation->isOneToOne() && $driver->initRelated($prev[$parent], $relationAlias)) {
|
||||
if ( ! $relation->isOneToOne()) {
|
||||
$oneToOne = false;
|
||||
// append element
|
||||
if (isset($nonemptyComponents[$dqlAlias])) {
|
||||
$driver->initRelated($prev[$parent], $relationAlias);
|
||||
if ( ! isset($identifierMap[$path][$id[$parent]][$id[$dqlAlias]])) {
|
||||
$element = $driver->getElement($data, $componentName);
|
||||
|
||||
// just event stuff
|
||||
$event->set('data', $element);
|
||||
$listeners[$componentName]->postHydrate($event);
|
||||
//--
|
||||
|
||||
if ($field = $this->_getCustomIndexField($dqlAlias)) {
|
||||
// TODO: we should check this earlier. Fields used in INDEXBY
|
||||
// must be unique. Then this can be removed here.
|
||||
@ -223,7 +224,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
||||
$index = $identifierMap[$path][$id[$parent]][$id[$dqlAlias]];
|
||||
}
|
||||
// register collection for later snapshots
|
||||
$driver->registerCollection($prev[$parent][$relationAlias]);
|
||||
//$driver->registerCollection($prev[$parent][$relationAlias]);
|
||||
}
|
||||
} else {
|
||||
// 1-1 relation
|
||||
@ -315,11 +316,17 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
||||
if ( ! isset($cache[$key])) {
|
||||
// cache general information like the column name <-> field name mapping
|
||||
$e = explode('__', $key);
|
||||
$columnName = strtolower(array_pop($e));
|
||||
$columnName = strtolower(array_pop($e));
|
||||
$cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))];
|
||||
$mapper = $this->_queryComponents[$cache[$key]['dqlAlias']]['mapper'];
|
||||
$classMetadata = $mapper->getClassMetadata();
|
||||
$fieldName = $mapper->getFieldName($columnName);
|
||||
// check whether it's an aggregate value or a regular field
|
||||
if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName])) {
|
||||
$fieldName = $this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName];
|
||||
} else {
|
||||
$fieldName = $mapper->getFieldName($columnName);
|
||||
}
|
||||
|
||||
$cache[$key]['fieldName'] = $fieldName;
|
||||
|
||||
// cache identifier information
|
||||
@ -343,10 +350,6 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
|
||||
$dqlAlias = $cache[$key]['dqlAlias'];
|
||||
$fieldName = $cache[$key]['fieldName'];
|
||||
|
||||
if (isset($this->_queryComponents[$dqlAlias]['agg'][$fieldName])) {
|
||||
$fieldName = $this->_queryComponents[$dqlAlias]['agg'][$fieldName];
|
||||
}
|
||||
|
||||
if ($cache[$key]['isIdentifier']) {
|
||||
$id[$dqlAlias] .= '|' . $value;
|
||||
}
|
||||
|
@ -71,8 +71,6 @@ class Doctrine_Hydrator_ArrayDriver
|
||||
if ( ! isset($data[$name])) {
|
||||
$data[$name] = array();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Doctrine_Hydrate_RecordDriver
|
||||
* Doctrine_Hydrator_RecordDriver
|
||||
* Hydration strategy used for creating graphs of entity objects.
|
||||
*
|
||||
* @package Doctrine
|
||||
@ -34,8 +34,13 @@
|
||||
*/
|
||||
class Doctrine_Hydrator_RecordDriver
|
||||
{
|
||||
/** Collections initialized by the driver */
|
||||
protected $_collections = array();
|
||||
/** Mappers */
|
||||
protected $_mappers = array();
|
||||
/** Memory for initialized relations */
|
||||
private $_initializedRelations = array();
|
||||
/** Null object */
|
||||
private $_nullObject;
|
||||
|
||||
public function __construct()
|
||||
@ -53,54 +58,32 @@ class Doctrine_Hydrator_RecordDriver
|
||||
|
||||
public function getLastKey($coll)
|
||||
{
|
||||
$coll->end();
|
||||
|
||||
return $coll->key();
|
||||
// check needed because of mixed results
|
||||
if (is_array($coll)) {
|
||||
end($coll);
|
||||
return key($coll);
|
||||
} else {
|
||||
$coll->end();
|
||||
return $coll->key();
|
||||
}
|
||||
}
|
||||
|
||||
public function initRelated($record, $name)
|
||||
public function initRelated(Doctrine_Record $record, $name)
|
||||
{
|
||||
return true;
|
||||
/*
|
||||
if ( ! is_array($record)) {
|
||||
$record[$name];
|
||||
return true;
|
||||
if ( ! isset($this->_initializedRelations[$record->getOid()][$name])) {
|
||||
$relation = $record->getClassMetadata()->getRelation($name);
|
||||
$relatedClass = $relation->getTable();
|
||||
$coll = $this->getElementCollection($relatedClass->getClassName());
|
||||
$coll->setReference($record, $relation);
|
||||
$record[$name] = $coll;
|
||||
$this->_initializedRelations[$record->getOid()][$name] = true;
|
||||
}
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
|
||||
public function registerCollection(Doctrine_Collection $coll)
|
||||
{
|
||||
$this->_collections[] = $coll;
|
||||
}
|
||||
|
||||
/**
|
||||
* isIdentifiable
|
||||
* returns whether or not a given data row is identifiable (it contains
|
||||
* all primary key fields specified in the second argument)
|
||||
*
|
||||
* @param array $row
|
||||
* @param Doctrine_Table $table
|
||||
* @return boolean
|
||||
*/
|
||||
/*public function isIdentifiable(array $row, Doctrine_Table $table)
|
||||
{
|
||||
$primaryKeys = $table->getIdentifierColumnNames();
|
||||
|
||||
if (is_array($primaryKeys)) {
|
||||
foreach ($primaryKeys as $id) {
|
||||
if ( ! isset($row[$id])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( ! isset($row[$primaryKeys])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
|
||||
public function getNullPointer()
|
||||
{
|
||||
@ -127,6 +110,7 @@ class Doctrine_Hydrator_RecordDriver
|
||||
}
|
||||
$this->_collections = array();
|
||||
$this->_mappers = array();
|
||||
$this->_initializedRelations = array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
422
lib/Doctrine/HydratorNew.php
Normal file
422
lib/Doctrine/HydratorNew.php
Normal file
@ -0,0 +1,422 @@
|
||||
<?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.phpdoctrine.org>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The hydrator has the tedious task to construct object or array graphs out of
|
||||
* a database result set.
|
||||
*
|
||||
* @package Doctrine
|
||||
* @subpackage Hydrator
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.phpdoctrine.org
|
||||
* @since 1.0
|
||||
* @version $Revision: 3192 $
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
{
|
||||
/**
|
||||
* hydrateResultSet
|
||||
* parses the data returned by statement object
|
||||
*
|
||||
* This is method defines the core of Doctrine's object population algorithm.
|
||||
*
|
||||
* The key idea is the loop over the rowset only once doing all the needed operations
|
||||
* within this massive loop.
|
||||
*
|
||||
* @todo: Detailed documentation. Refactor (too long & nesting level).
|
||||
*
|
||||
* @param mixed $stmt
|
||||
* @param array $tableAliases Array that maps table aliases (SQL alias => DQL alias)
|
||||
* @param array $aliasMap Array that maps DQL aliases to their components
|
||||
* (DQL alias => array(
|
||||
* 'table' => Table object,
|
||||
* 'parent' => Parent DQL alias (if any),
|
||||
* 'relation' => Relation object (if any),
|
||||
* 'map' => Custom index to use as the key in the result (if any),
|
||||
* 'agg' => List of aggregate value names (sql alias => dql alias)
|
||||
* )
|
||||
* )
|
||||
* @return mixed The created object/array graph.
|
||||
*/
|
||||
public function hydrateResultSet($stmt, $tableAliases, $hydrationMode = null)
|
||||
{
|
||||
if ($hydrationMode === null) {
|
||||
$hydrationMode = $this->_hydrationMode;
|
||||
}
|
||||
|
||||
if ($hydrationMode == Doctrine::HYDRATE_NONE) {
|
||||
return $stmt->fetchAll(PDO::FETCH_NUM);
|
||||
}
|
||||
|
||||
$this->_tableAliases = $tableAliases;
|
||||
|
||||
if ($hydrationMode == Doctrine::HYDRATE_ARRAY) {
|
||||
$driver = new Doctrine_Hydrator_ArrayDriver();
|
||||
} else {
|
||||
$driver = new Doctrine_Hydrator_RecordDriver();
|
||||
}
|
||||
|
||||
$event = new Doctrine_Event(null, Doctrine_Event::HYDRATE, null);
|
||||
|
||||
//$s = microtime(true);
|
||||
|
||||
// Used variables during hydration
|
||||
reset($this->_queryComponents);
|
||||
$rootAlias = key($this->_queryComponents);
|
||||
$rootComponentName = $this->_queryComponents[$rootAlias]['table']->getClassName();
|
||||
// if only one class is involved we can make our lives easier
|
||||
$isSimpleQuery = count($this->_queryComponents) <= 1;
|
||||
// Holds hydration listeners that get called during hydration
|
||||
$listeners = array();
|
||||
// Lookup map to quickly discover/lookup existing records in the result
|
||||
// It's the identifier "memory"
|
||||
$identifierMap = array();
|
||||
// Holds for each class a pointer to the last previously seen element in the result set
|
||||
$resultPointers = array();
|
||||
// holds the values of the identifier/primary key fields of components,
|
||||
// separated by a pipe '|' and grouped by component alias (r, u, i, ... whatever)
|
||||
// the $idTemplate is a prepared template. $id is set to a fresh template when
|
||||
// starting to process a row.
|
||||
$id = array();
|
||||
$idTemplate = array();
|
||||
|
||||
// Holds the resulting hydrated data structure
|
||||
if ($this->_isResultMixed) {
|
||||
$result = array();
|
||||
} else {
|
||||
$result = $driver->getElementCollection($rootComponentName);
|
||||
}
|
||||
|
||||
if ($stmt === false || $stmt === 0) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Initialize
|
||||
foreach ($this->_queryComponents as $dqlAlias => $component) {
|
||||
// disable lazy-loading of related elements during hydration
|
||||
$component['table']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
|
||||
$componentName = $component['table']->getClassName();
|
||||
$listeners[$componentName] = $component['table']->getRecordListener();
|
||||
$identifierMap[$dqlAlias] = array();
|
||||
$resultPointers[$dqlAlias] = array();
|
||||
$idTemplate[$dqlAlias] = '';
|
||||
}
|
||||
|
||||
// Process result set
|
||||
$cache = array();
|
||||
while ($data = $stmt->fetch(Doctrine::FETCH_ASSOC)) {
|
||||
$id = $idTemplate; // initialize the id-memory
|
||||
$nonemptyComponents = array();
|
||||
$rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents);
|
||||
|
||||
//
|
||||
// hydrate the data of the root entity from the current row
|
||||
//
|
||||
$class = $this->_queryComponents[$rootAlias]['table'];
|
||||
$componentName = $class->getComponentName();
|
||||
|
||||
// just event stuff
|
||||
$event->set('data', $rowData[$rootAlias]);
|
||||
$listeners[$componentName]->preHydrate($event);
|
||||
//--
|
||||
|
||||
// Check for an existing element
|
||||
$index = false;
|
||||
if ($isSimpleQuery || ! isset($identifierMap[$rootAlias][$id[$rootAlias]])) {
|
||||
$element = $driver->getElement($rowData[$rootAlias], $componentName);
|
||||
|
||||
// just event stuff
|
||||
$event->set('data', $element);
|
||||
$listeners[$componentName]->postHydrate($event);
|
||||
//--
|
||||
|
||||
// do we need to index by a custom field?
|
||||
if ($field = $this->_getCustomIndexField($rootAlias)) {
|
||||
if (isset($result[$field])) {
|
||||
throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found non-unique key mapping.");
|
||||
} else if ( ! isset($element[$field])) {
|
||||
throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found a non-existent key.");
|
||||
}
|
||||
if ($this->_isResultMixed) {
|
||||
$result[] = array($element[$field] => $element);
|
||||
} else {
|
||||
$result[$element[$field]] = $element;
|
||||
}
|
||||
} else {
|
||||
if ($this->_isResultMixed) {
|
||||
$result[] = array($element);
|
||||
} else {
|
||||
$result[] = $element;
|
||||
}
|
||||
}
|
||||
|
||||
$identifierMap[$rootAlias][$id[$rootAlias]] = $driver->getLastKey($result);
|
||||
} else {
|
||||
$index = $identifierMap[$rootAlias][$id[$rootAlias]];
|
||||
}
|
||||
|
||||
$this->_setLastElement($resultPointers, $result, $index, $rootAlias, false);
|
||||
unset($rowData[$rootAlias]);
|
||||
// end hydrate data of the root component for the current row
|
||||
|
||||
// Check for scalar values
|
||||
if (isset($rowData['scalars'])) {
|
||||
$scalars = $rowData['scalars'];
|
||||
unset($rowData['scalars']);
|
||||
}
|
||||
|
||||
// $prev[$rootAlias] now points to the last element in $result.
|
||||
// now hydrate the rest of the data found in the current row, that belongs to other
|
||||
// (related) components.
|
||||
foreach ($rowData as $dqlAlias => $data) {
|
||||
$index = false;
|
||||
$map = $this->_queryComponents[$dqlAlias];
|
||||
$componentName = $map['table']->getComponentName();
|
||||
|
||||
// just event stuff
|
||||
$event->set('data', $data);
|
||||
$listeners[$componentName]->preHydrate($event);
|
||||
//--
|
||||
|
||||
$parent = $map['parent'];
|
||||
$relation = $map['relation'];
|
||||
$relationAlias = $relation->getAlias();
|
||||
|
||||
$path = $parent . '.' . $dqlAlias;
|
||||
|
||||
$key = key(reset($resultPointers));
|
||||
if ($this->_isResultMixed && $parent == $rootAlias && isset($resultPointers[$parent][$key])) {
|
||||
$baseElement =& $resultPointers[$parent][$key];
|
||||
} else if (isset($resultPointers[$parent])) {
|
||||
$baseElement =& $resultPointers[$parent];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check the type of the relation (many or single-valued)
|
||||
if ( ! $relation->isOneToOne()) {
|
||||
// x-many relation
|
||||
$oneToOne = false;
|
||||
if (isset($nonemptyComponents[$dqlAlias])) {
|
||||
$driver->initRelated($baseElement, $relationAlias);
|
||||
if ( ! isset($identifierMap[$path][$id[$parent]][$id[$dqlAlias]])) {
|
||||
$element = $driver->getElement($data, $componentName);
|
||||
|
||||
// just event stuff
|
||||
$event->set('data', $element);
|
||||
$listeners[$componentName]->postHydrate($event);
|
||||
//--
|
||||
|
||||
if ($field = $this->_getCustomIndexField($dqlAlias)) {
|
||||
// TODO: we should check this earlier. Fields used in INDEXBY
|
||||
// must be unique. Then this can be removed here.
|
||||
if (isset($baseElement[$relationAlias][$field])) {
|
||||
throw Doctrine_Hydrator_Exception::nonUniqueKeyMapping();
|
||||
} else if ( ! isset($element[$field])) {
|
||||
throw Doctrine_Hydrator_Exception::nonExistantFieldUsedAsIndex($field);
|
||||
}
|
||||
$baseElement[$relationAlias][$element[$field]] = $element;
|
||||
} else {
|
||||
$baseElement[$relationAlias][] = $element;
|
||||
}
|
||||
|
||||
$identifierMap[$path][$id[$parent]][$id[$dqlAlias]] = $driver->getLastKey($baseElement[$relationAlias]);
|
||||
} else {
|
||||
$index = $identifierMap[$path][$id[$parent]][$id[$dqlAlias]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// x-1 relation
|
||||
$oneToOne = true;
|
||||
if ( ! isset($nonemptyComponents[$dqlAlias])) {
|
||||
$baseElement[$relationAlias] = $driver->getNullPointer();
|
||||
} else if ( ! isset($baseElement[$relationAlias])) {
|
||||
$baseElement[$relationAlias] = $driver->getElement($data, $componentName);
|
||||
}
|
||||
}
|
||||
$coll =& $baseElement[$relationAlias];
|
||||
$this->_setLastElement($resultPointers, $coll, $index, $dqlAlias, $oneToOne);
|
||||
}
|
||||
|
||||
// append scalar values
|
||||
if (isset($scalars)) {
|
||||
$rowNumber = count($result) - 1;
|
||||
foreach ($scalars as $name => $value) {
|
||||
$result[$rowNumber][$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
$driver->flush();
|
||||
|
||||
// re-enable lazy loading
|
||||
foreach ($this->_queryComponents as $dqlAlias => $data) {
|
||||
$data['table']->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, true);
|
||||
}
|
||||
|
||||
//$e = microtime(true);
|
||||
//echo 'Hydration took: ' . ($e - $s) . ' for '.count($result).' records<br />';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* _setLastElement
|
||||
*
|
||||
* sets the last element of given data array / collection
|
||||
* as previous element
|
||||
*
|
||||
* @param array $prev The array that contains the pointers to the latest element of each class.
|
||||
* @param array|Collection The object collection.
|
||||
* @param boolean|integer $index Index of the element in the collection.
|
||||
* @param string $dqlAlias
|
||||
* @param boolean $oneToOne Whether it is a single-valued association or not.
|
||||
* @return void
|
||||
* @todo Detailed documentation
|
||||
*/
|
||||
protected function _setLastElement(&$resultPointers, &$coll, $index, $dqlAlias, $oneToOne)
|
||||
{
|
||||
if ($coll === $this->_nullObject) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($index !== false) {
|
||||
// Link element at $index to previous element for the component
|
||||
// identified by the DQL alias $alias
|
||||
$resultPointers[$dqlAlias] =& $coll[$index];
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_array($coll) && $coll) {
|
||||
if ($oneToOne) {
|
||||
$resultPointers[$dqlAlias] =& $coll;
|
||||
} else {
|
||||
end($coll);
|
||||
$resultPointers[$dqlAlias] =& $coll[key($coll)];
|
||||
}
|
||||
} else if ($coll instanceof Doctrine_Record) {
|
||||
$resultPointers[$dqlAlias] = $coll;
|
||||
} else if (count($coll) > 0) {
|
||||
$resultPointers[$dqlAlias] = $coll->getLast();
|
||||
} else if (isset($resultPointers[$dqlAlias])) {
|
||||
unset($resultPointers[$dqlAlias]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the fields of a data row into a new array, grouped by the component
|
||||
* they belong to. The column names in the result set are mapped to their
|
||||
* field names during this procedure.
|
||||
*
|
||||
* @return array An array with all the fields (name => value) of the data row,
|
||||
* grouped by their component (alias).
|
||||
*/
|
||||
protected function _gatherRowData(&$data, &$cache, &$id, &$nonemptyComponents)
|
||||
{
|
||||
$rowData = array();
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
// Parse each column name only once. Cache the results.
|
||||
if ( ! isset($cache[$key])) {
|
||||
// cache general information like the column name <-> field name mapping
|
||||
$e = explode('__', $key);
|
||||
$columnName = strtolower(array_pop($e));
|
||||
$cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))];
|
||||
$mapper = $this->_queryComponents[$cache[$key]['dqlAlias']]['mapper'];
|
||||
$classMetadata = $mapper->getClassMetadata();
|
||||
// check whether it's an aggregate value or a regular field
|
||||
if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName])) {
|
||||
$fieldName = $this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName];
|
||||
$cache[$key]['isScalar'] = true;
|
||||
} else {
|
||||
$fieldName = $mapper->getFieldName($columnName);
|
||||
$cache[$key]['isScalar'] = false;
|
||||
}
|
||||
|
||||
$cache[$key]['fieldName'] = $fieldName;
|
||||
|
||||
// cache identifier information
|
||||
if ($classMetadata->isIdentifier($fieldName)) {
|
||||
$cache[$key]['isIdentifier'] = true;
|
||||
} else {
|
||||
$cache[$key]['isIdentifier'] = false;
|
||||
}
|
||||
|
||||
// cache type information
|
||||
$type = $classMetadata->getTypeOfColumn($columnName);
|
||||
if ($type == 'integer' || $type == 'string') {
|
||||
$cache[$key]['isSimpleType'] = true;
|
||||
} else {
|
||||
$cache[$key]['type'] = $type;
|
||||
$cache[$key]['isSimpleType'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
$mapper = $this->_queryComponents[$cache[$key]['dqlAlias']]['mapper'];
|
||||
$dqlAlias = $cache[$key]['dqlAlias'];
|
||||
$fieldName = $cache[$key]['fieldName'];
|
||||
|
||||
if ($cache[$key]['isScalar']) {
|
||||
$rowData['scalars'][$fieldName] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($cache[$key]['isIdentifier']) {
|
||||
$id[$dqlAlias] .= '|' . $value;
|
||||
}
|
||||
|
||||
if ($cache[$key]['isSimpleType']) {
|
||||
$rowData[$dqlAlias][$fieldName] = $value;
|
||||
} else {
|
||||
$rowData[$dqlAlias][$fieldName] = $mapper->prepareValue(
|
||||
$fieldName, $value, $cache[$key]['type']);
|
||||
}
|
||||
|
||||
if ( ! isset($nonemptyComponents[$dqlAlias]) && $value !== null) {
|
||||
$nonemptyComponents[$dqlAlias] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $rowData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the custom field used for indexing for the specified component alias.
|
||||
*
|
||||
* @return string The field name of the field used for indexing or NULL
|
||||
* if the component does not use any custom field indices.
|
||||
*/
|
||||
protected function _getCustomIndexField($alias)
|
||||
{
|
||||
return isset($this->_queryComponents[$alias]['map']) ? $this->_queryComponents[$alias]['map'] : null;
|
||||
}
|
||||
|
||||
|
||||
private $_isResultMixed = false;
|
||||
public function setResultMixed($bool)
|
||||
{
|
||||
$this->_isResultMixed = $bool;
|
||||
}
|
||||
|
||||
}
|
@ -90,23 +90,6 @@ class Doctrine_Mapper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* createQuery
|
||||
* creates a new Doctrine_Query object and adds the component name
|
||||
* of this table as the query 'from' part
|
||||
*
|
||||
* @param string Optional alias name for component aliasing.
|
||||
*
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function createQuery($alias = '')
|
||||
{
|
||||
if ( ! empty($alias)) {
|
||||
$alias = ' ' . trim($alias);
|
||||
}
|
||||
return Doctrine_Query::create($this->_conn)->from($this->getComponentName() . $alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the connection for this class
|
||||
*
|
||||
@ -139,7 +122,7 @@ class Doctrine_Mapper
|
||||
*/
|
||||
public function create(array $array = array())
|
||||
{
|
||||
$record = new $this->_domainClassName($this, true);
|
||||
$record = new $this->_domainClassName();
|
||||
$record->fromArray($array);
|
||||
|
||||
return $record;
|
||||
@ -177,79 +160,6 @@ class Doctrine_Mapper
|
||||
{
|
||||
return $this->_conn->unitOfWork->detach($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an entity by its primary key.
|
||||
*
|
||||
* @param $id database row id
|
||||
* @param int $hydrationMode Doctrine::HYDRATE_ARRAY or Doctrine::HYDRATE_RECORD
|
||||
* @return mixed Array or Doctrine_Record or false if no result
|
||||
* @todo Remove. Move to EntityRepository.
|
||||
*/
|
||||
public function find($id, $hydrationMode = null)
|
||||
{
|
||||
if (is_null($id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = is_array($id) ? array_values($id) : array($id);
|
||||
|
||||
return $this->createQuery()
|
||||
->where(implode(' = ? AND ', (array) $this->_classMetadata->getIdentifier()) . ' = ?')
|
||||
->fetchOne($id, $hydrationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all entities of the mapper's class.
|
||||
* Use with care.
|
||||
*
|
||||
* @param int $hydrationMode Doctrine::HYDRATE_ARRAY or Doctrine::HYDRATE_RECORD
|
||||
* @return Doctrine_Collection
|
||||
* @todo Remove. Move to EntityRepository.
|
||||
*/
|
||||
public function findAll($hydrationMode = null)
|
||||
{
|
||||
return $this->createQuery()->execute(array(), $hydrationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* findBySql
|
||||
* finds records with given SQL where clause
|
||||
* returns a collection of records
|
||||
*
|
||||
* @param string $dql DQL after WHERE clause
|
||||
* @param array $params query parameters
|
||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
||||
* @return Doctrine_Collection
|
||||
*
|
||||
* @todo This actually takes DQL, not SQL, but it requires column names
|
||||
* instead of field names. This should be fixed to use raw SQL instead.
|
||||
* @todo Remove. Move to EntityRepository.
|
||||
*/
|
||||
public function findBySql($dql, array $params = array(), $hydrationMode = null)
|
||||
{
|
||||
return $this->createQuery()->where($dql)->execute($params, $hydrationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* findByDql
|
||||
* finds records with given DQL where clause
|
||||
* returns a collection of records
|
||||
*
|
||||
* @param string $dql DQL after WHERE clause
|
||||
* @param array $params query parameters
|
||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
||||
* @return Doctrine_Collection
|
||||
* @todo Remove. Move to EntityRepository.
|
||||
*/
|
||||
public function findByDql($dql, array $params = array(), $hydrationMode = null)
|
||||
{
|
||||
$query = new Doctrine_Query($this->_conn);
|
||||
$component = $this->getComponentName();
|
||||
$dql = 'FROM ' . $component . ' WHERE ' . $dql;
|
||||
|
||||
return $query->query($dql, $params, $hydrationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a named query.
|
||||
@ -349,9 +259,7 @@ class Doctrine_Mapper
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
$record = new $this->_domainClassName($this, true, $data);
|
||||
$data = array();
|
||||
return $record;
|
||||
return new $this->_domainClassName(true, $data);
|
||||
}
|
||||
|
||||
$idHash = $this->_conn->unitOfWork->getIdentifierHash($id);
|
||||
@ -360,12 +268,12 @@ class Doctrine_Mapper
|
||||
$this->_classMetadata->getRootClassName())) {
|
||||
$record->hydrate($data);
|
||||
} else {
|
||||
$record = new $this->_domainClassName($this, false, $data);
|
||||
$record = new $this->_domainClassName(false, $data);
|
||||
$this->_conn->unitOfWork->registerIdentity($record);
|
||||
}
|
||||
$data = array();
|
||||
} else {
|
||||
$record = new $this->_domainClassName($this, true, $data);
|
||||
$record = new $this->_domainClassName(true, $data);
|
||||
}
|
||||
|
||||
return $record;
|
||||
@ -545,83 +453,6 @@ class Doctrine_Mapper
|
||||
return $this->_domainClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* findBy
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $value
|
||||
* @param string $hydrationMode
|
||||
* @return void
|
||||
* @todo Remove. Move to EntityRepository.
|
||||
*/
|
||||
protected function findBy($fieldName, $value, $hydrationMode = null)
|
||||
{
|
||||
return $this->createQuery()->where($fieldName . ' = ?')->execute(array($value), $hydrationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* findOneBy
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $value
|
||||
* @param string $hydrationMode
|
||||
* @return void
|
||||
* @todo Remove. Move to EntityRepository.
|
||||
*/
|
||||
protected function findOneBy($fieldName, $value, $hydrationMode = null)
|
||||
{
|
||||
$results = $this->createQuery()->where($fieldName . ' = ?')->limit(1)->execute(
|
||||
array($value), $hydrationMode);
|
||||
return $hydrationMode === Doctrine::HYDRATE_ARRAY ? array_shift($results) : $results->getFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* __call
|
||||
*
|
||||
* Adds support for magic finders.
|
||||
* findByColumnName, findByRelationAlias
|
||||
* findById, findByContactId, etc.
|
||||
*
|
||||
* @return void
|
||||
* @throws Doctrine_Mapper_Exception If the method called is an invalid find* method
|
||||
* or no find* method at all and therefore an invalid
|
||||
* method call.
|
||||
* @todo Remove. Move to EntityRepository.
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
if (substr($method, 0, 6) == 'findBy') {
|
||||
$by = substr($method, 6, strlen($method));
|
||||
$method = 'findBy';
|
||||
} else if (substr($method, 0, 9) == 'findOneBy') {
|
||||
$by = substr($method, 9, strlen($method));
|
||||
$method = 'findOneBy';
|
||||
} else {
|
||||
throw new Doctrine_Mapper_Exception("Undefined method '$method'.");
|
||||
}
|
||||
|
||||
if (isset($by)) {
|
||||
if ( ! isset($arguments[0])) {
|
||||
throw new Doctrine_Mapper_Exception('You must specify the value to findBy.');
|
||||
}
|
||||
|
||||
$fieldName = Doctrine::tableize($by);
|
||||
$hydrationMode = isset($arguments[1]) ? $arguments[1]:null;
|
||||
|
||||
if ($this->_classMetadata->hasField($fieldName)) {
|
||||
return $this->$method($fieldName, $arguments[0], $hydrationMode);
|
||||
} else if ($this->_classMetadata->hasRelation($by)) {
|
||||
$relation = $this->_classMetadata->getRelation($by);
|
||||
if ($relation['type'] === Doctrine_Relation::MANY) {
|
||||
throw new Doctrine_Mapper_Exception('Cannot findBy many relationship.');
|
||||
}
|
||||
return $this->$method($relation['local'], $arguments[0], $hydrationMode);
|
||||
} else {
|
||||
throw new Doctrine_Mapper_Exception('Cannot find by: ' . $by . '. Invalid field or relationship alias.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves an entity and all it's related entities.
|
||||
*
|
||||
@ -795,7 +626,12 @@ class Doctrine_Mapper
|
||||
$query = 'DELETE FROM ' . $assocTable->getTableName()
|
||||
. ' WHERE ' . $rel->getForeign() . ' = ?'
|
||||
. ' AND ' . $rel->getLocal() . ' = ?';
|
||||
$this->_conn->execute($query, array($r->getIncremented(), $record->getIncremented()));
|
||||
// FIXME: composite key support
|
||||
$ids1 = $r->identifier();
|
||||
$id1 = count($ids1) > 0 ? array_pop($ids1) : null;
|
||||
$ids2 = $record->identifier();
|
||||
$id2 = count($ids2) > 0 ? array_pop($ids2) : null;
|
||||
$this->_conn->execute($query, array($id1, $id2));
|
||||
}
|
||||
|
||||
$assocMapper = $this->_conn->getMapper($assocTable->getComponentName());
|
||||
@ -804,7 +640,6 @@ class Doctrine_Mapper
|
||||
$assocRecord->set($assocTable->getFieldName($rel->getForeign()), $r);
|
||||
$assocRecord->set($assocTable->getFieldName($rel->getLocal()), $record);
|
||||
$assocMapper->save($assocRecord);
|
||||
//$this->saveSingleRecord($assocRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -890,19 +725,6 @@ class Doctrine_Mapper
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasAttribute($key)
|
||||
{
|
||||
switch ($key) {
|
||||
case Doctrine::ATTR_LOAD_REFERENCES:
|
||||
case Doctrine::ATTR_QUERY_LIMIT:
|
||||
case Doctrine::ATTR_COLL_KEY:
|
||||
case Doctrine::ATTR_VALIDATE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function executeQuery(Doctrine_Query $query)
|
||||
{
|
||||
|
||||
|
@ -111,7 +111,8 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy
|
||||
if ( ! $value->exists()) {
|
||||
$value->save();
|
||||
}
|
||||
$record->set($field, $value->getIncremented());
|
||||
$idValues = $value->identifier();
|
||||
$record->set($field, $idValues[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.org>.
|
||||
*/
|
||||
Doctrine::autoload('Doctrine_Query_Abstract');
|
||||
|
||||
/**
|
||||
* Doctrine_Query
|
||||
* A Doctrine_Query object represents a DQL query. It is used to query databases for
|
||||
|
@ -117,12 +117,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* @var Doctrine_ClassMetadata
|
||||
*/
|
||||
protected $_class;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Doctrine_Mapper
|
||||
*/
|
||||
protected $_mapper;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -186,6 +180,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* @var array
|
||||
*/
|
||||
protected $_references = array();
|
||||
|
||||
/**
|
||||
* The EntityManager that is responsible for the persistence of the entity.
|
||||
*
|
||||
* @var Doctrine_EntityManager
|
||||
*/
|
||||
protected $_em;
|
||||
|
||||
/**
|
||||
* The object identifier of the object. Each object has a unique identifier during runtime.
|
||||
@ -206,23 +207,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* open connections
|
||||
* @throws Doctrine_Record_Exception if the cleanData operation fails somehow
|
||||
*/
|
||||
public function __construct($mapper = null, $isNewEntry = false, array $data = array())
|
||||
public function __construct($isNewEntry = true, array $data = array())
|
||||
{
|
||||
if (isset($mapper) && $mapper instanceof Doctrine_Mapper) {
|
||||
$class = get_class($this);
|
||||
$this->_mapper = $mapper;
|
||||
$this->_class = $this->_mapper->getClassMetadata();
|
||||
$exists = ! $isNewEntry;
|
||||
} else {
|
||||
$this->_mapper = Doctrine_Manager::getInstance()->getMapper(get_class($this));
|
||||
$this->_class = $this->_mapper->getClassMetadata();
|
||||
$exists = false;
|
||||
}
|
||||
|
||||
$this->_entityName = $this->_mapper->getMappedClassName();
|
||||
$this->_oid = self::$_index;
|
||||
$this->_entityName = get_class($this);
|
||||
$this->_em = Doctrine_Manager::getInstance()->getCurrentConnection();
|
||||
$this->_class = $this->_em->getClassMetadata($this->_entityName);
|
||||
|
||||
self::$_index++;
|
||||
$this->_oid = self::$_index++;
|
||||
|
||||
// get the data array
|
||||
$this->_data = $data;
|
||||
@ -232,9 +223,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->_values = $this->cleanData($this->_data);
|
||||
|
||||
$this->_extractIdentifier($exists);
|
||||
$this->_extractIdentifier( ! $isNewEntry);
|
||||
|
||||
if ( ! $exists) {
|
||||
if ($isNewEntry) {
|
||||
if ($count > count($this->_values)) {
|
||||
$this->_state = Doctrine_Record::STATE_TDIRTY;
|
||||
} else {
|
||||
@ -252,7 +243,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
}
|
||||
|
||||
self::$_useAutoAccessorOverride = false; // @todo read from attribute the first time
|
||||
$this->_mapper->manage($this);
|
||||
$this->_em->manage($this);
|
||||
$this->construct();
|
||||
}
|
||||
|
||||
@ -510,13 +501,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$tmp = $data;
|
||||
$data = array();
|
||||
|
||||
$fieldNames = $this->_mapper->getFieldNames();
|
||||
$fieldNames = $this->_em->getMapper($this->_entityName)->getFieldNames();
|
||||
foreach ($fieldNames as $fieldName) {
|
||||
if (isset($tmp[$fieldName])) {
|
||||
$data[$fieldName] = $tmp[$fieldName];
|
||||
} else if (array_key_exists($fieldName, $tmp)) {
|
||||
$data[$fieldName] = Doctrine_Null::$INSTANCE;
|
||||
} else if (!isset($this->_data[$fieldName])) {
|
||||
} else if ( ! isset($this->_data[$fieldName])) {
|
||||
$data[$fieldName] = Doctrine_Null::$INSTANCE;
|
||||
}
|
||||
unset($tmp[$fieldName]);
|
||||
@ -554,7 +545,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
case Doctrine::IDENTIFIER_AUTOINC:
|
||||
case Doctrine::IDENTIFIER_SEQUENCE:
|
||||
case Doctrine::IDENTIFIER_NATURAL:
|
||||
$name = (array)$this->_class->getIdentifier();
|
||||
$name = $this->_class->getIdentifier();
|
||||
$name = $name[0];
|
||||
if ($exists) {
|
||||
if (isset($this->_data[$name]) && $this->_data[$name] !== Doctrine_Null::$INSTANCE) {
|
||||
@ -563,7 +554,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
}
|
||||
break;
|
||||
case Doctrine::IDENTIFIER_COMPOSITE:
|
||||
$names = (array)$this->_class->getIdentifier();
|
||||
$names = $this->_class->getIdentifier();
|
||||
|
||||
foreach ($names as $name) {
|
||||
if ($this->_data[$name] === Doctrine_Null::$INSTANCE) {
|
||||
@ -575,6 +566,14 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL:
|
||||
*/
|
||||
final public function setIdentifier(array $identifier)
|
||||
{
|
||||
$this->_id = $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the entity.
|
||||
@ -596,6 +595,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
unset($vars['_errorStack']);
|
||||
unset($vars['_filter']);
|
||||
unset($vars['_node']);
|
||||
unset($vars['_em']);
|
||||
|
||||
//$name = (array)$this->_table->getIdentifier();
|
||||
$this->_data = array_merge($this->_data, $this->_id);
|
||||
@ -642,13 +642,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->preUnserialize($event);
|
||||
|
||||
$manager = Doctrine_Manager::getInstance();
|
||||
$manager = Doctrine_Manager::getInstance();
|
||||
$connection = $manager->getConnectionForComponent(get_class($this));
|
||||
|
||||
$this->_oid = self::$_index;
|
||||
self::$_index++;
|
||||
|
||||
$this->_mapper = $connection->getMapper(get_class($this));
|
||||
$this->_em = $connection;
|
||||
|
||||
$array = unserialize($serialized);
|
||||
|
||||
@ -656,7 +656,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$this->$k = $v;
|
||||
}
|
||||
|
||||
$this->_class = $this->_mapper->getTable();
|
||||
$this->_entityName = get_class($this);
|
||||
$this->_class = $this->_em->getClassMetadata($this->_entityName);
|
||||
|
||||
foreach ($this->_data as $k => $v) {
|
||||
switch ($this->_class->getTypeOf($k)) {
|
||||
@ -674,7 +675,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
}
|
||||
}
|
||||
|
||||
$this->_mapper->manage($this);
|
||||
$this->_em->manage($this);
|
||||
$this->cleanData($this->_data);
|
||||
$this->_extractIdentifier($this->exists());
|
||||
|
||||
@ -749,7 +750,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$id = array_values($id);
|
||||
|
||||
if ($deep) {
|
||||
$query = $this->_mapper->createQuery();
|
||||
$query = $this->_class->getConnection()->createQuery()->from($this->_entityName);
|
||||
foreach (array_keys($this->_references) as $name) {
|
||||
$query->leftJoin(get_class($this) . '.' . $name);
|
||||
}
|
||||
@ -758,7 +759,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$record = $query->fetchOne($id);
|
||||
} else {
|
||||
// Use FETCH_ARRAY to avoid clearing object relations
|
||||
$record = $this->_mapper->find($id, Doctrine::HYDRATE_ARRAY);
|
||||
$record = $this->getRepository()->find($this->identifier(), Doctrine::HYDRATE_ARRAY);
|
||||
if ($record) {
|
||||
$this->hydrate($record);
|
||||
}
|
||||
@ -929,8 +930,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
}
|
||||
return $this->_references[$fieldName];
|
||||
} catch (Doctrine_Relation_Exception $e) {
|
||||
echo $e->getTraceAsString();
|
||||
echo "<br/><br/>";
|
||||
//echo $e->getTraceAsString();
|
||||
//echo "<br/><br/>";
|
||||
foreach ($this->_class->getFilters() as $filter) {
|
||||
if (($value = $filter->filterGet($this, $fieldName, $value)) !== null) {
|
||||
return $value;
|
||||
@ -979,7 +980,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
if (isset($this->_data[$fieldName])) {
|
||||
if ($value instanceof Doctrine_Record) {
|
||||
$type = $this->_class->getTypeOf($fieldName);
|
||||
$id = $value->getIncremented();
|
||||
// FIXME: composite key support
|
||||
$ids = $value->identifier();
|
||||
$id = count($ids) > 0 ? array_pop($ids) : null;
|
||||
if ($id !== null && $type !== 'object') {
|
||||
$value = $id;
|
||||
}
|
||||
@ -998,6 +1001,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->_data[$fieldName] = $value;
|
||||
$this->_modified[] = $fieldName;
|
||||
|
||||
/* We can't do this currently because there are tests that change
|
||||
* the primary key of already persisted entities (ugh). */
|
||||
if ($this->isTransient() && $this->_class->isIdentifier($fieldName)) {
|
||||
$this->_id[$fieldName] = $value;
|
||||
}
|
||||
|
||||
switch ($this->_state) {
|
||||
case Doctrine_Record::STATE_CLEAN:
|
||||
$this->_state = Doctrine_Record::STATE_DIRTY;
|
||||
@ -1011,8 +1021,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
try {
|
||||
$this->_coreSetRelated($fieldName, $value);
|
||||
} catch (Doctrine_Relation_Exception $e) {
|
||||
echo $e->getTraceAsString();
|
||||
echo "<br/><br/>";
|
||||
//echo $e->getTraceAsString();
|
||||
//echo "<br/><br/>";
|
||||
foreach ($this->_class->getFilters() as $filter) {
|
||||
if (($value = $filter->filterSet($this, $fieldName, $value)) !== null) {
|
||||
return $value;
|
||||
@ -1131,7 +1141,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
public function save(Doctrine_Connection $conn = null)
|
||||
{
|
||||
// TODO: Forward to EntityManager. There: registerNew() OR registerDirty() on UnitOfWork.
|
||||
$this->_mapper->save($this, $conn);
|
||||
$this->_em->save($this, $conn);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1175,7 +1185,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
public function replace(Doctrine_Connection $conn = null)
|
||||
{
|
||||
if ($conn === null) {
|
||||
$conn = $this->_mapper->getConnection();
|
||||
$conn = $this->_em;
|
||||
}
|
||||
|
||||
return $conn->replace($this->_class, $this->getPrepared(), $this->_id);
|
||||
@ -1249,7 +1259,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
break;
|
||||
default:
|
||||
if ($this->_data[$field] instanceof Doctrine_Record) {
|
||||
$this->_data[$field] = $this->_data[$field]->getIncremented();
|
||||
// FIXME: composite key support
|
||||
$ids = $this->_data[$field]->identifier();
|
||||
$id = count($ids) > 0 ? array_pop($ids) : null;
|
||||
$this->_data[$field] = $id;
|
||||
}
|
||||
/** TODO:
|
||||
if ($this->_data[$v] === null) {
|
||||
@ -1313,8 +1326,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
if ($this->_class->getIdentifierType() == Doctrine::IDENTIFIER_AUTOINC) {
|
||||
$idFieldNames = (array)$this->_class->getIdentifier();
|
||||
$id = $idFieldNames[0];
|
||||
$a[$id] = $this->getIncremented();
|
||||
$idFieldName = $idFieldNames[0];
|
||||
|
||||
$ids = $this->identifier();
|
||||
$id = count($ids) > 0 ? array_pop($ids) : null;
|
||||
|
||||
$a[$idFieldName] = $id;
|
||||
}
|
||||
|
||||
if ($deep) {
|
||||
@ -1460,17 +1477,41 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* Checks whether the entity already has a persistent state.
|
||||
*
|
||||
* @return boolean TRUE if the object is new, FALSE otherwise.
|
||||
* @deprecated Use isTransient()
|
||||
*/
|
||||
public function isNew()
|
||||
{
|
||||
return $this->_state == self::STATE_TCLEAN || $this->_state == self::STATE_TDIRTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the entity already has a persistent state.
|
||||
*
|
||||
* @return boolean TRUE if the object is new, FALSE otherwise.
|
||||
*/
|
||||
public function isTransient()
|
||||
{
|
||||
return $this->_state == self::STATE_TCLEAN || $this->_state == self::STATE_TDIRTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the entity has been modified since it was last synchronized
|
||||
* with the database.
|
||||
*
|
||||
* @return boolean TRUE if the object has been modified, FALSE otherwise.
|
||||
*/
|
||||
public function isDirty()
|
||||
{
|
||||
return ($this->_state === Doctrine_Record::STATE_DIRTY ||
|
||||
$this->_state === Doctrine_Record::STATE_TDIRTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the entity has been modified since it was last synchronized
|
||||
* with the database.
|
||||
*
|
||||
* @return boolean TRUE if the object has been modified, FALSE otherwise.
|
||||
* @deprecated Use isDirty()
|
||||
*/
|
||||
public function isModified()
|
||||
{
|
||||
@ -1496,6 +1537,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
/**
|
||||
* getIterator
|
||||
* @return Doctrine_Record_Iterator a Doctrine_Record_Iterator that iterates through the data
|
||||
* @todo Really needed/useful?
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
@ -1513,7 +1555,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
public function delete(Doctrine_Connection $conn = null)
|
||||
{
|
||||
// TODO: Forward to EntityManager. There: registerRemoved() on UnitOfWork
|
||||
return $this->_mapper->delete($this, $conn);
|
||||
return $this->_em->remove($this, $conn);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1532,7 +1574,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
unset($data[$id]);
|
||||
}
|
||||
|
||||
$ret = $this->_mapper->create($data);
|
||||
$ret = $this->_em->createEntity($this->_entityName, $data);
|
||||
$modified = array();
|
||||
|
||||
foreach ($data as $key => $val) {
|
||||
@ -1581,7 +1623,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$this->_data[$fieldName] = $value;
|
||||
}
|
||||
} else {
|
||||
$idFieldNames = (array)$this->_class->getIdentifier();
|
||||
$idFieldNames = $this->_class->getIdentifier();
|
||||
$name = $idFieldNames[0];
|
||||
$this->_id[$name] = $id;
|
||||
$this->_data[$name] = $id;
|
||||
@ -1601,23 +1643,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the value of autoincremented primary key of this object (if any)
|
||||
*
|
||||
* @return integer
|
||||
* @todo Better name? Not sure this is the right place here.
|
||||
* @todo Plays against full composite key support..
|
||||
*/
|
||||
final public function getIncremented()
|
||||
{
|
||||
$id = current($this->_id);
|
||||
if ($id === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* hasRefence
|
||||
* @param string $name
|
||||
@ -1964,15 +1989,15 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
{
|
||||
return $this->_class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mapper of the entity.
|
||||
*
|
||||
* @return Doctrine_Mapper
|
||||
*/
|
||||
public function getMapper()
|
||||
|
||||
public function getEntityManager()
|
||||
{
|
||||
return $this->_mapper;
|
||||
return $this->_em;
|
||||
}
|
||||
|
||||
public function getRepository()
|
||||
{
|
||||
return $this->_class->getConnection()->getRepository($this->_entityName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2002,8 +2027,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
public function free($deep = false)
|
||||
{
|
||||
if ($this->_state != self::STATE_LOCKED) {
|
||||
$this->_mapper->detach($this);
|
||||
$this->_mapper->removeRecord($this);
|
||||
$this->_em->detach($this);
|
||||
$this->_em->removeRecord($this);
|
||||
$this->_data = array();
|
||||
$this->_id = array();
|
||||
|
||||
|
@ -93,18 +93,15 @@ class Doctrine_Relation_Association extends Doctrine_Relation
|
||||
* @return Doctrine_Record|Doctrine_Collection
|
||||
*/
|
||||
public function fetchRelatedFor(Doctrine_Record $record)
|
||||
{
|
||||
$id = $record->getIncremented();
|
||||
//var_dump($id);
|
||||
//echo "<br /><br />";
|
||||
{
|
||||
// FIXME: composite key support
|
||||
$ids = $record->identifier();
|
||||
$id = count($ids) > 0 ? array_pop($ids) : null;
|
||||
|
||||
if (empty($id) || ! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
|
||||
//echo "here" . $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES);
|
||||
$coll = new Doctrine_Collection($this->getForeignComponentName());
|
||||
} else {
|
||||
$query = Doctrine_Query::create()->parseQuery($this->getRelationDql(1));
|
||||
//echo $query->getDql() . "<br />";
|
||||
//echo $query->getSql() . "<br />";
|
||||
//echo "<br /><br />";
|
||||
$coll = Doctrine_Query::create()->query($this->getRelationDql(1), array($id));
|
||||
}
|
||||
$coll->setReference($record, $this);
|
||||
|
@ -18,7 +18,7 @@
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.org>.
|
||||
*/
|
||||
Doctrine::autoload('Doctrine_Relation_Association');
|
||||
|
||||
/**
|
||||
* Doctrine_Relation_Association_Self
|
||||
*
|
||||
@ -75,8 +75,10 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association
|
||||
}
|
||||
|
||||
public function fetchRelatedFor(Doctrine_Record $record)
|
||||
{
|
||||
$id = $record->getIncremented();
|
||||
{
|
||||
// FIXME: composite key support
|
||||
$ids = $record->identifier();
|
||||
$id = count($ids) > 0 ? array_pop($ids) : null;
|
||||
|
||||
$q = new Doctrine_RawSql();
|
||||
|
||||
|
@ -74,35 +74,11 @@ class Doctrine_Relation_Nest extends Doctrine_Relation_Association
|
||||
return $dql;
|
||||
}
|
||||
|
||||
/**
|
||||
public function fetchRelatedFor(Doctrine_Record $record)
|
||||
{
|
||||
$id = $record->getIncremented();
|
||||
|
||||
if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
|
||||
return new Doctrine_Collection($this->getTable());
|
||||
} else {
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$c = $this->getTable()->getComponentName();
|
||||
$a = substr($c, 0, 1);
|
||||
$c2 = $this->getAssociationTable()->getComponentName();
|
||||
$a2 = substr($c2, 0, 1);
|
||||
|
||||
$q->from($c)
|
||||
->innerJoin($c . '.' . $c2)
|
||||
|
||||
$sub = 'SELECT ' . $this->getForeign()
|
||||
. ' FROM ' . $c2
|
||||
. ' WHERE ' . $this->getLocal()
|
||||
. ' = ?';
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public function fetchRelatedFor(Doctrine_Record $record)
|
||||
{
|
||||
$id = $record->getIncremented();
|
||||
// FIXME: composite key support
|
||||
$ids = $record->identifier();
|
||||
$id = count($ids) > 0 ? array_pop($ids) : null;
|
||||
|
||||
|
||||
if (empty($id) || ! $this->_foreignMapper->getClassMetadata()->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
|
||||
|
@ -147,12 +147,6 @@ class Doctrine_Relation_Parser
|
||||
$this->getRelations();
|
||||
return $this->getRelation($alias, false);
|
||||
} else {
|
||||
/*try {
|
||||
throw new Exception();
|
||||
} catch (Exception $e) {
|
||||
//echo "" . "<br />";
|
||||
///echo $e->getTraceAsString() . "<br /><br /><br />";
|
||||
}*/
|
||||
throw new Doctrine_Relation_Exception("Unknown relation '$alias'.");
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,8 @@ class Doctrine_Validator
|
||||
if ($value === Doctrine_Null::$INSTANCE) {
|
||||
$value = null;
|
||||
} else if ($value instanceof Doctrine_Record) {
|
||||
$value = $value->getIncremented();
|
||||
$ids = $value->identifier();
|
||||
$value = count($ids) > 0 ? array_pop($ids) : null;
|
||||
}
|
||||
|
||||
$dataType = $classMetadata->getTypeOf($fieldName);
|
||||
|
@ -9,11 +9,22 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/** The data of the hydration mode dataProvider */
|
||||
protected static $hydrationModeProviderData = array(
|
||||
array('hydrationMode' => Doctrine::HYDRATE_RECORD),
|
||||
array('hydrationMode' => Doctrine::HYDRATE_ARRAY)
|
||||
);
|
||||
/** Getter for the hydration mode dataProvider */
|
||||
public static function hydrationModeProvider()
|
||||
{
|
||||
return self::$hydrationModeProviderData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fakes the DQL query: select u.id, u.name from CmsUser u
|
||||
* Select u.id, u.name from CmsUser u
|
||||
*
|
||||
*/
|
||||
public function testBasic()
|
||||
public function testBasicHydration()
|
||||
{
|
||||
// Faked query components
|
||||
$queryComponents = array(
|
||||
@ -72,4 +83,285 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
|
||||
$this->assertEquals('jwage', $objectResult[1]->name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* select u.id, u.status, p.phonenumber, upper(u.name) nameUpper from User u
|
||||
* join u.phonenumbers p
|
||||
* =
|
||||
* select u.id, u.status, p.phonenumber, upper(u.name) as u__0 from USERS u
|
||||
* INNER JOIN PHONENUMBERS p ON u.id = p.user_id
|
||||
*
|
||||
* @dataProvider hydrationModeProvider
|
||||
*/
|
||||
public function testNewHydrationMixedQueryFetchJoin($hydrationMode)
|
||||
{
|
||||
// Faked query components
|
||||
$queryComponents = array(
|
||||
'u' => array(
|
||||
'table' => $this->sharedFixture['connection']->getClassMetadata('CmsUser'),
|
||||
'mapper' => $this->sharedFixture['connection']->getMapper('CmsUser'),
|
||||
'parent' => null,
|
||||
'relation' => null,
|
||||
'map' => null,
|
||||
'agg' => array('0' => 'nameUpper')
|
||||
),
|
||||
'p' => array(
|
||||
'table' => $this->sharedFixture['connection']->getClassMetadata('CmsPhonenumber'),
|
||||
'mapper' => $this->sharedFixture['connection']->getMapper('CmsPhonenumber'),
|
||||
'parent' => 'u',
|
||||
'relation' => $this->sharedFixture['connection']->getClassMetadata('CmsUser')->getRelation('phonenumbers'),
|
||||
'map' => null
|
||||
)
|
||||
);
|
||||
|
||||
// Faked table alias map
|
||||
$tableAliasMap = array(
|
||||
'u' => 'u',
|
||||
'p' => 'p'
|
||||
);
|
||||
|
||||
// Faked result set
|
||||
$resultSet = array(
|
||||
//row1
|
||||
array(
|
||||
'u__id' => '1',
|
||||
'u__status' => 'developer',
|
||||
'u__0' => 'ROMANB',
|
||||
'p__phonenumber' => '42',
|
||||
),
|
||||
array(
|
||||
'u__id' => '1',
|
||||
'u__status' => 'developer',
|
||||
'u__0' => 'ROMANB',
|
||||
'p__phonenumber' => '43',
|
||||
),
|
||||
array(
|
||||
'u__id' => '2',
|
||||
'u__status' => 'developer',
|
||||
'u__0' => 'JWAGE',
|
||||
'p__phonenumber' => '91'
|
||||
)
|
||||
);
|
||||
|
||||
$stmt = new Doctrine_HydratorMockStatement($resultSet);
|
||||
$hydrator = new Doctrine_HydratorNew();
|
||||
$hydrator->setQueryComponents($queryComponents);
|
||||
|
||||
$hydrator->setResultMixed(true);
|
||||
|
||||
$result = $hydrator->hydrateResultSet($stmt, $tableAliasMap, $hydrationMode);
|
||||
//var_dump($result);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertTrue(is_array($result[0]));
|
||||
$this->assertTrue(is_array($result[1]));
|
||||
|
||||
$this->assertEquals(3, count($result[0][0]));
|
||||
// first user => 2 phonenumbers
|
||||
$this->assertEquals(2, count($result[0][0]['phonenumbers']));
|
||||
$this->assertEquals('ROMANB', $result[0]['nameUpper']);
|
||||
// second user => 1 phonenumber
|
||||
$this->assertEquals(1, count($result[1][0]['phonenumbers']));
|
||||
$this->assertEquals('JWAGE', $result[1]['nameUpper']);
|
||||
|
||||
$this->assertEquals(42, $result[0][0]['phonenumbers'][0]['phonenumber']);
|
||||
$this->assertEquals(43, $result[0][0]['phonenumbers'][1]['phonenumber']);
|
||||
$this->assertEquals(91, $result[1][0]['phonenumbers'][0]['phonenumber']);
|
||||
|
||||
if ($hydrationMode == Doctrine::HYDRATE_RECORD) {
|
||||
$this->assertTrue($result[0][0] instanceof Doctrine_Record);
|
||||
$this->assertTrue($result[0][0]['phonenumbers'] instanceof Doctrine_Collection);
|
||||
$this->assertTrue($result[0][0]['phonenumbers'][0] instanceof Doctrine_Record);
|
||||
$this->assertTrue($result[0][0]['phonenumbers'][1] instanceof Doctrine_Record);
|
||||
$this->assertTrue($result[1][0] instanceof Doctrine_Record);
|
||||
$this->assertTrue($result[1][0]['phonenumbers'] instanceof Doctrine_Collection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* select u.id, u.status, count(p.phonenumber) numPhones from User u
|
||||
* join u.phonenumbers p group by u.status, u.id
|
||||
* =
|
||||
* select u.id, u.status, count(p.phonenumber) as p__0 from USERS u
|
||||
* INNER JOIN PHONENUMBERS p ON u.id = p.user_id group by u.id, u.status
|
||||
*
|
||||
* @dataProvider hydrationModeProvider
|
||||
*/
|
||||
public function testNewHydrationBasicsMixedQueryNormalJoin($hydrationMode)
|
||||
{
|
||||
// Faked query components
|
||||
$queryComponents = array(
|
||||
'u' => array(
|
||||
'table' => $this->sharedFixture['connection']->getClassMetadata('CmsUser'),
|
||||
'mapper' => $this->sharedFixture['connection']->getMapper('CmsUser'),
|
||||
'parent' => null,
|
||||
'relation' => null,
|
||||
'map' => null
|
||||
),
|
||||
'p' => array(
|
||||
'table' => $this->sharedFixture['connection']->getClassMetadata('CmsPhonenumber'),
|
||||
'mapper' => $this->sharedFixture['connection']->getMapper('CmsPhonenumber'),
|
||||
'parent' => 'u',
|
||||
'relation' => $this->sharedFixture['connection']->getClassMetadata('CmsUser')->getRelation('phonenumbers'),
|
||||
'map' => null,
|
||||
'agg' => array('0' => 'numPhones')
|
||||
)
|
||||
);
|
||||
|
||||
// Faked table alias map
|
||||
$tableAliasMap = array(
|
||||
'u' => 'u',
|
||||
'p' => 'p'
|
||||
);
|
||||
|
||||
// Faked result set
|
||||
$resultSet = array(
|
||||
//row1
|
||||
array(
|
||||
'u__id' => '1',
|
||||
'u__status' => 'developer',
|
||||
'p__0' => '2',
|
||||
),
|
||||
array(
|
||||
'u__id' => '2',
|
||||
'u__status' => 'developer',
|
||||
'p__0' => '1',
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$stmt = new Doctrine_HydratorMockStatement($resultSet);
|
||||
$hydrator = new Doctrine_HydratorNew();
|
||||
$hydrator->setQueryComponents($queryComponents);
|
||||
|
||||
$hydrator->setResultMixed(true);
|
||||
|
||||
$result = $hydrator->hydrateResultSet($stmt, $tableAliasMap, $hydrationMode);
|
||||
//var_dump($result);
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertTrue(is_array($result[0]));
|
||||
$this->assertTrue(is_array($result[1]));
|
||||
|
||||
// first user => 2 phonenumbers
|
||||
$this->assertEquals(2, $result[0]['numPhones']);
|
||||
// second user => 1 phonenumber
|
||||
$this->assertEquals(1, $result[1]['numPhones']);
|
||||
|
||||
if ($hydrationMode == Doctrine::HYDRATE_RECORD) {
|
||||
$this->assertTrue($result[0][0] instanceof Doctrine_Record);
|
||||
$this->assertTrue($result[1][0] instanceof Doctrine_Record);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* select u.id, u.status, upper(u.name) nameUpper from User u index by u.id
|
||||
* join u.phonenumbers p indexby p.phonenumber
|
||||
* =
|
||||
* select u.id, u.status, upper(u.name) as p__0 from USERS u
|
||||
* INNER JOIN PHONENUMBERS p ON u.id = p.user_id
|
||||
*
|
||||
* @dataProvider hydrationModeProvider
|
||||
*/
|
||||
public function testNewHydrationMixedQueryFetchJoinCustomIndex($hydrationMode)
|
||||
{
|
||||
// Faked query components
|
||||
$queryComponents = array(
|
||||
'u' => array(
|
||||
'table' => $this->sharedFixture['connection']->getClassMetadata('CmsUser'),
|
||||
'mapper' => $this->sharedFixture['connection']->getMapper('CmsUser'),
|
||||
'parent' => null,
|
||||
'relation' => null,
|
||||
'agg' => array('0' => 'nameUpper'),
|
||||
'map' => 'id'
|
||||
),
|
||||
'p' => array(
|
||||
'table' => $this->sharedFixture['connection']->getClassMetadata('CmsPhonenumber'),
|
||||
'mapper' => $this->sharedFixture['connection']->getMapper('CmsPhonenumber'),
|
||||
'parent' => 'u',
|
||||
'relation' => $this->sharedFixture['connection']->getClassMetadata('CmsUser')->getRelation('phonenumbers'),
|
||||
'map' => 'phonenumber'
|
||||
)
|
||||
);
|
||||
|
||||
// Faked table alias map
|
||||
$tableAliasMap = array(
|
||||
'u' => 'u',
|
||||
'p' => 'p'
|
||||
);
|
||||
|
||||
// Faked result set
|
||||
$resultSet = array(
|
||||
//row1
|
||||
array(
|
||||
'u__id' => '1',
|
||||
'u__status' => 'developer',
|
||||
'u__0' => 'ROMANB',
|
||||
'p__phonenumber' => '42',
|
||||
),
|
||||
array(
|
||||
'u__id' => '1',
|
||||
'u__status' => 'developer',
|
||||
'u__0' => 'ROMANB',
|
||||
'p__phonenumber' => '43',
|
||||
),
|
||||
array(
|
||||
'u__id' => '2',
|
||||
'u__status' => 'developer',
|
||||
'u__0' => 'JWAGE',
|
||||
'p__phonenumber' => '91'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$stmt = new Doctrine_HydratorMockStatement($resultSet);
|
||||
$hydrator = new Doctrine_HydratorNew();
|
||||
$hydrator->setQueryComponents($queryComponents);
|
||||
|
||||
// give the hydrator an artificial hint
|
||||
$hydrator->setResultMixed(true);
|
||||
|
||||
$result = $hydrator->hydrateResultSet($stmt, $tableAliasMap, $hydrationMode);
|
||||
if ($hydrationMode == Doctrine::HYDRATE_ARRAY) {
|
||||
//var_dump($result);
|
||||
}
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertTrue(is_array($result[0]));
|
||||
$this->assertTrue(is_array($result[1]));
|
||||
|
||||
|
||||
// first user => 2 phonenumbers. notice the custom indexing by user id
|
||||
$this->assertEquals(2, count($result[0]['1']['phonenumbers']));
|
||||
// second user => 1 phonenumber. notice the custom indexing by user id
|
||||
$this->assertEquals(1, count($result[1]['2']['phonenumbers']));
|
||||
|
||||
// test the custom indexing of the phonenumbers
|
||||
$this->assertTrue(isset($result[0]['1']['phonenumbers']['42']));
|
||||
$this->assertTrue(isset($result[0]['1']['phonenumbers']['43']));
|
||||
$this->assertTrue(isset($result[1]['2']['phonenumbers']['91']));
|
||||
|
||||
// test the scalar values
|
||||
$this->assertEquals('ROMANB', $result[0]['nameUpper']);
|
||||
$this->assertEquals('JWAGE', $result[1]['nameUpper']);
|
||||
|
||||
if ($hydrationMode == Doctrine::HYDRATE_RECORD) {
|
||||
$this->assertTrue($result[0]['1'] instanceof Doctrine_Record);
|
||||
$this->assertTrue($result[1]['2'] instanceof Doctrine_Record);
|
||||
$this->assertTrue($result[0]['1']['phonenumbers'] instanceof Doctrine_Collection);
|
||||
$this->assertEquals(2, count($result[0]['1']['phonenumbers']));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -18,6 +18,8 @@ class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase
|
||||
|
||||
public function testRegisterNew()
|
||||
{
|
||||
$this->_user->username = 'romanb';
|
||||
$this->_user->id = 1;
|
||||
$this->_unitOfWork->registerNew($this->_user);
|
||||
$this->assertFalse($this->_unitOfWork->contains($this->_user));
|
||||
$this->assertTrue($this->_unitOfWork->isRegisteredNew($this->_user));
|
||||
@ -35,7 +37,15 @@ class Orm_UnitOfWorkTestCase extends Doctrine_OrmTestCase
|
||||
$this->assertTrue($this->_unitOfWork->isRegisteredDirty($this->_user));
|
||||
$this->assertFalse($this->_unitOfWork->isRegisteredNew($this->_user));
|
||||
$this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user));
|
||||
|
||||
}
|
||||
|
||||
public function testRegisterRemovedOnTransientEntityIsIgnored()
|
||||
{
|
||||
$this->_user->username = 'romanb';
|
||||
$this->_user->id = 1;
|
||||
$this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user));
|
||||
$this->_unitOfWork->registerRemoved($this->_user);
|
||||
$this->assertFalse($this->_unitOfWork->isRegisteredRemoved($this->_user));
|
||||
}
|
||||
|
||||
/*public function testSavedEntityHasIdentityAndIsManaged()
|
||||
|
9
tests/models/cms/CmsPhonenumber.php
Normal file
9
tests/models/cms/CmsPhonenumber.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
class CmsPhonenumber extends Doctrine_Record
|
||||
{
|
||||
public static function initMetadata($class)
|
||||
{
|
||||
$class->mapColumn('user_id', 'integer', 4);
|
||||
$class->mapColumn('phonenumber', 'string', 50, array('primary' => true));
|
||||
}
|
||||
}
|
@ -6,5 +6,8 @@ class CmsUser extends Doctrine_Record
|
||||
$class->mapColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
|
||||
$class->mapColumn('username', 'string', 255);
|
||||
$class->mapColumn('name', 'string', 255);
|
||||
|
||||
$class->hasMany('CmsPhonenumber as phonenumbers', array(
|
||||
'local' => 'id', 'foreign' => 'user_id'));
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$user->save();
|
||||
|
||||
$user = $this->connection->getMapper('User')->find($user->identifier());
|
||||
$user = $this->connection->getRepository('User')->find($user->identifier());
|
||||
$this->assertEqual($user->name, 'Jack');
|
||||
|
||||
$user['name'] = 'Jack';
|
||||
@ -97,7 +97,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$user->save();
|
||||
|
||||
$user = $this->connection->getMapper('User')->find($user->identifier());
|
||||
$user = $this->connection->getRepository('User')->find($user->identifier());
|
||||
$this->assertEqual($user->name, 'Jack');
|
||||
|
||||
$user->name = 'Jack';
|
||||
@ -115,7 +115,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$user->save();
|
||||
|
||||
$user = $this->connection->getMapper('User')->find($user->identifier());
|
||||
$user = $this->connection->getRepository('User')->find($user->identifier());
|
||||
|
||||
$this->assertEqual($user->get('name'), 'Jack');
|
||||
|
||||
|
@ -168,7 +168,7 @@ class Doctrine_ClassTableInheritance_TestCase extends Doctrine_UnitTestCase
|
||||
$profiler = new Doctrine_Connection_Profiler();
|
||||
$this->conn->addListener($profiler);
|
||||
|
||||
$record = $this->conn->getMapper('CTITest')->find(1);
|
||||
$record = $this->conn->getRepository('CTITest')->find(1);
|
||||
|
||||
$record->age = 11;
|
||||
$record->name = 'Jack';
|
||||
@ -193,7 +193,7 @@ class Doctrine_ClassTableInheritance_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
$this->conn->clear();
|
||||
|
||||
$record = $this->conn->getMapper('CTITest')->find(1);
|
||||
$record = $this->conn->getRepository('CTITest')->find(1);
|
||||
|
||||
$this->assertEqual($record->id, 1);
|
||||
$this->assertEqual($record->name, 'Jack');
|
||||
@ -209,7 +209,7 @@ class Doctrine_ClassTableInheritance_TestCase extends Doctrine_UnitTestCase
|
||||
$profiler = new Doctrine_Connection_Profiler();
|
||||
$this->conn->addListener($profiler);
|
||||
|
||||
$record = $this->conn->getMapper('CTITest')->find(1);
|
||||
$record = $this->conn->getRepository('CTITest')->find(1);
|
||||
|
||||
$record->delete();
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Doctrine_CustomPrimaryKey_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($c->identifier(), array('uid' => 1));
|
||||
$this->connection->clear();
|
||||
|
||||
$c = $this->connection->getMapper('CustomPK')->find(1);
|
||||
$c = $this->connection->getRepository('CustomPK')->find(1);
|
||||
|
||||
$this->assertEqual($c->identifier(), array('uid' => 1));
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class Doctrine_DataType_Boolean_TestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
$this->connection->clear();
|
||||
|
||||
$test = $test->getMapper()->find($test->id);
|
||||
$test = $test->getRepository()->find($test->id);
|
||||
$this->assertIdentical($test->is_working, true);
|
||||
}
|
||||
public function testNormalQuerying() {
|
||||
|
@ -172,7 +172,7 @@ class Doctrine_DataType_Enum_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testFailingRefresh()
|
||||
{
|
||||
$enum = $this->connection->getMapper('EnumTest')->find(1);
|
||||
$enum = $this->connection->getRepository('EnumTest')->find(1);
|
||||
|
||||
$this->conn->exec('DELETE FROM enum_test WHERE id = 1');
|
||||
|
||||
|
@ -197,7 +197,7 @@ class Doctrine_UnitTestCase extends UnitTestCase
|
||||
//echo "exporting : " . var_dump($this->tables);
|
||||
//echo "<br /><br />";
|
||||
$this->conn->export->exportClasses($this->tables);
|
||||
$this->objTable = $this->connection->getMapper('User');
|
||||
$this->objTable = $this->connection->getRepository('User');
|
||||
}
|
||||
|
||||
public function prepareData()
|
||||
|
@ -152,7 +152,7 @@ class Doctrine_Inheritance_Joined_TestCase extends Doctrine_UnitTestCase
|
||||
public function testDqlQueryJoinsTransparentlyAcrossParents()
|
||||
{
|
||||
$this->_createManager();
|
||||
$this->conn->getMapper('CTI_Manager')->clear();
|
||||
$this->conn->clear('CTI_Manager');
|
||||
|
||||
$query = $this->conn->createQuery();
|
||||
$query->parseQuery("SELECT m.* FROM CTI_Manager m");
|
||||
@ -167,8 +167,8 @@ class Doctrine_Inheritance_Joined_TestCase extends Doctrine_UnitTestCase
|
||||
public function testQueryingBaseClassOuterJoinsSubClassesAndReturnsSubclassInstances()
|
||||
{
|
||||
$this->_createManager();
|
||||
$this->conn->getMapper('CTI_Manager')->clear();
|
||||
$this->conn->getMapper('CTI_User')->clear();
|
||||
$this->conn->clear('CTI_Manager');
|
||||
$this->conn->clear('CTI_User');
|
||||
|
||||
$query = $this->conn->createQuery();
|
||||
$query->parseQuery("SELECT u.* FROM CTI_User u");
|
||||
|
@ -41,9 +41,9 @@ class Doctrine_Query_JoinCondition2_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function prepareData()
|
||||
{
|
||||
$this->conn->getMapper('User')->clear();
|
||||
$this->conn->getMapper('Group')->clear();
|
||||
$this->conn->getMapper('Groupuser')->clear();
|
||||
$this->conn->clear('User');
|
||||
$this->conn->clear('Group');
|
||||
$this->conn->clear('Groupuser');
|
||||
|
||||
$zYne = new User();
|
||||
$zYne->name = 'zYne';
|
||||
|
@ -43,7 +43,7 @@ class Doctrine_Query_MultiJoin_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$query = new Doctrine_Query($this->connection);
|
||||
|
||||
$user = $this->connection->getMapper('User')->find(4);
|
||||
$user = $this->connection->getRepository('User')->find(4);
|
||||
|
||||
|
||||
$album = $this->connection->create('Album');
|
||||
@ -73,7 +73,7 @@ class Doctrine_Query_MultiJoin_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual(count($user->Album[1]->Song), 4);
|
||||
|
||||
|
||||
$user = $this->connection->getMapper('User')->find(5);
|
||||
$user = $this->connection->getRepository('User')->find(5);
|
||||
|
||||
$user->Album[0]->name = 'Clayman';
|
||||
$user->Album[1]->name = 'Colony';
|
||||
@ -122,7 +122,7 @@ class Doctrine_Query_MultiJoin_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testInitializeMoreData()
|
||||
{
|
||||
$user = $this->connection->getMapper('User')->find(4);
|
||||
$user = $this->connection->getRepository('User')->find(4);
|
||||
$user->Book[0]->name = 'The Prince';
|
||||
$user->Book[0]->Author[0]->name = 'Niccolo Machiavelli';
|
||||
$user->Book[0]->Author[1]->name = 'Someone';
|
||||
@ -133,7 +133,7 @@ class Doctrine_Query_MultiJoin_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$user->save();
|
||||
|
||||
$user = $this->connection->getMapper('User')->find(5);
|
||||
$user = $this->connection->getRepository('User')->find(5);
|
||||
$user->Book[0]->name = 'Zadig';
|
||||
$user->Book[0]->Author[0]->name = 'Voltaire';
|
||||
$user->Book[0]->Author[1]->name = 'Someone';
|
||||
|
@ -60,7 +60,7 @@ class Doctrine_Query_ReferenceModel_TestCase extends Doctrine_UnitTestCase {
|
||||
$this->connection->unitOfWork->saveAll();
|
||||
$this->connection->clear();
|
||||
|
||||
$category = $category->getMapper()->find($category->id);
|
||||
$category = $category->getRepository()->find($category->id);
|
||||
|
||||
$this->assertEqual($category->name, 'Root');
|
||||
$this->assertEqual($category->Subcategory[0]->name, 'Sub 1');
|
||||
|
@ -62,6 +62,6 @@ class Doctrine_Query_Registry_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$user = new User();
|
||||
|
||||
$user->getMapper()->executeNamedQuery('User.all');
|
||||
$user->getEntityManager()->executeNamedQuery('User.all');
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($account->amount, 2000);
|
||||
|
||||
|
||||
$user = $user->getMapper()->find($user->id);
|
||||
$user = $user->getRepository()->find($user->id);
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
|
||||
|
||||
|
||||
@ -148,7 +148,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($gzip->gzip, "compressed");
|
||||
|
||||
$this->connection->clear();
|
||||
$gzip = $gzip->getMapper()->find($gzip->id);
|
||||
$gzip = $gzip->getRepository()->find($gzip->id);
|
||||
$this->assertEqual($gzip->gzip, "compressed");
|
||||
|
||||
$gzip->gzip = "compressed 2";
|
||||
@ -209,7 +209,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertTrue(array_key_exists('id', $a));
|
||||
$this->assertTrue(is_numeric($a['id']));
|
||||
$this->connection->clear();
|
||||
$user = $user->getMapper()->find($user->id);
|
||||
$user = $user->getRepository()->find($user->id);
|
||||
|
||||
$a = $user->toArray();
|
||||
|
||||
@ -231,7 +231,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testUpdatingWithNullValue()
|
||||
{
|
||||
$user = $this->connection->getMapper('User')->find(5);
|
||||
$user = $this->connection->getRepository('User')->find(5);
|
||||
$user->name = null;
|
||||
$this->assertEqual($user->name, null);
|
||||
|
||||
@ -241,7 +241,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$this->connection->clear();
|
||||
|
||||
$user = $this->connection->getMapper('User')->find(5);
|
||||
$user = $this->connection->getRepository('User')->find(5);
|
||||
|
||||
$this->assertEqual($user->name, null);
|
||||
|
||||
@ -249,7 +249,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testSerialize()
|
||||
{
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
$str = serialize($user);
|
||||
$user2 = unserialize($str);
|
||||
|
||||
@ -279,7 +279,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($record->entity2, 4);
|
||||
$this->assertEqual($record->entity1, 3);
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_TDIRTY);
|
||||
$this->assertEqual($record->identifier(), array("entity1" => null, "entity2" => null));
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 3, "entity2" => 4));
|
||||
|
||||
$record->save();
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
|
||||
@ -287,7 +287,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($record->entity1, 3);
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 3, "entity2" => 4));
|
||||
|
||||
$record = $record->getMapper()->find($record->identifier());
|
||||
$record = $record->getRepository()->find($record->identifier());
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($record->entity2, 4);
|
||||
$this->assertEqual($record->entity1, 3);
|
||||
@ -300,20 +300,21 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($record->entity2, 5);
|
||||
$this->assertEqual($record->entity1, 2);
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 3, "entity2" => 4));
|
||||
|
||||
|
||||
$record->save();
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($record->entity2, 5);
|
||||
$this->assertEqual($record->entity1, 2);
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 2, "entity2" => 5));
|
||||
$record = $record->getMapper()->find($record->identifier());
|
||||
|
||||
$record = $record->getRepository()->find($record->identifier());
|
||||
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($record->entity2, 5);
|
||||
$this->assertEqual($record->entity1, 2);
|
||||
$this->assertEqual($record->identifier(), array("entity1" => 2, "entity2" => 5));
|
||||
|
||||
$record->refresh();
|
||||
|
||||
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($record->entity2, 5);
|
||||
$this->assertEqual($record->entity1, 2);
|
||||
@ -368,7 +369,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$this->connection->unitOfWork->saveAll();
|
||||
|
||||
$task = $task->getMapper()->find($task->identifier());
|
||||
$task = $task->getRepository()->find($task->identifier());
|
||||
|
||||
$this->assertEqual($task->name, "Task 1");
|
||||
$this->assertEqual($task->ResourceAlias[0]->name, "Resource 1");
|
||||
@ -386,7 +387,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($user->updated, null);
|
||||
$user->save();
|
||||
$id = $user->identifier();
|
||||
$user = $user->getMapper()->find($id);
|
||||
$user = $user->getRepository()->find($id);
|
||||
$this->assertEqual($user->name, "Jack Daniels");
|
||||
$this->assertEqual($user->created, null);
|
||||
$this->assertEqual($user->updated, null);
|
||||
@ -439,12 +440,12 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$elements = $this->connection->query("FROM Element");
|
||||
$this->assertEqual($elements->count(), 5);
|
||||
|
||||
$e = $e->getMapper()->find(1);
|
||||
$e = $e->getRepository()->find(1);
|
||||
$this->assertEqual($e->name,"parent");
|
||||
|
||||
$this->assertEqual($e->Child[0]->name,"child 1");
|
||||
|
||||
$c = $e->getMapper()->find(2);
|
||||
$c = $e->getRepository()->find(2);
|
||||
$this->assertEqual($c->name, "child 1");
|
||||
|
||||
$this->assertEqual($e->Child[0]->parent_id, 1);
|
||||
@ -553,7 +554,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
$user->set("name","Jack Daniels",true);
|
||||
|
||||
|
||||
@ -566,7 +567,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testCopy()
|
||||
{
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
$new = $user->copy();
|
||||
|
||||
$this->assertTrue($new instanceof Doctrine_Record);
|
||||
@ -583,7 +584,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testCopyAndModify()
|
||||
{
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
$new = $user->copy();
|
||||
|
||||
$this->assertTrue($new instanceof Doctrine_Record);
|
||||
@ -604,7 +605,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testReferences()
|
||||
{
|
||||
$user = $this->connection->getMapper('User')->find(5);
|
||||
$user = $this->connection->getRepository('User')->find(5);
|
||||
|
||||
$this->assertTrue($user->Phonenumber instanceof Doctrine_Collection);
|
||||
$this->assertEqual($user->Phonenumber->count(), 3);
|
||||
@ -615,7 +616,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($user->Phonenumber->count(), 0);
|
||||
$user->save();
|
||||
|
||||
$user->getMapper()->clear();
|
||||
$user->getEntityManager()->clear('User');
|
||||
|
||||
$user = $this->objTable->find(5);
|
||||
|
||||
@ -736,15 +737,11 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testSaveAssociations()
|
||||
{
|
||||
$userMapper = $this->connection->getMapper('User');
|
||||
$userMapper = $this->connection->getRepository('User');
|
||||
$user = $userMapper->find(5);
|
||||
$this->assertTrue($userMapper === $user->getMapper());
|
||||
$this->assertTrue($userMapper->getTable() === $user->getMapper()->getTable());
|
||||
$this->assertTrue($userMapper->getTable() === $this->conn->getClassMetadata('User'));
|
||||
$this->assertTrue($this->conn === $userMapper->getConnection());
|
||||
|
||||
|
||||
$userTable = $userMapper->getTable();
|
||||
$userTable = $this->connection->getClassMetadata('User');
|
||||
/*echo get_class($rel1) . "<br />";
|
||||
echo get_class($rel2) . "<br />";
|
||||
echo get_class($userTable->getRelation('Group'));
|
||||
@ -753,7 +750,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
echo "local:" . $rel2->getLocal() . "---foreign:" . $rel2->getForeign() . "<br />";
|
||||
echo "........<br />";*/
|
||||
|
||||
$gf = $this->connection->getMapper("Group");
|
||||
$gf = $this->connection->getRepository("Group");
|
||||
//echo "start";
|
||||
$this->assertTrue($user->Group instanceof Doctrine_Collection);
|
||||
//echo "end";
|
||||
@ -865,14 +862,14 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
|
||||
$this->assertTrue(is_integer($user->count()));
|
||||
}
|
||||
|
||||
public function testGetReference()
|
||||
{
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
|
||||
$this->assertTrue($user->Email instanceof Doctrine_Record);
|
||||
$this->assertTrue($user->Phonenumber instanceof Doctrine_Collection);
|
||||
@ -882,13 +879,13 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
public function testGetIterator()
|
||||
{
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
$this->assertTrue($user->getIterator() instanceof ArrayIterator);
|
||||
}
|
||||
|
||||
public function testRefreshRelated()
|
||||
{
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
$user->Address[0]->address = "Address #1";
|
||||
$user->Address[1]->address = "Address #2";
|
||||
$user->save();
|
||||
@ -904,7 +901,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
public function testRefreshDeep()
|
||||
{
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
$user->Address[0]->address = "Address #1";
|
||||
$user->Address[1]->address = "Address #2";
|
||||
$user->save();
|
||||
|
@ -117,7 +117,7 @@ class Doctrine_Relation_Nest_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$this->connection->clear();
|
||||
|
||||
$e = $e->getMapper()->find($e->id);
|
||||
$e = $e->getRepository()->find($e->id);
|
||||
|
||||
$count = count($this->conn);
|
||||
|
||||
|
@ -83,7 +83,7 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$this->connection->clear();
|
||||
|
||||
$t = $this->connection->getMapper('FieldNameTest')->find(1);
|
||||
$t = $this->connection->getRepository('FieldNameTest')->find(1);
|
||||
|
||||
$this->assertEqual($t->someColumn, 'abc');
|
||||
$this->assertEqual($t->someEnum, 'php');
|
||||
|
@ -37,7 +37,7 @@ class Doctrine_Ticket_626D_TestCase extends Doctrine_UnitTestCase
|
||||
$student1 = $this->newStudent('T626D_Student1', '07090002', 'First Student');
|
||||
|
||||
try {
|
||||
$student = $this->conn->getMapper('T626D_Student1')->find('07090002');
|
||||
$student = $this->conn->getRepository('T626D_Student1')->find('07090002');
|
||||
$this->pass();
|
||||
} catch (Exception $e) {
|
||||
$this->fail($e->__toString());
|
||||
|
@ -140,7 +140,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
|
||||
public function testValidate()
|
||||
{
|
||||
$this->manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
|
||||
$user = $this->connection->getMapper('User')->find(4);
|
||||
$user = $this->connection->getRepository('User')->find(4);
|
||||
|
||||
$set = array('password' => 'this is an example of too long password',
|
||||
'loginname' => 'this is an example of too long loginname',
|
||||
@ -200,7 +200,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
|
||||
public function testSave()
|
||||
{
|
||||
$this->manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
try {
|
||||
$user->name = "this is an example of too long name not very good example but an example nevertheless";
|
||||
$user->save();
|
||||
@ -260,7 +260,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
|
||||
}
|
||||
|
||||
// Tests validateOnUpdate()
|
||||
$user = $this->connection->getMapper("User")->find(4);
|
||||
$user = $this->connection->getRepository("User")->find(4);
|
||||
try {
|
||||
$user->name = "The Saint"; // Set correct name
|
||||
$user->password = "Top Secret"; // Set correct password
|
||||
@ -337,7 +337,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
|
||||
$r->identifier = '1234';
|
||||
$r->save();
|
||||
|
||||
$r = $this->connection->getMapper('ValidatorTest_Person')->findAll()->getFirst();
|
||||
$r = $this->connection->getRepository('ValidatorTest_Person')->findAll()->getFirst();
|
||||
$r->identifier = 1234;
|
||||
try {
|
||||
$r->save();
|
||||
|
Loading…
x
Reference in New Issue
Block a user