1
0
mirror of synced 2025-01-18 06:21:40 +03:00

Merged current state of my experimental branch back to trunk.

This commit is contained in:
romanb 2008-01-05 19:55:56 +00:00
parent 344ab02d95
commit d9112ad1d7
71 changed files with 3517 additions and 1878 deletions

View File

@ -194,6 +194,33 @@ final class Doctrine
const ATTR_AUTOLOAD_TABLE_CLASSES = 160;
const ATTR_MODEL_LOADING = 161;
/**
* INHERITANCE TYPE CONSTANTS.
*/
/**
* Constant for Single Table Inheritance.
*
* @see http://martinfowler.com/eaaCatalog/singleTableInheritance.html
*/
const INHERITANCETYPE_SINGLE_TABLE = 1;
/**
* Constant for Class Table Inheritance.
*
* @see http://martinfowler.com/eaaCatalog/classTableInheritance.html
*/
const INHERITANCETYPE_JOINED = 2;
/**
* Constant for Concrete Table Inheritance.
*
* @see http://martinfowler.com/eaaCatalog/concreteTableInheritance.html
*/
const INHERITANCETYPE_TABLE_PER_CLASS = 3;
/**
* LIMIT CONSTANTS
*/

View File

@ -37,11 +37,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @var array $data an array containing the records of this collection
*/
protected $data = array();
/**
* @var Doctrine_Table $table each collection has only records of specified table
*/
protected $_table;
protected $_mapper;
/**
* @var array $_snapshot a snapshot of the fetched data
@ -79,20 +76,26 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*
* @param Doctrine_Table|string $table
*/
public function __construct($table, $keyColumn = null)
public function __construct($mapper, $keyColumn = null)
{
if ( ! ($table instanceof Doctrine_Table)) {
$table = Doctrine_Manager::getInstance()
->getTable($table);
if ($mapper instanceof Doctrine_Table) {
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString();
}
}
$this->_table = $table;
if (is_string($mapper)) {
$mapper = Doctrine_Manager::getInstance()->getMapper($mapper);
}
$this->_mapper = $mapper;
if ($keyColumn === null) {
$keyColumn = $table->getBoundQueryPart('indexBy');
$keyColumn = $mapper->getBoundQueryPart('indexBy');
}
if ($keyColumn === null) {
$keyColumn = $table->getAttribute(Doctrine::ATTR_COLL_KEY);
$keyColumn = $mapper->getAttribute(Doctrine::ATTR_COLL_KEY);
}
if ($keyColumn !== null) {
@ -119,7 +122,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
public function getTable()
{
return $this->_table;
return $this->_mapper->getTable();
}
/**
@ -171,11 +174,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->$name = $values;
}
$this->_table = $connection->getTable($this->_table);
$this->_mapper = $connection->getMapper($this->_mapper);
$keyColumn = isset($array['keyColumn']) ? $array['keyColumn'] : null;
if ($keyColumn === null) {
$keyColumn = $this->_table->getBoundQueryPart('indexBy');
$keyColumn = $this->_mapper->getBoundQueryPart('indexBy');
}
if ($keyColumn !== null) {
@ -266,6 +269,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
public function setReference(Doctrine_Record $record, Doctrine_Relation $relation)
{
/*try {
throw new Exception();
} catch (Exception $e) {
echo "relation set on collection: " . get_class($relation) . "<br />";
echo $e->getTraceAsString() . "<br />";
}*/
$this->reference = $record;
$this->relation = $relation;
@ -273,9 +282,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$relation instanceof Doctrine_Relation_LocalKey) {
$this->referenceField = $relation->getForeignFieldName();
$value = $record->get($relation->getLocalFieldName());
foreach ($this->data as $record) {
if ($value !== null) {
$record->set($this->referenceField, $value, false);
@ -283,7 +290,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$record->set($this->referenceField, $this->reference, false);
}
}
} elseif ($relation instanceof Doctrine_Relation_Association) {
} else if ($relation instanceof Doctrine_Relation_Association) {
}
}
@ -308,7 +315,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function remove($key)
{
$removed = $this->data[$key];
unset($this->data[$key]);
return $removed;
}
@ -324,6 +330,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
{
return isset($this->data[$key]);
}
public function search(Doctrine_Record $record)
{
return array_search($record, $this->data, true);
@ -349,7 +356,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function get($key)
{
if ( ! isset($this->data[$key])) {
$record = $this->_table->create();
$record = $this->_mapper->create();
if (isset($this->referenceField)) {
$value = $this->reference->get($this->relation->getLocalFieldName());
@ -383,7 +390,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function getPrimaryKeys()
{
$list = array();
$name = $this->_table->getIdentifier();
$name = $this->_mapper->getTable()->getIdentifier();
foreach ($this->data as $record) {
if (is_array($record) && isset($record[$name])) {
@ -488,7 +495,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function loadRelated($name = null)
{
$list = array();
$query = new Doctrine_Query($this->_table->getConnection());
$query = new Doctrine_Query($this->_mapper->getConnection());
if ( ! isset($name)) {
foreach ($this->data as $record) {
@ -497,13 +504,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$list[] = $value;
}
}
$query->from($this->_table->getComponentName() . '(' . implode(", ",$this->_table->getPrimaryKeys()) . ')');
$query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')');
$query->from($this->_mapper->getComponentName() . '(' . implode(", ",$this->_mapper->getTable()->getPrimaryKeys()) . ')');
$query->where($this->_mapper->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')');
return $query;
}
$rel = $this->_table->getRelation($name);
$rel = $this->_mapper->getTable()->getRelation($name);
if ($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) {
foreach ($this->data as $record) {
@ -534,7 +541,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
public function populateRelated($name, Doctrine_Collection $coll)
{
$rel = $this->_table->getRelation($name);
$rel = $this->_mapper->getTable()->getRelation($name);
$table = $rel->getTable();
$foreign = $rel->getForeign();
$local = $rel->getLocal();
@ -547,12 +554,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
}
}
} elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
} else if ($rel instanceof Doctrine_Relation_ForeignKey) {
foreach ($this->data as $key => $record) {
if ( ! $record->exists()) {
continue;
}
$sub = new Doctrine_Collection($table);
$sub = new Doctrine_Collection($rel->getForeignComponentName());
foreach ($coll as $k => $related) {
if ($related[$foreign] == $record[$local]) {
@ -563,8 +570,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->data[$key]->setRelated($name, $sub);
}
} elseif ($rel instanceof Doctrine_Relation_Association) {
$identifier = $this->_table->getIdentifier();
} else if ($rel instanceof Doctrine_Relation_Association) {
$identifier = $this->_mapper->getTable()->getIdentifier();
$asf = $rel->getAssociationFactory();
$name = $table->getComponentName();
@ -572,7 +579,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if ( ! $record->exists()) {
continue;
}
$sub = new Doctrine_Collection($table);
$sub = new Doctrine_Collection($rel->getForeignComponentName());
foreach ($coll as $k => $related) {
if ($related->get($local) == $record[$identifier]) {
$sub->add($related->get($name));
@ -634,7 +641,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* Snapshot with the objects 1, 2 and 4
* Current data with objects 2, 3 and 5
*
* The process would remove object 4
* The process would remove objects 1 and 4
*
* @return Doctrine_Collection
*/
@ -643,7 +650,6 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
foreach (array_udiff($this->_snapshot, $this->data, array($this, "compareRecords")) as $record) {
$record->delete();
}
return $this;
}
@ -789,21 +795,24 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function save(Doctrine_Connection $conn = null)
{
if ($conn == null) {
$conn = $this->_table->getConnection();
$conn = $this->_mapper->getConnection();
}
$conn->beginInternalTransaction();
$conn->transaction->addCollection($this);
$this->processDiff();
foreach ($this->getData() as $key => $record) {
$record->save($conn);
try {
$conn->beginInternalTransaction();
$conn->transaction->addCollection($this);
$this->processDiff();
foreach ($this->getData() as $key => $record) {
$record->save($conn);
}
$conn->commit();
} catch (Exception $e) {
$conn->rollback();
throw $e;
}
$conn->commit();
return $this;
}
@ -818,20 +827,24 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function delete(Doctrine_Connection $conn = null)
{
if ($conn == null) {
$conn = $this->_table->getConnection();
$conn = $this->_mapper->getConnection();
}
$conn->beginInternalTransaction();
$conn->transaction->addCollection($this);
try {
$conn->beginInternalTransaction();
$conn->transaction->addCollection($this);
foreach ($this as $key => $record) {
$record->delete($conn);
}
foreach ($this as $key => $record) {
$record->delete($conn);
$conn->commit();
} catch (Exception $e) {
$conn->rollback();
throw $e;
}
$conn->commit();
$this->data = array();
return $this;
}

View File

@ -196,6 +196,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
}
return $this->_params[$name];
}
/**
* setImpl
* binds given class to given template name
@ -391,8 +392,8 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
}
/**
* sets a parent for this configurable component
* the parent must be configurable component itself
* Sets a parent for this configurable component
* the parent must be a configurable component itself.
*
* @param Doctrine_Configurable $component
* @return void
@ -404,7 +405,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
/**
* getParent
* returns the parent of this component
* Returns the parent of this component.
*
* @return Doctrine_Configurable
*/

View File

@ -60,11 +60,18 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/
protected $dbh;
protected $_tableFactory;
/**
* @var array $tables an array containing all the initialized Doctrine_Table objects
* keys representing Doctrine_Table component names and values as Doctrine_Table objects
* keys representing component names and values as Doctrine_Table objects
*/
protected $tables = array();
protected $tables = array();
/**
* @var array An array of mapper objects currently maintained by this connection.
*/
protected $_mappers = array();
/**
* @var string $driverName the name of this connection driver
@ -195,6 +202,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
$this->setParent($manager);
$this->_tableFactory = new Doctrine_Table_Factory($this);
$this->setAttribute(Doctrine::ATTR_CASE, Doctrine::CASE_NATURAL);
$this->setAttribute(Doctrine::ATTR_ERRMODE, Doctrine::ERRMODE_EXCEPTION);
@ -568,7 +577,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return mixed boolean false if empty value array was given,
* otherwise returns the number of affected rows
*/
public function insert(Doctrine_Table $table, array $fields) {
public function insert(Doctrine_Table $table, array $fields)
{
if (empty($fields)) {
return false;
}
@ -588,7 +598,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$a[] = '?';
}
}
// build the statement
$query = 'INSERT INTO ' . $this->quoteIdentifier($tableName)
. ' (' . implode(', ', $cols) . ') '
@ -596,9 +606,53 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$query .= implode(', ', $a) . ')';
// prepare and execute the statement
return $this->exec($query, array_values($fields));
}
/**
* @todo DESCRIBE WHAT THIS METHOD DOES, PLEASE!
*/
public function processSingleInsert(Doctrine_Record $record)
{
$fields = $record->getPrepared();
if (empty($fields)) {
return false;
}
$table = $record->getTable();
$identifier = (array) $table->getIdentifier();
$seq = $record->getTable()->getOption('sequenceName');
if ( ! empty($seq)) {
$id = $this->sequence->nextId($seq);
$seqName = $table->getIdentifier();
$fields[$seqName] = $id;
$record->assignIdentifier($id);
}
$this->insert($table, $fields);
if (empty($seq) && count($identifier) == 1 && $identifier[0] == $table->getIdentifier() &&
$table->getIdentifierType() != Doctrine::IDENTIFIER_NATURAL) {
if (strtolower($this->getName()) == 'pgsql') {
$seq = $table->getTableName() . '_' . $identifier[0];
}
$id = $this->sequence->lastInsertId($seq);
if ( ! $id) {
throw new Doctrine_Connection_Exception("Couldn't get last insert identifier.");
}
$record->assignIdentifier($id);
} else {
$record->assignIdentifier(true);
}
}
/**
* Set the charset on the current connection
@ -914,7 +968,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->getAttribute(Doctrine::ATTR_LISTENER)->preQuery($event);
if ( ! $event->skipOperation) {
$stmt = $this->dbh->query($query);
//try {
$stmt = $this->dbh->query($query);
/*} catch (Exception $e) {
if (strstr($e->getMessage(), 'no such column')) {
echo $query . "<br /><br />";
}
}*/
$this->_count++;
}
$this->getAttribute(Doctrine::ATTR_LISTENER)->postQuery($event);
@ -941,7 +1002,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if ( ! empty($params)) {
$stmt = $this->prepare($query);
$stmt->execute($params);
//echo "<br /><br />" . $query . "<br /><br />";
return $stmt->rowCount();
} else {
$event = new Doctrine_Event($this, Doctrine_Event::CONN_EXEC, $query, $params);
@ -950,7 +1011,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if ( ! $event->skipOperation) {
$count = $this->dbh->exec($query);
//echo "<br /><br />" . $query . "<br /><br />";
$this->_count++;
}
$this->getAttribute(Doctrine::ATTR_LISTENER)->postExec($event);
@ -976,7 +1037,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$name = 'Doctrine_Connection_' . $this->driverName . '_Exception';
$exc = new $name($e->getMessage(), (int) $e->getCode());
$exc = new $name($e->getMessage(), (int) $e->getCode());
if ( ! is_array($e->errorInfo)) {
$e->errorInfo = array(null, null, null, null);
}
@ -1000,30 +1061,58 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{
return isset($this->tables[$name]);
}
/**
* returns a table object for given component name
* Gets the table object that represents the database table that is used to
* persist the specified domain class.
*
* @param string $name component name
* @return object Doctrine_Table
* @return Doctrine_Table
*/
public function getTable($name)
public function getTable($className)
{
if (isset($this->tables[$name])) {
return $this->tables[$name];
if (isset($this->tables[$className])) {
return $this->tables[$className];
}
$class = $name . 'Table';
if (class_exists($class, $this->getAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES)) &&
in_array('Doctrine_Table', class_parents($class))) {
$table = new $class($name, $this, true);
$this->_tableFactory->loadTables($className, $this->tables);
return $this->tables[$className];
}
/**
* Gets a mapper for the specified domain class that is used map instances of
* the class between the relational database and their object representation.
*
* @return Doctrine_Mapper_Abstract The mapper object.
*/
public function getMapper($className)
{
if (isset($this->_mappers[$className])) {
return $this->_mappers[$className];
}
$customMapperClass = $className . 'Mapper';
if (class_exists($customMapperClass, $this->getAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES)) &&
in_array('Doctrine_Mapper', class_parents($customMapperClass))) {
$table = $this->getTable($className);
$mapper = new $customMapperClass($className, $this);
} else {
$table = new Doctrine_Table($name, $this, true);
// instantiate correct mapper type
$table = $this->getTable($className);
$inheritanceType = $table->getInheritanceType();
if ($inheritanceType == Doctrine::INHERITANCETYPE_JOINED) {
$mapper = new Doctrine_Mapper_Joined($className, $table);
} else if ($inheritanceType == Doctrine::INHERITANCETYPE_SINGLE_TABLE) {
$mapper = new Doctrine_Mapper_SingleTable($className, $table);
} else if ($inheritanceType == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) {
$mapper = new Doctrine_Mapper_TablePerClass($className, $table);
} else {
throw new Doctrine_Connection_Exception("Unknown inheritance type '$inheritanceType'. Can't create mapper.");
}
}
$this->tables[$name] = $table;
return $table;
$this->_mappers[$className] = $mapper;
return $mapper;
}
/**
@ -1035,6 +1124,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{
return $this->tables;
}
public function getMappers()
{
//var_dump($this->_mappers);
return $this->_mappers;
}
/**
* returns an iterator that iterators through all
@ -1091,7 +1186,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/
public function create($name)
{
return $this->getTable($name)->create();
return $this->getMapper($name)->create();
}
/**
@ -1127,9 +1222,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/
public function clear()
{
foreach ($this->tables as $k => $table) {
$table->getRepository()->evictAll();
$table->clear();
foreach ($this->_mappers as $mapper) {
$mapper->getRepository()->evictAll();
$mapper->clear();
}
}
@ -1142,6 +1237,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function evictTables()
{
$this->tables = array();
$this->_mappers = array();
$this->exported = array();
}
@ -1174,6 +1270,16 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{
return $this->transaction->getTransactionLevel();
}
/**
* get the current internal transaction nesting level
*
* @return integer
*/
public function getInternalTransactionLevel()
{
return $this->transaction->getInternalTransactionLevel();
}
/**
* errorCode
@ -1184,7 +1290,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function errorCode()
{
$this->connect();
return $this->dbh->errorCode();
}
@ -1197,7 +1302,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public function errorInfo()
{
$this->connect();
return $this->dbh->errorInfo();
}
@ -1222,7 +1326,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if ( ! $this->getAttribute(Doctrine::ATTR_RESULT_CACHE)) {
throw new Doctrine_Exception('Result Cache driver not initialized.');
}
return $this->getAttribute(Doctrine::ATTR_RESULT_CACHE);
}
@ -1236,7 +1339,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if ( ! $this->getAttribute(Doctrine::ATTR_QUERY_CACHE)) {
throw new Doctrine_Exception('Query Cache driver not initialized.');
}
return $this->getAttribute(Doctrine::ATTR_QUERY_CACHE);
}
@ -1275,6 +1377,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
return $this->transaction->beginTransaction($savepoint);
}
/**
* Initiates a transaction.
*
* This method must only be used by Doctrine itself to initiate transactions.
* Userland-code must use {@link beginTransaction()}.
*/
public function beginInternalTransaction($savepoint = null)
{
return $this->transaction->beginInternalTransaction($savepoint);

View File

@ -32,6 +32,32 @@ Doctrine::autoload('Doctrine_Connection_Module');
*/
class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
{
protected $_autoflush = true;
protected $_inserts = array();
protected $_updates = array();
protected $_deletes = array();
public function flush()
{
return $this->saveAll();
}
public function addInsert()
{
}
public function addUpdate()
{
}
public function addDelete()
{
}
/**
* buildFlushTree
* builds a flush tree that is used in transactions
@ -47,9 +73,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
{
$tree = array();
foreach ($tables as $k => $table) {
if ( ! ($table instanceof Doctrine_Table)) {
$table = $this->conn->getTable($table, false);
if ( ! ($table instanceof Doctrine_Mapper)) {
$table = $this->conn->getMapper($table);
}
$nm = $table->getComponentName();
@ -60,7 +85,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$index = max(array_keys($tree));
}
$rels = $table->getRelations();
$rels = $table->getTable()->getRelations();
// group relations
@ -93,7 +118,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$tree[] = $name;
}
} elseif ($rel instanceof Doctrine_Relation_LocalKey) {
} else if ($rel instanceof Doctrine_Relation_LocalKey) {
if ($index2 !== false) {
if ($index2 <= $index)
continue;
@ -104,7 +129,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
array_unshift($tree,$name);
$index++;
}
} elseif ($rel instanceof Doctrine_Relation_Association) {
} else if ($rel instanceof Doctrine_Relation_Association) {
$t = $rel->getAssociationFactory();
$n = $t->getComponentName();
@ -138,7 +163,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
* @param Doctrine_Record $record
* @return void
*/
public function saveGraph(Doctrine_Record $record)
/*public function saveGraph(Doctrine_Record $record)
{
$conn = $this->getConnection();
@ -210,15 +235,15 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$conn->commit();
return true;
}
}*/
/**
* saves the given record
*
* @param Doctrine_Record $record
* @return void
*/
public function save(Doctrine_Record $record)
/*public function save(Doctrine_Record $record)
{
$event = new Doctrine_Event($record, Doctrine_Event::RECORD_SAVE);
@ -245,7 +270,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record->getTable()->getRecordListener()->postSave($event);
$record->postSave($event);
}
}*/
/**
* deletes given record and all the related composites
@ -254,9 +279,13 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
* this event can be listened by the onPreDelete and onDelete listeners
*
* @return boolean true on success, false on failure
* @todo Move to Doctrine_Table (which will become Doctrine_Mapper).
*/
public function delete(Doctrine_Record $record)
{
if ( ! $this->_autoflush) {
return true;
}
if ( ! $record->exists()) {
return false;
}
@ -278,16 +307,15 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
if ( ! $event->skipOperation) {
$record->state(Doctrine_Record::STATE_TDIRTY);
if ($table->getOption('joinedParents')) {
if ($table->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED) {
foreach ($table->getOption('joinedParents') as $parent) {
$parentTable = $table->getConnection()->getTable($parent);
$this->conn->delete($parentTable, $record->identifier());
}
}
$this->conn->delete($table, $record->identifier());
$record->state(Doctrine_Record::STATE_TCLEAN);
} else {
// return to original state
@ -298,7 +326,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record->postDelete($event);
$table->removeRecord($record);
$record->getMapper()->removeRecord($record);
$this->conn->commit();
@ -308,7 +336,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
/**
* @todo Description. See also the todo for deleteMultiple().
*/
public function deleteRecord(Doctrine_Record $record)
/*public function deleteRecord(Doctrine_Record $record)
{
$ids = $record->identifier();
$tmp = array();
@ -325,7 +353,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
return $this->conn->exec($query, $params);
}
}*/
/**
* deleteMultiple
@ -395,7 +423,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
* @throws PDOException if something went wrong at database level
* @param Doctrine_Record $record
*/
public function saveRelated(Doctrine_Record $record)
/*public function saveRelated(Doctrine_Record $record)
{
$saveLater = array();
foreach ($record->getReferences() as $k => $v) {
@ -413,20 +441,12 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
// Protection against infinite function recursion before attempting to save
if ($obj instanceof Doctrine_Record && $obj->isModified()) {
$obj->save($this->conn);
/** Can this be removed?
$id = array_values($obj->identifier());
foreach ((array) $rel->getLocal() as $k => $field) {
$record->set($field, $id[$k]);
}
*/
}
}
}
return $saveLater;
}
}*/
/**
* saveAssociations
@ -443,7 +463,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
* @param Doctrine_Record $record
* @return void
*/
public function saveAssociations(Doctrine_Record $record)
/*public function saveAssociations(Doctrine_Record $record)
{
foreach ($record->getReferences() as $k => $v) {
$rel = $record->getTable()->getRelation($k);
@ -469,7 +489,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
}
}
}
}*/
/**
* deletes all related composites
@ -498,7 +518,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
* @throws PDOException if something went wrong at database level
* @return void
*/
public function saveAll()
/*public function saveAll()
{
// get the flush tree
$tree = $this->buildFlushTree($this->conn->getTables());
@ -508,7 +528,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$table = $this->conn->getTable($name);
foreach ($table->getRepository() as $record) {
$this->save($record);
$table->save($record);
}
}
@ -517,7 +537,41 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$table = $this->conn->getTable($name);
foreach ($table->getRepository() as $record) {
$this->saveAssociations($record);
$table->saveAssociations($record);
}
}
}*/
/**
* saveAll
* persists all the pending records from all tables
*
* @throws PDOException if something went wrong at database level
* @return void
*/
public function saveAll()
{
//echo "<br /><br />flushin all.<br /><br />";
// get the flush tree
$tree = $this->buildFlushTree($this->conn->getMappers());
//foreach ($tree as $name) echo $name . "<br />";
// save all records
foreach ($tree as $name) {
$mapper = $this->conn->getMapper($name);
foreach ($mapper->getRepository() as $record) {
//echo $record->getOid() . "<br />";
$mapper->save($record);
}
}
// save all associations
foreach ($tree as $name) {
$mapper = $this->conn->getMapper($name);
foreach ($mapper->getRepository() as $record) {
$mapper->saveAssociations($record);
}
}
}
@ -527,9 +581,14 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
*
* @param Doctrine_Record $record record to be updated
* @return boolean whether or not the update was successful
* @todo Move to Doctrine_Table (which will become Doctrine_Mapper).
*/
public function update(Doctrine_Record $record)
/*public function update(Doctrine_Record $record)
{
if ( ! $this->_autoflush) {
return true;
}
$event = new Doctrine_Event($record, Doctrine_Event::RECORD_UPDATE);
$record->preUpdate($event);
@ -541,7 +600,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
if ( ! $event->skipOperation) {
$identifier = $record->identifier();
if ($table->getOption('joinedParents')) {
if ($table->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED
&& count($table->getOption('joinedParents')) > 0) {
$dataSet = $this->formatDataSet($record);
$component = $table->getComponentName();
@ -560,8 +620,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
foreach ($classes as $class) {
$parentTable = $this->conn->getTable($class);
$this->conn->update($this->conn->getTable($class), $dataSet[$class], $identifier);
$this->conn->update($parentTable, $dataSet[$class], $identifier);
}
} else {
$array = $record->getPrepared();
@ -576,17 +635,22 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record->postUpdate($event);
return true;
}
}*/
/**
* inserts a record into database
*
* @param Doctrine_Record $record record to be inserted
* @return boolean
* @todo Move to Doctrine_Table (which will become Doctrine_Mapper).
*/
public function insert(Doctrine_Record $record)
/*public function insert(Doctrine_Record $record)
{
// listen the onPreInsert event
if ( ! $this->_autoflush) {
return true;
}
// listen the onPreInsert event
$event = new Doctrine_Event($record, Doctrine_Event::RECORD_INSERT);
$record->preInsert($event);
@ -596,7 +660,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$table->getRecordListener()->preInsert($event);
if ( ! $event->skipOperation) {
if ($table->getOption('joinedParents')) {
if ($table->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED &&
count($table->getOption('joinedParents')) > 0) {
$dataSet = $this->formatDataSet($record);
$component = $table->getComponentName();
@ -633,12 +698,12 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record->postInsert($event);
return true;
}
}*/
/**
* @todo DESCRIBE WHAT THIS METHOD DOES, PLEASE!
*/
public function formatDataSet(Doctrine_Record $record)
/*public function formatDataSet(Doctrine_Record $record)
{
$table = $record->getTable();
@ -662,50 +727,6 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
return $dataSet;
}
}*/
/**
* @todo DESCRIBE WHAT THIS METHOD DOES, PLEASE!
*/
public function processSingleInsert(Doctrine_Record $record)
{
$fields = $record->getPrepared();
if (empty($fields)) {
return false;
}
$table = $record->getTable();
$identifier = (array) $table->getIdentifier();
$seq = $record->getTable()->sequenceName;
if ( ! empty($seq)) {
$id = $this->conn->sequence->nextId($seq);
$seqName = $table->getIdentifier();
$fields[$seqName] = $id;
$record->assignIdentifier($id);
}
$this->conn->insert($table, $fields);
if (empty($seq) && count($identifier) == 1 && $identifier[0] == $table->getIdentifier() &&
$table->getIdentifierType() != Doctrine::IDENTIFIER_NATURAL) {
if (strtolower($this->conn->getName()) == 'pgsql') {
$seq = $table->getTableName() . '_' . $identifier[0];
}
$id = $this->conn->sequence->lastInsertId($seq);
if ( ! $id) {
throw new Doctrine_Connection_Exception("Couldn't get last insert identifier.");
}
$record->assignIdentifier($id);
} else {
$record->assignIdentifier(true);
}
}
}

View File

@ -1201,16 +1201,13 @@ class Doctrine_Export extends Doctrine_Connection_Module
public function exportGeneratorsSql(Doctrine_Table $table)
{
$sql = array();
foreach ($this->getAllGenerators($table) as $name => $generator) {
$table = $generator->getTable();
// Make sure plugin has a valid table
if ($table instanceof Doctrine_Table) {
$data = $table->getExportableFormat();
$query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']);
$sql = array_merge($sql, (array) $query);
}
}

View File

@ -84,7 +84,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
// Used variables during hydration
reset($this->_queryComponents);
$rootAlias = key($this->_queryComponents);
$rootComponentName = $this->_queryComponents[$rootAlias]['table']->getComponentName();
$rootComponentName = $this->_queryComponents[$rootAlias]['mapper']->getComponentName();
// if only one component is involved we can make our lives easier
$isSimpleQuery = count($this->_queryComponents) <= 1;
// Holds the resulting hydrated data structure
@ -107,7 +107,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
// Initialize
foreach ($this->_queryComponents as $dqlAlias => $data) {
$componentName = $data['table']->getComponentName();
$componentName = $data['mapper']->getComponentName();
$listeners[$componentName] = $data['table']->getRecordListener();
$identifierMap[$dqlAlias] = array();
$prev[$dqlAlias] = array();
@ -124,7 +124,8 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
// hydrate the data of the root component from the current row
//
$table = $this->_queryComponents[$rootAlias]['table'];
$componentName = $table->getComponentName();
$mapper = $this->_queryComponents[$rootAlias]['mapper'];
$componentName = $mapper->getComponentName();
$event->set('data', $rowData[$rootAlias]);
$listeners[$componentName]->preHydrate($event);
$element = $driver->getElement($rowData[$rootAlias], $componentName);
@ -166,7 +167,8 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
$index = false;
$map = $this->_queryComponents[$dqlAlias];
$table = $map['table'];
$componentName = $table->getComponentName();
$mapper = $map['mapper'];
$componentName = $mapper->getComponentName();
$event->set('data', $data);
$listeners[$componentName]->preHydrate($event);
@ -192,9 +194,9 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
if ($field = $this->_getCustomIndexField($dqlAlias)) {
if (isset($prev[$parent][$relationAlias][$field])) {
throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found non-unique key mapping.");
throw new Doctrine_Hydrator_Exception("Hydration failed. Found non-unique key mapping.");
} else if ( ! isset($element[$field])) {
throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found a non-existent key.");
throw new Doctrine_Hydrator_Exception("Hydration failed. Found a non-existent field '$field'.");
}
$prev[$parent][$relationAlias][$element[$field]] = $element;
} else {
@ -306,7 +308,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
}
$map = $this->_queryComponents[$cache[$key]['dqlAlias']];
$table = $map['table'];
$mapper = $map['mapper'];
$dqlAlias = $cache[$key]['dqlAlias'];
$fieldName = $cache[$key]['fieldName'];
@ -321,7 +323,7 @@ class Doctrine_Hydrator extends Doctrine_Hydrator_Abstract
if ($cache[$key]['isSimpleType']) {
$rowData[$dqlAlias][$fieldName] = $value;
} else {
$rowData[$dqlAlias][$fieldName] = $table->prepareValue($fieldName, $value);
$rowData[$dqlAlias][$fieldName] = $mapper->prepareValue($fieldName, $value);
}
if ( ! isset($nonemptyComponents[$dqlAlias]) && $value !== null) {

View File

@ -106,7 +106,7 @@ class Doctrine_Hydrator_RecordDriver extends Doctrine_Locator_Injectable
public function getElement(array $data, $component)
{
if ( ! isset($this->_tables[$component])) {
$this->_tables[$component] = Doctrine_Manager::getInstance()->getTable($component);
$this->_tables[$component] = Doctrine_Manager::getInstance()->getMapper($component);
$this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false);
}

View File

@ -74,7 +74,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
private function __construct()
{
$this->_root = dirname(__FILE__);
Doctrine_Locator_Injectable::initNullObject(new Doctrine_Null);
}
@ -190,9 +189,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
public function find($queryKey, $params = array(), $hydrationMode = Doctrine::HYDRATE_RECORD)
{
return Doctrine_Manager::getInstance()
->getQueryRegistry()
->get($queryKey)
->execute($params, $hydrationMode);
->getQueryRegistry()
->get($queryKey)
->execute($params, $hydrationMode);
}
/**
@ -210,9 +209,9 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
public function findOne($queryKey, $params = array(), $hydrationMode = Doctrine::HYDRATE_RECORD)
{
return Doctrine_Manager::getInstance()
->getQueryRegistry()
->get($queryKey)
->fetchOne($params, $hydrationMode);
->getQueryRegistry()
->get($queryKey)
->fetchOne($params, $hydrationMode);
}
/**
@ -275,9 +274,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$adapter = $parts;
} else {
$parts = $this->parseDsn($adapter);
$driverName = $parts['scheme'];
$adapter = $parts;
}
@ -297,7 +294,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$this->_index++;
}
$drivers = array('mysql' => 'Doctrine_Connection_Mysql',
'sqlite' => 'Doctrine_Connection_Sqlite',
'pgsql' => 'Doctrine_Connection_Pgsql',
@ -309,6 +305,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
'firebird' => 'Doctrine_Connection_Firebird',
'informix' => 'Doctrine_Connection_Informix',
'mock' => 'Doctrine_Connection_Mock');
if ( ! isset($drivers[$driverName])) {
throw new Doctrine_Manager_Exception('Unknown driver ' . $driverName);
}
@ -363,8 +360,6 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*/
public function parseDsn($dsn)
{
//fix linux sqlite dsn so that it will parse correctly
$dsn = str_replace("///", "/", $dsn);
@ -573,6 +568,18 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
{
return $this->getConnectionForComponent($componentName)->getTable($componentName);
}
/**
* getMapper
* Returns the mapper object for the given component name.
*
* @param string $componentName
* @return Doctrine_Mapper
*/
public function getMapper($componentName)
{
return $this->getConnectionForComponent($componentName)->getMapper($componentName);
}
/**
* table

1037
lib/Doctrine/Mapper.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
<?php
class Doctrine_Mapper_Exception extends Doctrine_Exception {}

View File

@ -0,0 +1,152 @@
<?php
class Doctrine_Mapper_Joined extends Doctrine_Mapper
{
/**
* inserts a record into database
*
* @param Doctrine_Record $record record to be inserted
* @return boolean
* @todo Move to Doctrine_Table (which will become Doctrine_Mapper).
*/
public function insert(Doctrine_Record $record)
{
$table = $this->_table;
$dataSet = $this->_formatDataSet($record);
$component = $table->getComponentName();
$classes = $table->getOption('joinedParents');
array_unshift($classes, $component);
foreach (array_reverse($classes) as $k => $parent) {
if ($k === 0) {
$rootRecord = new $parent();
$rootRecord->merge($dataSet[$parent]);
parent::insert($rootRecord);
$record->assignIdentifier($rootRecord->identifier());
} else {
foreach ((array) $rootRecord->identifier() as $id => $value) {
$dataSet[$parent][$id] = $value;
}
$this->_conn->insert($this->_conn->getTable($parent), $dataSet[$parent]);
}
}
return true;
}
/**
* updates given record
*
* @param Doctrine_Record $record record to be updated
* @return boolean whether or not the update was successful
* @todo Move to Doctrine_Table (which will become Doctrine_Mapper).
*/
public function update(Doctrine_Record $record)
{
$event = new Doctrine_Event($record, Doctrine_Event::RECORD_UPDATE);
$record->preUpdate($event);
$table = $this->_table;
$this->getRecordListener()->preUpdate($event);
if ( ! $event->skipOperation) {
$identifier = $record->identifier();
$dataSet = $this->_formatDataSet($record);
$component = $table->getComponentName();
$classes = $table->getOption('joinedParents');
array_unshift($classes, $component);
foreach ($record as $field => $value) {
if ($value instanceof Doctrine_Record) {
if ( ! $value->exists()) {
$value->save();
}
$record->set($field, $value->getIncremented());
}
}
foreach (array_reverse($classes) as $class) {
$parentTable = $this->_conn->getTable($class);
$this->_conn->update($parentTable, $dataSet[$class], $identifier);
}
$record->assignIdentifier(true);
}
$this->getRecordListener()->postUpdate($event);
$record->postUpdate($event);
return true;
}
/**
*
*
*/
public function getCustomJoins()
{
return $this->_table->getOption('joinedParents');
}
/**
*
*/
public function getDiscriminatorColumn($domainClassName)
{
$joinedParents = $this->_table->getOption('joinedParents');
if (count($joinedParents) <= 0) {
$inheritanceMap = $this->_table->getOption('inheritanceMap');
} else {
$inheritanceMap = $this->_conn->getTable(array_pop($joinedParents))->getOption('inheritanceMap');
}
return isset($inheritanceMap[$domainClassName]) ? $inheritanceMap[$domainClassName] : array();
}
/**
*
*/
public function getFieldNames()
{
if ($this->_fieldNames) {
return $this->_fieldNames;
}
$fieldNames = $this->_table->getFieldNames();
foreach ($this->_table->getOption('joinedParents') as $parent) {
$fieldNames = array_merge($this->_conn->getTable($parent)->getFieldNames(),
$fieldNames);
}
$this->_fieldNames = $fieldNames;
return $fieldNames;
}
/**
*
*/
protected function _formatDataSet(Doctrine_Record $record)
{
$table = $this->_table;
$dataSet = array();
$component = $table->getComponentName();
$array = $record->getPrepared();
$classes = array_merge(array($component), $this->_table->getOption('joinedParents'));
foreach ($classes as $class) {
$table = $this->_conn->getTable($class);
foreach ($table->getColumns() as $columnName => $definition) {
if (isset($definition['primary'])) {
continue;
}
$fieldName = $table->getFieldName($columnName);
$dataSet[$class][$fieldName] = isset($array[$fieldName]) ? $array[$fieldName] : null;
}
}
return $dataSet;
}
}

View File

@ -0,0 +1,15 @@
<?php
class Doctrine_Mapper_SingleTable extends Doctrine_Mapper
{
public function getDiscriminatorColumn($domainClassName)
{
$inheritanceMap = $this->_table->getOption('inheritanceMap');
return isset($inheritanceMap[$domainClassName]) ? $inheritanceMap[$domainClassName] : array();
}
}

View File

@ -0,0 +1,8 @@
<?php
class Doctrine_Mapper_TablePerClass extends Doctrine_Mapper
{
}

View File

@ -396,7 +396,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
return $this->getSqlAggregateAlias($dqlAlias);
} else {
throw new Doctrine_Query_Exception('Unknown aggregate alias: ' . $dqlAlias);
throw new Doctrine_Query_Exception('Unknown aggregate alias: ' . $dqlAlias);
}
}
@ -507,7 +507,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$columnName = $table->getColumnName($fieldName);
if (($owner = $table->getColumnOwner($columnName)) !== null &&
$owner !== $table->getComponentName()) {
$parent = $this->_conn->getTable($owner);
$columnName = $parent->getColumnName($fieldName);
$parentAlias = $this->getTableAlias($componentAlias . '.' . $parent->getComponentName());
@ -1156,10 +1155,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$q .= ' SET ' . implode(', ', $this->_sqlParts['set']);
}
$string = $this->applyInheritance();
// apply inheritance to WHERE part
// append discriminator column conditions (if any)
$string = $this->_createDiscriminatorSql();
if ( ! empty($string)) {
if (substr($string, 0, 1) === '(' && substr($string, -1) === ')') {
$this->_sqlParts['where'][] = $string;
@ -1496,15 +1493,19 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$table = $this->loadRoot($name, $componentAlias);
} else {
$join = ($delimeter == ':') ? 'INNER JOIN ' : 'LEFT JOIN ';
//echo "!!!!!!" . $prevPath . "!!!!!<br />";
$relation = $table->getRelation($name);
$localTable = $table;
$table = $relation->getTable();
$this->_queryComponents[$componentAlias] = array('table' => $table,
'parent' => $parent,
'relation' => $relation,
'map' => null);
//echo "<br /><br />" . $table->getComponentName() . "------" . $relation->getForeignComponentName() . "<br /><br />";
$this->_queryComponents[$componentAlias] = array(
'table' => $table,
'mapper' => $this->_conn->getMapper($relation->getForeignComponentName()),
'parent' => $parent,
'relation' => $relation,
'map' => null
);
if ( ! $relation->isOneToOne()) {
$this->_needsSubquery = true;
}
@ -1519,7 +1520,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
. ' '
. $this->_conn->quoteIdentifier($foreignAlias);
$map = $relation->getTable()->inheritanceMap;
$map = $relation->getTable()->getOption('inheritanceMap');
if ( ! $loadFields || ! empty($map) || $joinCondition) {
$this->_subqueryAliases[] = $foreignAlias;
@ -1529,14 +1530,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$asf = $relation->getAssociationTable();
$assocTableName = $asf->getTableName();
if ( ! $loadFields || ! empty($map) || $joinCondition) {
$this->_subqueryAliases[] = $assocTableName;
}
$assocPath = $prevPath . '.' . $asf->getComponentName();
$this->_queryComponents[$assocPath] = array('parent' => $prevPath, 'relation' => $relation, 'table' => $asf);
//var_dump($name); echo "hrrrr";
//echo "<br /><br />" . $asf->getComponentName() . "---2---" . $relation->getForeignComponentName() . "<br /><br />";
$this->_queryComponents[$assocPath] = array(
'parent' => $prevPath,
'relation' => $relation,
'table' => $asf,
'mapper' => $this->_conn->getMapper($relation->getAssociationClassName())
);
$assocAlias = $this->getTableAlias($assocPath, $asf->getTableName());
@ -1595,8 +1602,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
. $this->_conn->quoteIdentifier($foreignAlias . '.' . $relation->getForeign());
}
}
$queryPart .= $this->buildInheritanceJoinSql($table->getComponentName(), $componentAlias);
$queryPart .= $this->_createCustomJoinSql($table->getComponentName(), $componentAlias);
$this->_sqlParts['from'][$componentAlias] = $queryPart;
if ( ! empty($joinCondition)) {
@ -1615,6 +1622,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
}
$table = $this->_queryComponents[$componentAlias]['table'];
$mapper = $this->_queryComponents[$componentAlias]['mapper'];
$indexBy = null;
@ -1624,12 +1632,12 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
if (isset($e[1])) {
$indexBy = $e[1];
}
} elseif ($table->getBoundQueryPart('indexBy') !== null) {
$indexBy = $table->getBoundQueryPart('indexBy');
} else if ($mapper->getBoundQueryPart('indexBy') !== null) {
$indexBy = $mapper->getBoundQueryPart('indexBy');
}
if ($indexBy !== null) {
if ( ! $table->hasColumn($table->getColumnName($indexBy))) {
if ( ! $table->hasField($indexBy)) {
throw new Doctrine_Query_Exception("Couldn't use key mapping. Column " . $indexBy . " does not exist.");
}
@ -1667,58 +1675,15 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$this->_tableAliasMap[$tableAlias] = $componentAlias;
$queryPart .= $this->buildInheritanceJoinSql($name, $componentAlias);
$queryPart .= $this->_createCustomJoinSql($name, $componentAlias);
$this->_sqlParts['from'][] = $queryPart;
$this->_queryComponents[$componentAlias] = array('table' => $table, 'map' => null);
//echo "<br /><br />" . $table->getComponentName() . "---3---" . $name . "<br /><br />";
$this->_queryComponents[$componentAlias] = array(
'table' => $table, 'mapper' => $this->_conn->getMapper($name), 'map' => null);
return $table;
}
/**
* @todo DESCRIBE ME!
*/
public function buildInheritanceJoinSql($name, $componentAlias)
{
// get the connection for the component
$manager = Doctrine_Manager::getInstance();
if ($manager->hasConnectionForComponent($name)) {
$this->_conn = $manager->getConnectionForComponent($name);
}
$table = $this->_conn->getTable($name);
$tableName = $table->getTableName();
// get the short alias for this table
$tableAlias = $this->getTableAlias($componentAlias, $tableName);
$queryPart = '';
foreach ($table->getOption('joinedParents') as $parent) {
$parentTable = $this->_conn->getTable($parent);
$parentAlias = $componentAlias . '.' . $parent;
// get the short alias for the parent table
$parentTableAlias = $this->getTableAlias($parentAlias, $parentTable->getTableName());
$queryPart .= ' LEFT JOIN ' . $this->_conn->quoteIdentifier($parentTable->getTableName())
. ' ' . $this->_conn->quoteIdentifier($parentTableAlias) . ' ON ';
//Doctrine::dump($table->getIdentifier());
foreach ((array) $table->getIdentifier() as $identifier) {
$column = $table->getColumnName($identifier);
$queryPart .= $this->_conn->quoteIdentifier($tableAlias)
. '.' . $this->_conn->quoteIdentifier($column)
. ' = ' . $this->_conn->quoteIdentifier($parentTableAlias)
. '.' . $this->_conn->quoteIdentifier($column);
}
}
return $queryPart;
}
/**
* count
@ -1767,12 +1732,12 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$q .= ' FROM ' . $this->_buildSqlFromPart();
// append column aggregation inheritance (if needed)
$string = $this->applyInheritance();
// append discriminator column conditions (if any)
$string = $this->_createDiscriminatorSql();
if ( ! empty($string)) {
$where[] = $string;
}
// append conditions
$q .= ( ! empty($where)) ? ' WHERE ' . implode(' AND ', $where) : '';
$q .= ( ! empty($groupby)) ? ' GROUP BY ' . implode(', ', $groupby) : '';

View File

@ -152,21 +152,21 @@ abstract class Doctrine_Query_Abstract
);
/**
* @var array $_dqlParts an array containing all DQL query parts
* @var array $_dqlParts An array containing all DQL query parts.
*/
protected $_dqlParts = array(
'from' => array(),
'select' => array(),
'forUpdate' => false,
'set' => array(),
'join' => array(),
'where' => array(),
'groupby' => array(),
'having' => array(),
'orderby' => array(),
'limit' => array(),
'offset' => array(),
);
'from' => array(),
'select' => array(),
'forUpdate' => false,
'set' => array(),
'join' => array(),
'where' => array(),
'groupby' => array(),
'having' => array(),
'orderby' => array(),
'limit' => array(),
'offset' => array(),
);
/**
@ -522,21 +522,59 @@ abstract class Doctrine_Query_Abstract
}
/**
* applyInheritance
* applies column aggregation inheritance to DQL / SQL query
*
* @return string
* Creates the SQL snippet for additional joins.
*
* @return string The created SQL snippet.
*/
public function applyInheritance()
protected function _createCustomJoinSql($componentName, $componentAlias)
{
$table = $this->_conn->getTable($componentName);
$tableAlias = $this->getSqlTableAlias($componentAlias, $table->getTableName());
$customJoins = $this->_conn->getMapper($componentName)->getCustomJoins();
$sql = '';
foreach ($customJoins as $componentName) {
$joinedTable = $this->_conn->getTable($componentName);
$joinedAlias = $componentAlias . '.' . $componentName;
$joinedTableAlias = $this->getSqlTableAlias($joinedAlias, $joinedTable->getTableName());
$sql .= ' LEFT JOIN ' . $this->_conn->quoteIdentifier($joinedTable->getTableName())
. ' ' . $this->_conn->quoteIdentifier($joinedTableAlias) . ' ON ';
foreach ($table->getIdentifierColumnNames() as $column) {
$sql .= $this->_conn->quoteIdentifier($tableAlias)
. '.' . $this->_conn->quoteIdentifier($column)
. ' = ' . $this->_conn->quoteIdentifier($joinedTableAlias)
. '.' . $this->_conn->quoteIdentifier($column);
}
}
return $sql;
}
/**
* Creates the SQL snippet for the WHERE part that contains the discriminator
* column conditions.
*
* @return string The created SQL snippet.
*/
protected function _createDiscriminatorSql()
{
// get the inheritance maps
$array = array();
foreach ($this->_queryComponents as $componentAlias => $data) {
$tableAlias = $this->getSqlTableAlias($componentAlias);
$array[$tableAlias][] = $data['table']->inheritanceMap;
//echo $data['table']->getComponentName() . " -- ";
/*if (!isset($data['mapper'])) {
//echo $data['table']->getComponentName();
echo $this->getDql();
}*/
/*if ($data['mapper']->getComponentName() != $data['table']->getComponentName()) {
//echo $this->getDql() . "<br />";
}*/
//echo $data['mapper']->getComponentName() . "_<br />";
//var_dump($data['mapper']->getDiscriminatorColumn($data['mapper']->getComponentName()));
$array[$tableAlias][] = $data['mapper']->getDiscriminatorColumn($data['mapper']->getComponentName());
}
//var_dump($array);
// apply inheritance maps
$str = '';
$c = array();
@ -902,6 +940,7 @@ abstract class Doctrine_Query_Abstract
}
$stmt = $this->_conn->execute($query, $params);
return $stmt;
}
@ -973,11 +1012,13 @@ abstract class Doctrine_Query_Abstract
foreach ($cachedComponents as $alias => $components) {
$e = explode('.', $components[0]);
if (count($e) === 1) {
$queryComponents[$alias]['table'] = $this->_conn->getTable($e[0]);
$queryComponents[$alias]['mapper'] = $this->_conn->getMapper($e[0]);
$queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getTable();
} else {
$queryComponents[$alias]['parent'] = $e[0];
$queryComponents[$alias]['relation'] = $queryComponents[$e[0]]['table']->getRelation($e[1]);
$queryComponents[$alias]['table'] = $queryComponents[$alias]['relation']->getTable();
$queryComponents[$alias]['mapper'] = $this->_conn->getMapper($queryComponents[$alias]['relation']->getForeignComponentName());
$queryComponents[$alias]['table'] = $queryComponents[$alias]['mapper']->getTable();
}
if (isset($v[1])) {
$queryComponents[$alias]['agg'] = $components[1];
@ -1004,7 +1045,8 @@ abstract class Doctrine_Query_Abstract
foreach ($this->getQueryComponents() as $alias => $components) {
if ( ! isset($components['parent'])) {
$componentInfo[$alias][] = $components['table']->getComponentName();
$componentInfo[$alias][] = $components['mapper']->getComponentName();
//$componentInfo[$alias][] = $components['mapper']->getComponentName();
} else {
$componentInfo[$alias][] = $components['parent'] . '.' . $components['relation']->getAlias();
}

View File

@ -40,7 +40,7 @@ class Doctrine_Query_From extends Doctrine_Query_Part
* @return void
*/
public function parse($str)
{
{
$str = trim($str);
$parts = $this->_tokenizer->bracketExplode($str, 'JOIN');
@ -78,7 +78,6 @@ class Doctrine_Query_From extends Doctrine_Query_Part
if ($operator) {
$e[0] = array_shift($e2) . $operator . implode('.', $e2);
}
$table = $this->query->load(implode(' ', $e));
}

View File

@ -99,6 +99,7 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
}
}
return $condition;
}
}

View File

@ -233,7 +233,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
}
}
$string = $this->applyInheritance();
$string = $this->_createDiscriminatorSql();
if ( ! empty($string)) {
$this->_sqlParts['where'][] = $string;
}
@ -312,13 +312,16 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
->getConnectionForComponent($component);
$table = $conn->getTable($component);
$this->_queryComponents[$componentAlias] = array('table' => $table);
$this->_queryComponents[$componentAlias] = array(
'table' => $table, 'mapper' => $conn->getMapper($component));
} else {
$relation = $table->getRelation($component);
$this->_queryComponents[$componentAlias] = array('table' => $relation->getTable(),
'parent' => $parent,
'relation' => $relation);
$this->_queryComponents[$componentAlias] = array(
'table' => $relation->getTable(),
'mapper' => $this->_conn->getMapper($component),
'parent' => $parent,
'relation' => $relation);
}
$this->addSqlTableAlias($tableAlias, $componentAlias);

View File

@ -78,6 +78,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
const STATE_LOCKED = 6;
/**
*
*/
protected $_domainClassName;
/**
* @var Doctrine_Node_<TreeImpl> node object
*/
@ -141,39 +146,51 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* open connections
* @throws Doctrine_Record_Exception if the cleanData operation fails somehow
*/
public function __construct($table = null, $isNewEntry = false)
public function __construct($mapper = null, $isNewEntry = false)
{
if (isset($table) && $table instanceof Doctrine_Table) {
$this->_table = $table;
$exists = ( ! $isNewEntry);
} else {
//echo get_class($this) . "<br />";
if (isset($mapper) && $mapper instanceof Doctrine_Table) {
//echo "one<br />";
$this->_table = $mapper;
//$this->_mapper = Doctrine_Manager::getInstance()->getMapper(get_class($this));
$exists = ! $isNewEntry;
return;
} else if (isset($mapper) && $mapper instanceof Doctrine_Mapper) {
//echo "two<br />";
$class = get_class($this);
// get the table of this class
$this->_table = Doctrine_Manager::getInstance()->getTable($class);
$this->_mapper = Doctrine_Manager::getInstance()->getMapper($class);
if ($class != $this->_mapper->getComponentName()) {
try {
throw new Exception("ddd");
} catch (Exception $e) {
echo "MISMATCH: " . get_class($this) . "---" . $mapper->getComponentName();
echo $e->getTraceAsString() . "<br /><br />";
}
}
$this->_table = $this->_mapper->getTable();
$exists = ! $isNewEntry;
} else {
//echo "three<br />";
$this->_mapper = Doctrine_Manager::getInstance()->getMapper(get_class($this));
$this->_table = $this->_mapper->getTable();
$exists = false;
}
// Check if the current connection has the records table in its registry
// If not this record is only used for creating table definition and setting up
// relations.
if ( ! $this->_table->getConnection()->hasTable($this->_table->getComponentName())) {
return;
}
$this->_domainClassName = get_class($this);
$this->_oid = self::$_index;
self::$_index++;
// get the data array
$this->_data = $this->_table->getData();
$this->_data = $this->_mapper->getData();
// get the column count
$count = count($this->_data);
$this->_values = $this->cleanData($this->_data);
$this->prepareIdentifiers($exists);
if ( ! $exists) {
if ($count > count($this->_values)) {
$this->_state = Doctrine_Record::STATE_TDIRTY;
@ -192,8 +209,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
$this->_errorStack = new Doctrine_Validator_ErrorStack(get_class($this));
$repository = $this->_table->getRepository();
$repository = $this->_mapper->getRepository();
$repository->add($this);
$this->construct();
@ -219,6 +235,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function setUp()
{ }
/**
* construct
* Empty template method to provide concrete Record classes with the possibility
@ -228,6 +245,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function construct()
{ }
/**
* getOid
* returns the object identifier
@ -238,6 +256,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
return $this->_oid;
}
public function oid()
{
return $this->_oid;
@ -250,7 +269,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function isValid()
{
if ( ! $this->_table->getAttribute(Doctrine::ATTR_VALIDATE)) {
if ( ! $this->_mapper->getAttribute(Doctrine::ATTR_VALIDATE)) {
return true;
}
// Clear the stack from any previous errors.
@ -276,6 +295,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
protected function validate()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the validation procedure only when the record is going to be
@ -283,6 +303,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
protected function validateOnUpdate()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the validation procedure only when the record is going to be
@ -290,54 +311,63 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
protected function validateOnInsert()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function preSerialize($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function postSerialize($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function preUnserialize($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the serializing procedure.
*/
public function postUnserialize($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure.
*/
public function preSave($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure.
*/
public function postSave($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the deletion procedure.
*/
public function preDelete($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the deletion procedure.
*/
public function postDelete($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure only when the record is going to be
@ -345,6 +375,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function preUpdate($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure only when the record is going to be
@ -352,6 +383,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function postUpdate($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure only when the record is going to be
@ -359,6 +391,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function preInsert($event)
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure only when the record is going to be
@ -366,6 +399,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function postInsert($event)
{ }
/**
* getErrorStack
*
@ -435,7 +469,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$tmp = $data;
$data = array();
foreach ($this->getTable()->getFieldNames() as $fieldName) {
$fieldNames = $this->_mapper->getFieldNames();
foreach ($fieldNames as $fieldName) {
if (isset($tmp[$fieldName])) {
$data[$fieldName] = $tmp[$fieldName];
} else if (!isset($this->_data[$fieldName])) {
@ -513,7 +548,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$vars = get_object_vars($this);
unset($vars['_references']);
unset($vars['_table']);
unset($vars['_mapper']);
//unset($vars['_table']);
unset($vars['_errorStack']);
unset($vars['_filter']);
unset($vars['_node']);
@ -524,7 +560,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
foreach ($this->_data as $k => $v) {
if ($v instanceof Doctrine_Record && $this->_table->getTypeOf($k) != 'object') {
unset($vars['_data'][$k]);
} elseif ($v === self::$_null) {
} else if ($v === self::$_null) {
unset($vars['_data'][$k]);
} else {
switch ($this->_table->getTypeOf($k)) {
@ -541,7 +577,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
}
}
$str = serialize($vars);
$this->postSerialize($event);
@ -569,16 +605,17 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$this->_oid = self::$_index;
self::$_index++;
$this->_table = $connection->getTable(get_class($this));
$this->_mapper = $connection->getMapper(get_class($this));
$array = unserialize($serialized);
foreach($array as $k => $v) {
$this->$k = $v;
}
$this->_table = $this->_mapper->getTable();
foreach ($this->_data as $k => $v) {
switch ($this->_table->getTypeOf($k)) {
case 'array':
case 'object':
@ -594,12 +631,9 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
}
$this->_table->getRepository()->add($this);
$this->_mapper->getRepository()->add($this);
$this->cleanData($this->_data);
$this->prepareIdentifiers($this->exists());
$this->postUnserialize($event);
}
@ -642,7 +676,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
if ($err) {
throw new Doctrine_Record_State_Exception('Unknown record state ' . $state);
throw new Doctrine_Record_Exception('Unknown record state ' . $state);
}
}
@ -669,15 +703,16 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$id = array_values($id);
if ($deep) {
$query = $this->getTable()->createQuery();
$query = $this->_mapper->createQuery();
foreach (array_keys($this->_references) as $name) {
$query->leftJoin(get_class($this) . '.' . $name);
}
$query->where(implode(' = ? AND ', $this->getTable()->getIdentifierColumnNames()) . ' = ?');
$query->where(implode(' = ? AND ', $this->_table->getIdentifierColumnNames()) . ' = ?');
$record = $query->fetchOne($id);
} else {
// Use FETCH_ARRAY to avoid clearing object relations
$record = $this->getTable()->find($id, Doctrine::HYDRATE_ARRAY);
$record = $this->_mapper->find($id, Doctrine::HYDRATE_ARRAY);
if ($record) {
$this->hydrate($record);
}
@ -749,6 +784,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
return $this->_data;
}
public function getValues()
{
return $this->_values;
}
/**
* rawGet
@ -821,14 +861,17 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
try {
if ( ! isset($this->_references[$fieldName]) && $load) {
$rel = $this->_table->getRelation($fieldName);
$this->_references[$fieldName] = $rel->fetchRelatedFor($this);
/*if (count($this->_references[$fieldName]) > 0) {
echo $this->_references[$fieldName][0]->state() . "<br />";
}*/
}
return $this->_references[$fieldName];
} catch (Doctrine_Table_Exception $e) {
//echo $e->getTraceAsString();
//echo "<br /><br />";
foreach ($this->_table->getFilters() as $filter) {
if (($value = $filter->filterGet($this, $fieldName, $value)) !== null) {
return $value;
@ -867,8 +910,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* @return Doctrine_Record
*/
public function set($fieldName, $value, $load = true)
{
if (isset($this->_data[$fieldName])) {
{
if (isset($this->_data[$fieldName])) {
if ($value instanceof Doctrine_Record) {
$type = $this->_table->getTypeOf($fieldName);
@ -894,6 +937,12 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$this->_modified[] = $fieldName;
switch ($this->_state) {
case Doctrine_Record::STATE_CLEAN:
/*try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br /><br />";
}
echo "setting dirty ... <br />";*/
$this->_state = Doctrine_Record::STATE_DIRTY;
break;
case Doctrine_Record::STATE_TCLEAN:
@ -903,7 +952,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
} else {
try {
$this->coreSetRelated($fieldName, $value);
$this->_coreSetRelated($fieldName, $value);
} catch (Doctrine_Table_Exception $e) {
foreach ($this->_table->getFilters() as $filter) {
if (($value = $filter->filterSet($this, $fieldName, $value)) !== null) {
@ -918,7 +967,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* DESCRIBE WHAT THIS METHOD DOES, PLEASE!
* @todo Refactor. What about composite keys?
*/
public function coreSetRelated($name, $value)
private function _coreSetRelated($name, $value)
{
$rel = $this->_table->getRelation($name);
@ -937,8 +986,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
} else {
if ($value !== self::$_null) {
$relatedTable = $value->getTable();
$foreignFieldName = $relatedTable->getFieldName($rel->getForeign());
$localFieldName = $this->_table->getFieldName($rel->getLocal());
$foreignFieldName = $rel->getForeignFieldName();
$localFieldName = $rel->getLocalFieldName();
// one-to-one relation found
if ( ! ($value instanceof Doctrine_Record)) {
@ -1003,7 +1052,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
if ($this->_references[$fieldName] instanceof Doctrine_Record) {
// todo: delete related record when saving $this
$this->_references[$fieldName] = self::$_null;
} elseif ($this->_references[$fieldName] instanceof Doctrine_Collection) {
} else if ($this->_references[$fieldName] instanceof Doctrine_Collection) {
$this->_references[$fieldName]->setData(array());
}
}
@ -1021,10 +1070,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function save(Doctrine_Connection $conn = null)
{
if ($conn === null) {
$conn = $this->_table->getConnection();
}
$conn->unitOfWork->saveGraph($this);
$this->_mapper->saveGraph($this, $conn);
}
/**
@ -1066,7 +1112,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
public function replace(Doctrine_Connection $conn = null)
{
if ($conn === null) {
$conn = $this->_table->getConnection();
$conn = $this->_mapper->getConnection();
}
return $conn->replace($this->_table, $this->getPrepared(), $this->_id);
@ -1075,12 +1121,21 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
/**
* returns an array of modified fields and associated values
* @return array
* @todo What about a better name? getModifiedFields?
* @deprecated
*/
public function getModified()
{
return $this->getModifiedFields();
}
/**
* returns an array of modified fields and associated values.
*
* @return array
*/
public function getModifiedFields()
{
$a = array();
foreach ($this->_modified as $k => $v) {
$a[$v] = $this->_data[$v];
}
@ -1090,7 +1145,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
/**
* REDUNDANT?
*/
public function modifiedFields()
/*public function modifiedFields()
{
$a = array();
@ -1098,7 +1153,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$a[$v] = $this->_data[$v];
}
return $a;
}
}*/
/**
* getPrepared
@ -1153,10 +1208,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$a[$field] = $this->_data[$field];
}
}
$map = $this->_table->inheritanceMap;
//$map = $this->_table->getOption('inheritanceMap');
$map = $this->_mapper->getDiscriminatorColumn($this->_domainClassName);
foreach ($map as $k => $v) {
$old = $this->get($k, false);
if ((string) $old !== (string) $v || $old === null) {
$a[$k] = $v;
$this->_data[$k] = $v;
@ -1206,8 +1261,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
if ($this->_table->getIdentifierType() == Doctrine::IDENTIFIER_AUTOINC) {
$i = $this->_table->getIdentifier();
$a[$i] = $this->getIncremented();
$i = $this->_table->getIdentifier();
$a[$i] = $this->getIncremented();
}
if ($deep) {
@ -1237,6 +1292,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$array = $data->toArray($deep);
} else if (is_array($data)) {
$array = $data;
} else {
$array = array();
}
return $this->fromArray($array, $deep);
@ -1284,7 +1341,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
// eliminate relationships missing in the $array
foreach ($this->_references as $name => $obj) {
if (!isset($array[$name])) {
if ( ! isset($array[$name])) {
unset($this->$name);
}
}
@ -1380,7 +1437,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
public function delete(Doctrine_Connection $conn = null)
{
if ($conn == null) {
$conn = $this->_table->getConnection();
$conn = $this->_mapper->getConnection();
}
return $conn->unitOfWork->delete($this);
}
@ -1401,7 +1458,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
unset($data[$id]);
}
$ret = $this->_table->create($data);
$ret = $this->_mapper->create($data);
$modified = array();
foreach ($data as $key => $val) {
@ -1438,7 +1495,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$this->_data = $this->cleanData($this->_data);
$this->_state = Doctrine_Record::STATE_TCLEAN;
$this->_modified = array();
} elseif ($id === true) {
} else if ($id === true) {
$this->prepareIdentifiers(true);
$this->_state = Doctrine_Record::STATE_CLEAN;
$this->_modified = array();
@ -1604,13 +1661,13 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
if ( ! isset($this->_node)) {
$this->_node = Doctrine_Node::factory($this,
$this->getTable()->getOption('treeImpl'),
$this->getTable()->getOption('treeOptions')
);
$this->getTable()->getOption('treeImpl'),
$this->getTable()->getOption('treeOptions'));
}
return $this->_node;
}
/**
* revert
* reverts this record to given version, this method only works if versioning plugin
@ -1635,10 +1692,12 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
return $this;
}
public function unshiftFilter(Doctrine_Record_Filter $filter)
{
return $this->_table->unshiftFilter($filter);
}
/**
* unlink
* removes links from this record to given records
@ -1680,10 +1739,13 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
if (isset($this->_references[$alias])) {
foreach ($this->_references[$alias] as $k => $record) {
if (in_array(current($record->identifier()), $ids)) {
$this->_references[$alias]->remove($k);
}
}
$this->_references[$alias]->takeSnapshot();
}
return $this;
@ -1749,7 +1811,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$q = new Doctrine_Query();
$q->update($this->getTable()->getComponentName())
->set($rel->getLocalFieldName(), '?', $ids);
->set($rel->getLocalFieldName(), '?', $ids);
if (count($ids) > 0) {
$q->whereIn($rel->getTable()->getIdentifier(), array_values($this->identifier()));
@ -1778,15 +1840,15 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
*/
public function __call($method, $args)
{
if (($template = $this->_table->getMethodOwner($method)) !== false) {
if (($template = $this->_mapper->getMethodOwner($method)) !== false) {
$template->setInvoker($this);
return call_user_func_array(array($template, $method), $args);
}
foreach ($this->_table->getTemplates() as $template) {
foreach ($this->_mapper->getTable()->getTemplates() as $template) {
if (method_exists($template, $method)) {
$template->setInvoker($this);
$this->_table->setMethodOwner($method, $template);
$this->_mapper->setMethodOwner($method, $template);
return call_user_func_array(array($template, $method), $args);
}
@ -1799,9 +1861,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* used to delete node from tree - MUST BE USE TO DELETE RECORD IF TABLE ACTS AS TREE
*
*/
public function deleteNode() {
public function deleteNode()
{
$this->getNode()->delete();
}
public function toString()
{
return Doctrine::dump(get_object_vars($this));
@ -1814,4 +1878,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
return (string) $this->_oid;
}
public function free()
{
$this->_mapper->getRepository()->evict($this->_oid);
$this->_mapper->removeRecord($this);
}
}

View File

@ -36,11 +36,18 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
* @param Doctrine_Table $_table reference to associated Doctrine_Table instance
*/
protected $_table;
/**
*
* @var Doctrine_Mapper_Abstract
*/
protected $_mapper;
public function setTableDefinition()
{
}
public function setUp()
{
@ -57,6 +64,11 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
{
return $this->_table;
}
public function getMapper()
{
return $this->_mapper;
}
/**
* addListener
@ -120,6 +132,11 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
{
$this->_table->setTableName($tableName);
}
/**
*
* @deprecated Use setSubclasses()
*/
public function setInheritanceMap($map)
{
$this->_table->setOption('inheritanceMap', $map);
@ -127,16 +144,10 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
public function setSubclasses($map)
{
if (isset($map[get_class($this)])) {
$this->_table->setOption('inheritanceMap', $map[get_class($this)]);
return;
}
//echo "setting inheritance map on " . get_class($this) . "<br />";
$this->_table->setOption('inheritanceMap', $map);
$this->_table->setOption('subclasses', array_keys($map));
$conn = $this->_table->getConnection();
foreach ($map as $key => $value) {
$table = $conn->getTable($key);
$table->setOption('inheritanceMap', $value);
}
$this->_table->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE);
}
/**
@ -293,6 +304,13 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
*/
public function bindQueryParts(array $queryParts)
{
if (!$this->_table) {
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br />";
}
}
$this->_table->bindQueryParts($queryParts);
return $this;
@ -331,7 +349,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
}
if ( ! ($tpl instanceof Doctrine_Template)) {
throw new Doctrine_Record_Exception('Loaded plugin class is not an istance of Doctrine_Template.');
throw new Doctrine_Record_Exception('Loaded plugin class is not an instance of Doctrine_Template.');
}
$className = get_class($tpl);
@ -344,6 +362,27 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
return $this;
}
/**
*
*
*/
public function setInheritanceType($type, array $options = null)
{
if ($type == Doctrine::INHERITANCETYPE_SINGLE_TABLE) {
$this->setSubclasses($options);
} else if ($type == Doctrine::INHERITANCETYPE_JOINED) {
$this->setSubclasses($options);
} else if ($type == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) {
// concrete table inheritance ...
}
$this->_table->setInheritanceType($type);
}
protected function _getMapper($className)
{
}
/**
* check

View File

@ -60,22 +60,36 @@ abstract class Doctrine_Relation implements ArrayAccess
const ONE = 0;
const MANY = 2;
protected $definition = array('alias' => true,
'foreign' => true,
'local' => true,
'class' => true,
'type' => true,
'table' => true,
'localTable' => true,
'name' => false,
'refTable' => false,
protected $definition = array('alias' => true, // relation alias
'foreign' => true, // foreign column names
'local' => true, // local column names
'class' => true, // related(foreign) class name
'type' => true, // relation type
'table' => true, // related(foreign) table object
'localTable' => true, // local table object
'name' => false,
'onDelete' => false,
'onUpdate' => false,
'deferred' => false,
'deferrable' => false,
'constraint' => false,
'equal' => false,
'refClass' => false, // the name of the association class (many-many)
'refTable' => false, // the association table object (many-many)
'refRelationName' => false,
'refReverseRelationName' => false,
);
/**
* The mapper of the foreign (related) class.
*/
protected $_foreignMapper;
/**
* The mapper of the local class.
*/
protected $_localMapper;
/**
* constructor
@ -137,8 +151,8 @@ abstract class Doctrine_Relation implements ArrayAccess
$def[$key] = null;
}
}
$this->definition = $def;
$this->_foreignMapper = $this->getTable()->getConnection()->getMapper($def['class']);
}
/**
@ -153,6 +167,7 @@ abstract class Doctrine_Relation implements ArrayAccess
($this->definition['onUpdate']) ||
($this->definition['onDelete']));
}
public function isDeferred()
{
return $this->definition['deferred'];
@ -162,6 +177,7 @@ abstract class Doctrine_Relation implements ArrayAccess
{
return $this->definition['deferrable'];
}
public function isEqual()
{
return $this->definition['equal'];
@ -213,6 +229,11 @@ abstract class Doctrine_Relation implements ArrayAccess
{
return $this->definition['alias'];
}
public function getRelationName()
{
return $this->definition['relName'];
}
/**
* getType
@ -320,6 +341,11 @@ abstract class Doctrine_Relation implements ArrayAccess
return $dql;
}
public function getForeignComponentName()
{
return $this->definition['class'];
}
/**
* fetchRelatedFor

View File

@ -20,10 +20,9 @@
*/
Doctrine::autoload('Doctrine_Relation');
/**
* Doctrine_Relation_Association this class takes care of association mapping
* (= many-to-many relationships, where the relationship is handled with an additional relational table
* which holds 2 foreign keys)
* Doctrine_Relation_Association
*
* This class is reponsible for lazy-loading the related objects in a many-to-many relation.
*
* @package Doctrine
* @subpackage Relation
@ -46,6 +45,12 @@ class Doctrine_Relation_Association extends Doctrine_Relation
{
return $this->definition['refTable'];
}
public function getAssociationClassName()
{
return $this->definition['refClass'];
}
/**
* getRelationDql
@ -55,21 +60,36 @@ class Doctrine_Relation_Association extends Doctrine_Relation
*/
public function getRelationDql($count, $context = 'record')
{
$table = $this->definition['refTable'];
$component = $this->definition['refTable']->getComponentName();
//$table = $this->definition['refTable'];
$assocRelationName = isset($this->definition['refReverseRelationName']) ?
$this->definition['refReverseRelationName'] : $this->definition['refClass'];
/*if ($this->definition['localTable'] === $this->definition['table']) {
echo $this->definition['class'];
$rel = $this->definition['table']->getRelation('User');
$relationName = $rel->getRelationName();
}*/
//var_dump($this->definition['foreign']) . "<br />";
//echo $component;
//$rel = $this->definition['refTable']->getRelation($this->_foreignMapper->getComponentName());
//echo "LOCAL:" . $rel->getLocal() . "<br />";
$relatedClassName = $this->_foreignMapper->getComponentName();
switch ($context) {
case "record":
$sub = substr(str_repeat("?, ", $count),0,-2);
$dql = 'FROM ' . $this->getTable()->getComponentName();
$dql .= '.' . $component;
$dql .= ' WHERE ' . $this->getTable()->getComponentName()
. '.' . $component . '.' . $this->definition['local'] . ' IN (' . $sub . ')';
$dql = "FROM $relatedClassName";
$dql .= " INNER JOIN $relatedClassName.$assocRelationName";
//$dql .= " ON $relatedClassName.$assocRelationName.$inverseJoinColumn = $relatedClassName.$relatedClassIdentifier";
$dql .= " WHERE $relatedClassName.$assocRelationName.{$this->definition['local']} IN ($sub)";
break;
case "collection":
$sub = substr(str_repeat("?, ", $count),0,-2);
$dql = 'FROM ' . $component . '.' . $this->getTable()->getComponentName();
$dql .= ' WHERE ' . $component . '.' . $this->definition['local'] . ' IN (' . $sub . ')';
$dql = "FROM $assocRelationName INNER JOIN $assocRelationName.$relatedClassName";
//$dql .= " ON $relatedClassName.$assocRelationName.$inverseJoinColumn = $relatedClassName.$relatedClassIdentifier";
$dql .= " WHERE $assocRelationName.{$this->definition['local']} IN ($sub)";
break;
}
@ -87,9 +107,13 @@ class Doctrine_Relation_Association extends Doctrine_Relation
public function fetchRelatedFor(Doctrine_Record $record)
{
$id = $record->getIncremented();
if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$coll = new Doctrine_Collection($this->getTable());
if (empty($id) || ! $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);

View File

@ -54,19 +54,19 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association
. ' WHERE '.$this->definition['foreign']
. ' = ?';
$dql = 'FROM ' . $this->definition['table']->getComponentName()
$dql = 'FROM ' . $this->_foreignMapper->getComponentName()
. '.' . $this->definition['refTable']->getComponentName()
. ' WHERE ' . $this->definition['table']->getComponentName()
. ' WHERE ' . $this->_foreignMapper->getComponentName()
. '.' . $identifier
. ' IN (' . $sub . ')'
. ' || ' . $this->definition['table']->getComponentName()
. ' || ' . $this->_foreignMapper->getComponentName()
. '.' . $identifier
. ' IN (' . $sub2 . ')';
break;
case 'collection':
$sub = substr(str_repeat('?, ', $count),0,-2);
$dql = 'FROM '.$this->definition['refTable']->getComponentName()
. '.' . $this->definition['table']->getComponentName()
. '.' . $this->_foreignMapper->getComponentName()
. ' WHERE '.$this->definition['refTable']->getComponentName()
. '.' . $this->definition['local'] . ' IN (' . $sub . ')';
};

View File

@ -45,39 +45,39 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
{
$id = array();
$localTable = $record->getTable();
foreach ((array) $this->definition['local'] as $local) {
$value = $record->get($localTable->getFieldName($local));
if (isset($value)) {
$id[] = $value;
}
}
if ($this->isOneToOne()) {
if ( ! $record->exists() || empty($id) ||
! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->getTable()->create();
! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->_foreignMapper->create();
} else {
$dql = 'FROM ' . $this->getTable()->getComponentName()
$dql = 'FROM ' . $this->_foreignMapper->getComponentName()
. ' WHERE ' . $this->getCondition();
$coll = $this->getTable()->getConnection()->query($dql, $id);
$related = $coll[0];
}
// set the foreign key field on the related record
$related->set($related->getTable()->getFieldName($this->definition['foreign']),
$record, false);
} else {
if ( ! $record->exists() || empty($id) ||
! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = new Doctrine_Collection($this->getTable());
! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = new Doctrine_Collection($this->_foreignMapper->getComponentName());
} else {
$query = $this->getRelationDql(1);
$related = $this->getTable()->getConnection()->query($query, $id);
$query = $this->getRelationDql(1);
$related = $this->getTable()->getConnection()->query($query, $id);
}
$related->setReference($record, $this);
}
return $related;
}

View File

@ -46,8 +46,8 @@ class Doctrine_Relation_LocalKey extends Doctrine_Relation
$localFieldName = $record->getTable()->getFieldName($this->definition['local']);
$id = $record->get($localFieldName);
if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->getTable()->create();
if (empty($id) || ! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
$related = $this->_foreignMapper->create();
} else {
$dql = 'FROM ' . $this->getTable()->getComponentName()
. ' WHERE ' . $this->getCondition();

View File

@ -105,9 +105,10 @@ class Doctrine_Relation_Nest extends Doctrine_Relation_Association
$id = $record->getIncremented();
if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
return new Doctrine_Collection($this->getTable());
if (empty($id) || ! $this->_foreignMapper->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
return new Doctrine_Collection($this->getForeignComponentName());
} else {
$q = new Doctrine_RawSql();
$assocTable = $this->getAssociationFactory()->getTableName();

View File

@ -104,14 +104,7 @@ class Doctrine_Relation_Parser
unset($this->relations[$name]);
}
/* looks like old code?
$lower = strtolower($name);
if ($this->_table->hasColumn($lower)) {
throw new Doctrine_Relation_Exception("Couldn't bind relation. Column with name " . $lower . ' already exists!');
}
*/
$e = explode(' as ', $name);
$e = explode(' as ', $name);
$name = $e[0];
$alias = isset($e[1]) ? $e[1] : $name;
@ -120,16 +113,6 @@ class Doctrine_Relation_Parser
}
$this->_pending[$alias] = array_merge($options, array('class' => $name, 'alias' => $alias));
/**
$m = Doctrine_Manager::getInstance();
if (isset($options['onDelete'])) {
$m->addDeleteAction($name, $this->_table->getComponentName(), $options['onDelete']);
}
if (isset($options['onUpdate'])) {
$m->addUpdateAction($name, $this->_table->getComponentName(), $options['onUpdate']);
}
*/
return $this->_pending[$alias];
}
@ -142,70 +125,126 @@ class Doctrine_Relation_Parser
public function getRelation($alias, $recursive = true)
{
if (isset($this->_relations[$alias])) {
/*if ($alias == 'Groupuser') {
//var_dump($this->_relations[$alias]['foreign']);
}*/
return $this->_relations[$alias];
}
if (isset($this->_pending[$alias])) {
$def = $this->_pending[$alias];
$identifierColumnNames = $this->_table->getIdentifierColumnNames();
$idColumnName = array_pop($identifierColumnNames);
// check if reference class name exists
// if it does we are dealing with association relation
if (isset($def['refClass'])) {
$def = $this->completeAssocDefinition($def);
$localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getComponentName()));
if ( ! isset($this->_pending[$def['refClass']]) &&
! isset($this->_relations[$def['refClass']])) {
$parser = $def['refTable']->getRelationParser();
if ( ! $parser->hasRelation($this->_table->getComponentName())) {
$parser->bind($this->_table->getComponentName(),
array('type' => Doctrine_Relation::ONE,
'local' => $def['local'],
'foreign' => $idColumnName,
'localKey' => true,
));
}
if ( ! $this->hasRelation($def['refClass'])) {
$this->bind($def['refClass'], array('type' => Doctrine_Relation::MANY,
'foreign' => $def['local'],
'local' => $idColumnName));
}
}
if (in_array($def['class'], $localClasses)) {
$rel = new Doctrine_Relation_Nest($def);
} else {
$rel = new Doctrine_Relation_Association($def);
}
} else {
// simple foreign key relation
$def = $this->completeDefinition($def);
if (isset($def['localKey'])) {
$rel = new Doctrine_Relation_LocalKey($def);
} else {
$rel = new Doctrine_Relation_ForeignKey($def);
}
}
if (isset($rel)) {
// unset pending relation
unset($this->_pending[$alias]);
$this->_relations[$alias] = $rel;
return $rel;
}
$this->_loadRelation($alias);
}
if ($recursive) {
$this->getRelations();
return $this->getRelation($alias, false);
} else {
/*try {
throw new Doctrine_Table_Exception('Unknown relation alias ' . $alias);
} catch (Exception $e) {
echo $e->getTraceAsString();
echo "<br /><br />";
}*/
throw new Doctrine_Table_Exception('Unknown relation alias ' . $alias);
}
}
/**
* Loads a relation and puts it into the collection of loaded relations.
* In the process of initializing a relation it is common that multiple other, closely related
* relations are initialized, too.
*
* @param string $alias The name of the relation.
*/
protected function _loadRelation($alias)
{
$def = $this->_pending[$alias];
// check if reference class name exists
// if it does we are dealing with an association relation (many-many)
if (isset($def['refClass'])) {
$def = $this->completeAssocDefinition($def);
$localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getComponentName()));
// if the two many-many related components share the same table, we need
// custom relation names to distinguish the relations.
if ($this->_table->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE &&
in_array($def['class'], $this->_table->getOption('subclasses'))) {
if ( ! isset($def['refRelationName']) || ! isset($def['refReverseRelationName'])) {
throw new Doctrine_Relation_Exception("Incomplete relation. Many-to-many relations between "
. "classes that share the same table (single table inheritance) need to specify "
. "a 'refRelationName' and a 'refReverseRelationName' to distinguish relations.");
}
$relationName = $def['refRelationName'];
} else {
$relationName = $def['refClass'];
}
if ( ! isset($this->_pending[$relationName]) && ! isset($this->_relations[$relationName])) {
$this->_completeManyToManyRelation($def);
}
if (in_array($def['class'], $localClasses)) {
$rel = new Doctrine_Relation_Nest($def);
} else {
$rel = new Doctrine_Relation_Association($def);
}
} else {
// simple foreign key relation
$def = $this->completeDefinition($def);
if (isset($def['localKey'])) {
$rel = new Doctrine_Relation_LocalKey($def);
} else {
$rel = new Doctrine_Relation_ForeignKey($def);
}
}
if (isset($rel)) {
unset($this->_pending[$alias]);
$this->_relations[$alias] = $rel;
return $rel;
}
}
/**
* Completes the initialization of a many-to-many relation by adding
* two uni-directional relations between this parser's table and the intermediary table.
*
* @param array The relation definition.
*/
protected function _completeManyToManyRelation(array $def)
{
$identifierColumnNames = $this->_table->getIdentifierColumnNames();
$idColumnName = array_pop($identifierColumnNames);
// if the two many-many related components shared the same table, we need a relation name
// to distinguish the relations.
$relationName = $def['refClass'];
if (isset($def['refRelationName'])) {
$relationName .= ' as ' . $def['refRelationName'];
}
// add a relation pointing from the intermediary table to the table of this parser
$parser = $def['refTable']->getRelationParser();
if ( ! $parser->hasRelation($this->_table->getComponentName())) {
$parser->bind($this->_table->getComponentName(),
array('type' => Doctrine_Relation::ONE,
'local' => $def['local'],
'foreign' => $idColumnName,
'localKey' => true
)
);
}
// add a relation pointing from this parser's table to the xref table
if ( ! $this->hasRelation($relationName/*$def['refClass']*/)) {
$this->bind($relationName, array(
'type' => Doctrine_Relation::MANY,
'foreign' => $def['local'],
'local' => $idColumnName)
);
}
}
/**
* getRelations
@ -230,21 +269,23 @@ class Doctrine_Relation_Parser
*
* @param string $template
*/
public function getImpl($template)
public function getImpl(array &$def, $key)
{
$conn = $this->_table->getConnection();
if (in_array('Doctrine_Template', class_parents($template))) {
$impl = $this->_table->getImpl($template);
if (in_array('Doctrine_Template', class_parents($def[$key]))) {
$impl = $this->_table->getImpl($def[$key]);
if ($impl === null) {
throw new Doctrine_Relation_Parser_Exception("Couldn't find concrete implementation for template " . $template);
throw new Doctrine_Relation_Parser_Exception("Couldn't find concrete implementation for template " . $def[$key]);
}
} else {
$impl = $template;
$def[$key] = $impl;
}
return $conn->getTable($impl);
return $conn->getTable($def[$key]);
}
protected function _isTemplate($className)
{
return in_array('Doctrine_Template', class_parents($className));
}
/**
@ -256,10 +297,9 @@ class Doctrine_Relation_Parser
public function completeAssocDefinition($def)
{
$conn = $this->_table->getConnection();
$def['table'] = $this->getImpl($def['class']);
$def['table'] = $this->getImpl($def, 'class');
$def['localTable'] = $this->_table;
$def['class'] = $def['table']->getComponentName();
$def['refTable'] = $this->getImpl($def['refClass']);
$def['refTable'] = $this->getImpl($def, 'refClass');
$id = $def['refTable']->getIdentifierColumnNames();
@ -267,7 +307,6 @@ class Doctrine_Relation_Parser
if ( ! isset($def['foreign'])) {
// foreign key not set
// try to guess the foreign key
$def['foreign'] = ($def['local'] === $id[0]) ? $id[1] : $id[0];
}
if ( ! isset($def['local'])) {
@ -371,24 +410,23 @@ class Doctrine_Relation_Parser
public function completeDefinition($def)
{
$conn = $this->_table->getConnection();
$def['table'] = $this->getImpl($def['class']);
$def['table'] = $this->getImpl($def, 'class');
//$def['class'] = $def['table']->getComponentName();
$def['localTable'] = $this->_table;
$def['class'] = $def['table']->getComponentName();
$foreignClasses = array_merge($def['table']->getOption('parents'), array($def['class']));
$localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getComponentName()));
$localIdentifierColumnNames = $this->_table->getIdentifierColumnNames();
$localIdColumnName = array_pop($localIdentifierColumnNames);
$localIdColumnName = $localIdentifierColumnNames[count($localIdentifierColumnNames) - 1];
$foreignIdentifierColumnNames = $def['table']->getIdentifierColumnNames();
$foreignIdColumnName = array_pop($foreignIdentifierColumnNames);
$foreignIdColumnName = $foreignIdentifierColumnNames[count($foreignIdentifierColumnNames) - 1];
if (isset($def['local'])) {
if ( ! isset($def['foreign'])) {
// local key is set, but foreign key is not
// try to guess the foreign key
if ($def['local'] === $localIdColumnName) {
if ($def['local'] == $localIdColumnName) {
$def['foreign'] = $this->guessColumns($localClasses, $def['table']);
} else {
// the foreign field is likely to be the
@ -397,8 +435,8 @@ class Doctrine_Relation_Parser
$def['localKey'] = true;
}
} else {
if ($def['local'] !== $localIdColumnName &&
$def['type'] == Doctrine_Relation::ONE) {
if ((array)$def['local'] != $localIdentifierColumnNames &&
$def['type'] == Doctrine_Relation::ONE) {
$def['localKey'] = true;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,369 @@
<?php
/**
* A table factory is used to create table objects and load them with meta data.
*
* @todo Support different drivers for loading the meta data from different sources.
* @package Doctrine
*/
class Doctrine_Table_Factory
{
protected $_conn;
protected $_driver;
public function __construct(Doctrine_Connection $conn /*Doctrine_Table_Factory_Driver $driver*/)
{
$this->_conn = $conn;
//$this->_driver = $driver;
$name = "Doctrine_Table_Factory";
//call_user_func_array(array($name, 'foobar'), array());
}
/**
* Loads the metadata of the class in question and all it's ancestors whose metadata
* is still not loaded.
*
* @param string $name The name of the class for which the metadata should get loaded.
* @param array $tables The metadata collection to which the loaded metadata is added.
*/
public function loadTables($name, array &$tables)
{
$parentClass = $name;
$parentClasses = array();
$parentClassWithTable = false;
while ($parentClass = get_parent_class($parentClass)) {
if ($parentClass == 'Doctrine_Record') {
break;
}
if (isset($tables[$parentClass])) {
$parentClassWithTable = $parentClass;
break;
}
$class = new ReflectionClass($parentClass);
if ($class->isAbstract()) {
continue;
}
$parentClasses[] = $parentClass;
}
$parentClasses = array_reverse($parentClasses);
$parentClasses[] = $name;
if ($parentClassWithTable) {
$table = $tables[$parentClassWithTable];
} else {
$rootClassOfHierarchy = count($parentClasses) > 0 ? array_shift($parentClasses) : $name;
$table = new Doctrine_Table($rootClassOfHierarchy, $this->_conn);
$this->_loadMetaDataFromCode($table, $rootClassOfHierarchy);
$tables[$rootClassOfHierarchy] = $table;
}
if (count($parentClasses) == 0) {
return $table;
}
//var_dump($parentClasses);
//echo "<br /><br />";
// load meta data of subclasses
if ($table->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED) {
foreach ($parentClasses as $subclass) {
$subTable = new Doctrine_Table($subclass, $this->_conn);
$subTable->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED);
$this->_loadMetaDataFromCode($subTable, $subclass);
$tables[$subclass] = $subTable;
}
} else if ($table->getInheritanceType() == Doctrine::INHERITANCETYPE_SINGLE_TABLE) {
foreach ($parentClasses as $subclass) {
$this->_mergeInto($table, $subclass);
$tables[$subclass] = $table;
}
} else if ($table->getInheritanceType() == Doctrine::INHERITANCETYPE_TABLE_PER_CLASS) {
$parents = array();
foreach ($parentClasses as $subclass) {
$class = new ReflectionClass($subclass);
if ($class->isAbstract()) {
$parents[] = $subclass;
continue;
}
$subTable = new Doctrine_Table($subclass, $this->_conn);
$subTable->setInheritanceType(Doctrine::INHERITANCETYPE_TABLE_PER_CLASS);
$this->_loadMetaDataFromCode($subTable, $subclass);
$this->_mergeColumnsInto($table, $subTable, true);
foreach ($parents as $parent) {
$this->_mergeColumnsInto($this->_conn->getTable($parent), $subTable, true);
}
// currently relying on parent::setTableDefinition();
/*foreach ($abstracts as $abstractParent) {
Doctrine_Table_Factory::mergeInto($subTable, $abstractParent);
}*/
$tables[$subclass] = $subTable;
$parents[] = $subclass;
}
} else {
throw new Doctrine_Table_Factory_Exception("Failed to load meta data. Unknown inheritance type "
. "or no inheritance type specified for hierarchy.");
}
}
protected function _createTable($domainClassName)
{
return $this->_loadMetaDataFromCode($table, $domainClassName);
}
/**
* Initializes the in-memory metadata for the domain class this mapper belongs to.
* Uses reflection and code setup.
*/
protected function _loadMetaDataFromCode(Doctrine_Table $table, $name)
{
if ($name == 'Doctrine_Locator_Injectable') {
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br /><br />";
}
}
if ( ! class_exists($name) || empty($name)) {
//try {
throw new Doctrine_Exception("Couldn't find class " . $name);
//} catch (Exception $e) {
// echo $e->getTraceAsString() . "<br /><br />";
//}
}
$record = new $name($table);
$names = array();
$class = $name;
// get parent classes
do {
if ($class === 'Doctrine_Record') {
break;
}
$name = $class;
$names[] = $name;
} while ($class = get_parent_class($class));
if ($class === false) {
throw new Doctrine_Table_Exception('Unknown component.');
}
// reverse names
$names = array_reverse($names);
// save parents
array_pop($names);
$table->setOption('parents', $names);
/*echo "<br />";
var_dump($names);
echo "<br /><br />";*/
// set up metadata mapping
if (method_exists($record, 'setTableDefinition')) {
$record->setTableDefinition();
// get the declaring class of setTableDefinition method
$method = new ReflectionMethod($name, 'setTableDefinition');
$class = $method->getDeclaringClass();
} else {
$class = new ReflectionClass($class);
}
if ($table->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED) {
$joinedParents = array();
foreach (array_reverse($names) as $parent) {
$parentTable = $table->getConnection()->getTable($parent);
$parentColumns = $parentTable->getColumns();
$thisColumns = $table->getColumns();
foreach ($parentColumns as $columnName => $definition) {
if ( ! isset($definition['primary'])) {
if (isset($thisColumns[$columnName])) {
continue;
} else {
/*if ( ! isset($parentColumns[$columnName]['owner'])) {
$parentColumns[$columnName]['owner'] = $parentTable->getComponentName();
}
$joinedParents[] = $parentColumns[$columnName]['owner'];*/
$joinedParents[] = $parentTable->getComponentName();
}
} else {
unset($definition['autoincrement']);
$fullName = $columnName . ' as ' . $parentTable->getFieldName($columnName);
$table->setColumn($fullName, $definition['type'], $definition['length'], $definition, true);
}
}
}
$table->setOption('joinedParents', array_values(array_unique($joinedParents)));
}
$table->setOption('declaringClass', $class);
// set the table definition for the given tree implementation
if ($table->isTree()) {
$table->getTree()->setTableDefinition();
}
$table->setColumnCount(count($table->getColumns()));
$tableName = $table->getOption('tableName');
if ( ! isset($tableName)) {
$table->setOption('tableName', Doctrine::tableize($class->getName()));
}
$this->_initIdentifier($table);
// set up domain class relations
$record->setUp();
// if tree, set up tree relations
if ($table->isTree()) {
$table->getTree()->setUp();
}
return $table;
}
protected function _mergeInto(Doctrine_Table $table, $domainClassName)
{
if ( ! class_exists($domainClassName) || empty($domainClassName)) {
throw new Doctrine_Exception("Couldn't find class " . $domainClassName);
}
$record = new $domainClassName($table);
$record->setTableDefinition();
$record->setUp();
}
protected function _mergeColumnsInto(Doctrine_Table $sourceTable, Doctrine_Table $targetTable, $skipPk = false)
{
$sourceColumns = $sourceTable->getColumns();
foreach ($sourceColumns as $columnName => $definition) {
if ($skipPk && isset($definition['primary'])) {
continue;
}
$fullName = $columnName . ' as ' . $sourceTable->getFieldName($columnName);
$targetTable->setColumn($fullName, $definition['type'], $definition['length'], $definition);
}
}
protected function _mergeRelationsInto(Doctrine_Table $table, $domainClassName)
{
}
/**
* Initializes the table identifier(s)/primary key(s)
*
*/
protected function _initIdentifier(Doctrine_Table $table)
{
switch (count($table->getIdentifier())) {
case 0:
if ($table->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED &&
count($table->getOption('joinedParents')) > 0) {
$root = current($table->getOption('joinedParents'));
$rootTable = $table->getConnection()->getTable($root);
$table->setIdentifier($rootTable->getIdentifier());
if ($table->getIdentifierType() !== Doctrine::IDENTIFIER_AUTOINC) {
$table->setIdentifierType($rootTable->getIdentifierType());
} else {
$table->setIdentifierType(Doctrine::IDENTIFIER_NATURAL);
}
// add all inherited primary keys
foreach ((array) $table->getIdentifier() as $id) {
$definition = $rootTable->getDefinitionOf($id);
// inherited primary keys shouldn't contain autoinc
// and sequence definitions
unset($definition['autoincrement']);
unset($definition['sequence']);
// add the inherited primary key column
$fullName = $id . ' as ' . $rootTable->getFieldName($id);
$table->setColumn($fullName, $definition['type'], $definition['length'],
$definition, true);
}
} else {
$definition = array('type' => 'integer',
'length' => 20,
'autoincrement' => true,
'primary' => true);
$table->setColumn('id', $definition['type'], $definition['length'], $definition, true);
$table->setIdentifier('id');
$table->setIdentifierType(Doctrine::IDENTIFIER_AUTOINC);
}
$currentCount = $table->getColumnCount();
$table->setColumnCount(++$currentCount);
break;
case 1:
foreach ($table->getIdentifier() as $pk) {
$columnName = $table->getColumnName($pk);
$thisColumns = $table->getColumns();
$e = $thisColumns[$columnName];
$found = false;
foreach ($e as $option => $value) {
if ($found) {
break;
}
$e2 = explode(':', $option);
switch (strtolower($e2[0])) {
case 'autoincrement':
case 'autoinc':
$table->setIdentifierType(Doctrine::IDENTIFIER_AUTOINC);
$found = true;
break;
case 'seq':
case 'sequence':
$table->setIdentifierType(Doctrine::IDENTIFIER_SEQUENCE);
$found = true;
if ($value) {
$table->setOption('sequenceName', $value);
} else {
if (($sequence = $table->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) {
$table->setOption('sequenceName', $sequence);
} else {
$table->setOption('sequenceName', $table->getConnection()
->getSequenceName($this->getOption('tableName')));
}
}
break;
}
}
$identifierType = $table->getIdentifierType();
if ( ! isset($identifierType)) {
$table->setIdentifierType(Doctrine::IDENTIFIER_NATURAL);
}
}
$table->setIdentifier($pk);
break;
default:
$table->setIdentifierType(Doctrine::IDENTIFIER_COMPOSITE);
}
}
public static function foobar()
{
echo "bar!";
}
}

View File

@ -0,0 +1,3 @@
<?php
class Doctrine_Table_Factory_Exception extends Doctrine_Table_Exception {}

View File

@ -51,7 +51,7 @@ class Doctrine_Table_Repository implements Countable, IteratorAggregate
*
* @param Doctrine_Table $table
*/
public function __construct(Doctrine_Table $table)
public function __construct(Doctrine_Mapper $table)
{
$this->table = $table;
}
@ -126,7 +126,7 @@ class Doctrine_Table_Repository implements Countable, IteratorAggregate
public function evictAll()
{
$evicted = 0;
foreach ($this->registry as $oid=>$record) {
foreach ($this->registry as $oid => $record) {
if ($this->evict($oid)) {
$evicted++;
}

View File

@ -159,6 +159,17 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
{
return $this->_nestingLevel;
}
/**
* getInternalTransactionLevel
* get the current internal transaction nesting level
*
* @return integer
*/
public function getInternalTransactionLevel()
{
return $this->_internalNestingLevel;
}
/**
* beginTransaction
@ -315,6 +326,11 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
public function rollback($savepoint = null)
{
if ($this->_nestingLevel == 0) {
/*try {
throw new Doctrine_Transaction_Exception("Rollback failed. There is no active transaction.");
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br />";
}*/
throw new Doctrine_Transaction_Exception("Rollback failed. There is no active transaction.");
}

View File

@ -7,6 +7,6 @@ class FooForeignlyOwnedWithPk extends Doctrine_Record
}
public function setUp()
{
$this->hasOne('FooRecord', array('local' => 'id', 'foreign' => 'id'));
//$this->hasOne('FooRecord', array('local' => 'id', 'foreign' => 'id'));
}
}

View File

@ -31,7 +31,7 @@ class FooRecord extends Doctrine_Record
$this->hasMany('FooRecord as Children', array('local' => 'id', 'foreign' => 'parent_id'));
$this->hasOne('FooRecord as Parent', array('local' => 'parent_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
$this->hasOne('FooForeignlyOwnedWithPk', array('local' => 'id', 'foreign' => 'id', 'constraint' => true));
//$this->hasOne('FooForeignlyOwnedWithPk', array('local' => 'id', 'foreign' => 'id', 'constraint' => true));
$this->hasOne('FooLocallyOwned', array('local' => 'local_foo', 'onDelete' => 'RESTRICT'));
$this->hasMany('BarRecord as Bar', array('local' => 'fooId',

View File

@ -15,7 +15,12 @@ class Group extends Entity
'local' => 'group_id',
'foreign' => 'user_id',
'refClass' => 'Groupuser',
'refRelationName' => 'GroupGroupuser',
'refReverseRelationName' => 'UserGroupuser'
));
/*$this->hasMany('Groupuser as User', array(
'local' => 'id', 'foreign' => 'group_id'
));*/
}
}

View File

@ -4,8 +4,8 @@ class Groupuser extends Doctrine_Record
public function setTableDefinition()
{
$this->hasColumn('added', 'integer');
$this->hasColumn('group_id', 'integer');
$this->hasColumn('user_id', 'integer');
$this->hasColumn('group_id', 'integer', null /*,array('primary' => true)*/);
$this->hasColumn('user_id', 'integer', null /*,array('primary' => true)*/);
}
public function setUp()

View File

@ -3,6 +3,9 @@ class InheritanceEntityUser extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE,
array('InheritanceDealUser' => array('type' => 1)));
$this->setTableName('inheritance_entity_user');
$this->hasColumn('type', 'integer', 4, array ( 'primary' => true,));
@ -19,10 +22,6 @@ class InheritanceDealUser extends InheritanceEntityUser
{
public function setTableDefinition()
{
parent::setTableDefinition();
$this->setTableName('inheritance_entity_user');
$this->hasColumn('user_id', 'integer', 4, array ( 'primary' => true,));
$this->hasColumn('entity_id', 'integer', 4, array ( 'primary' => true,));
}
@ -33,8 +32,5 @@ class InheritanceDealUser extends InheritanceEntityUser
$this->hasOne('InheritanceUser as User', array('local' => 'user_id', 'foreign' => 'id'));
$this->hasOne('InheritanceDeal as Deal', array('local' => 'entity_id', 'foreign' => 'id'));
$this->setInheritanceMap(array (
'type' => 1,
));
}
}

View File

@ -27,7 +27,13 @@ class User extends Entity
'local' => 'user_id',
'foreign' => 'group_id',
'refClass' => 'Groupuser',
'refRelationName' => 'UserGroupuser',
'refReverseRelationName' => 'GroupGroupuser'
));
/*$this->hasMany('Groupuser as Group', array(
'local' => 'id', 'foreign' => 'user_id'
));*/
}
/** Custom validation */

View File

@ -77,7 +77,7 @@ class Doctrine_Access_TestCase extends Doctrine_UnitTestCase
$user->save();
$user = $this->connection->getTable('User')->find($user->identifier());
$user = $this->connection->getMapper('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->getTable('User')->find($user->identifier());
$user = $this->connection->getMapper('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->getTable('User')->find($user->identifier());
$user = $this->connection->getMapper('User')->find($user->identifier());
$this->assertEqual($user->get('name'), 'Jack');

View File

@ -43,7 +43,8 @@ class Doctrine_ClassTableInheritance_TestCase extends Doctrine_UnitTestCase
$table = $class->getTable();
$this->assertEqual($table->getOption('joinedParents'), array('CTITestParent2', 'CTITestParent3'));
$this->assertEqual($table->getOption('joinedParents'),
array('CTITestParent4', 'CTITestParent3', 'CTITestParent2', 'CTITestParent1'));
}
public function testExportGeneratesAllInheritedTables()
@ -93,7 +94,8 @@ class Doctrine_ClassTableInheritance_TestCase extends Doctrine_UnitTestCase
$record->save();
// pop the commit event
$profiler->pop();
$p = $profiler->pop();
var_dump($p->getQuery());
$this->assertEqual($profiler->pop()->getQuery(), 'INSERT INTO c_t_i_test_parent4 (age, id) VALUES (?, ?)');
// pop the prepare event
$profiler->pop();
@ -166,7 +168,7 @@ class Doctrine_ClassTableInheritance_TestCase extends Doctrine_UnitTestCase
$profiler = new Doctrine_Connection_Profiler();
$this->conn->addListener($profiler);
$record = $this->conn->getTable('CTITest')->find(1);
$record = $this->conn->getMapper('CTITest')->find(1);
$record->age = 11;
$record->name = 'Jack';
@ -191,7 +193,7 @@ class Doctrine_ClassTableInheritance_TestCase extends Doctrine_UnitTestCase
{
$this->conn->clear();
$record = $this->conn->getTable('CTITest')->find(1);
$record = $this->conn->getMapper('CTITest')->find(1);
$this->assertEqual($record->id, 1);
$this->assertEqual($record->name, 'Jack');
@ -207,7 +209,7 @@ class Doctrine_ClassTableInheritance_TestCase extends Doctrine_UnitTestCase
$profiler = new Doctrine_Connection_Profiler();
$this->conn->addListener($profiler);
$record = $this->conn->getTable('CTITest')->find(1);
$record = $this->conn->getMapper('CTITest')->find(1);
$record->delete();
@ -223,12 +225,14 @@ class Doctrine_ClassTableInheritance_TestCase extends Doctrine_UnitTestCase
$this->conn->addListener(new Doctrine_EventListener());
}
}
abstract class CTIAbstractBase extends Doctrine_Record
{ }
class CTITestParent1 extends CTIAbstractBase
class CTITestParent1 extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED, array(
'CTITestParent1' => 1, 'CTITestParent2' => 2,
'CTITestParent3' => 3, 'CTITestParent4' => 4,
'CTITest' => 5));
$this->hasColumn('name', 'string', 200);
}
}
@ -236,8 +240,6 @@ class CTITestParent2 extends CTITestParent1
{
public function setTableDefinition()
{
parent::setTableDefinition();
$this->hasColumn('verified', 'boolean', 1);
}
}
@ -257,7 +259,10 @@ class CTITestParent4 extends CTITestParent3
}
class CTITest extends CTITestParent4
{
public function setTableDefinition()
{
$this->hasColumn('age2', 'integer', 4);
}
}
class CTITestOneToManyRelated extends Doctrine_Record

View File

@ -167,10 +167,6 @@ class Doctrine_Connection_TestCase extends Doctrine_UnitTestCase
$f = true;
}
$this->assertTrue($f);
$table = $this->connection->getTable('User');
$this->assertTrue($table instanceof UserTable);
}
public function testCreate()

View File

@ -53,7 +53,7 @@ class Doctrine_CustomPrimaryKey_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($c->identifier(), array('uid' => 1));
$this->connection->clear();
$c = $this->connection->getTable('CustomPK')->find(1);
$c = $this->connection->getMapper('CustomPK')->find(1);
$this->assertEqual($c->identifier(), array('uid' => 1));
}

View File

@ -60,7 +60,7 @@ class Doctrine_DataType_Boolean_TestCase extends Doctrine_UnitTestCase {
$this->connection->clear();
$test = $test->getTable()->find($test->id);
$test = $test->getMapper()->find($test->id);
$this->assertIdentical($test->is_working, true);
}
public function testNormalQuerying() {

View File

@ -151,7 +151,7 @@ class Doctrine_DataType_Enum_TestCase extends Doctrine_UnitTestCase
public function testFailingRefresh()
{
$enum = $this->connection->getTable('EnumTest')->find(1);
$enum = $this->connection->getMapper('EnumTest')->find(1);
$this->conn->exec('DELETE FROM enum_test WHERE id = 1');

View File

@ -195,11 +195,11 @@ class Doctrine_UnitTestCase extends UnitTestCase
}
}
$this->conn->export->exportClasses($this->tables);
$this->objTable = $this->connection->getTable('User');
$this->objTable = $this->connection->getMapper('User');
}
public function prepareData()
{
$groups = new Doctrine_Collection($this->connection->getTable('Group'));
$groups = new Doctrine_Collection('Group');
$groups[0]->name = 'Drama Actors';

View File

@ -22,7 +22,9 @@ class UnitTestCase
if(is_array($value2)){
$value2 = var_export($value2, true);
}
$message = "$seperator Value1: $value $seperator != $seperator Value2: $value2 $seperator";
$this->_fail($message);
}
}

View File

@ -100,8 +100,12 @@ class Doctrine_Export_Record_TestCase extends Doctrine_UnitTestCase
Doctrine::createTablesFromModels(dirname(__FILE__) . DIRECTORY_SEPARATOR .'..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'export');
$this->assertEqual($this->adapter->pop(), 'COMMIT');
$this->assertEqual($this->adapter->pop(), 'ALTER TABLE cms__category_languages ADD FOREIGN KEY (category_id) REFERENCES cms__category(id) ON DELETE CASCADE');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category_languages (id BIGINT AUTO_INCREMENT, name TEXT, category_id BIGINT, language_id BIGINT, INDEX index_category_idx (category_id), INDEX index_language_idx (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category (id BIGINT AUTO_INCREMENT, created DATETIME, parent BIGINT, position MEDIUMINT, active BIGINT, INDEX index_parent_idx (parent), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
$createTableSql = array(
'CREATE TABLE cms__category_languages (id BIGINT AUTO_INCREMENT, name TEXT, category_id BIGINT, language_id BIGINT, INDEX index_category_idx (category_id), INDEX index_language_idx (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB',
'CREATE TABLE cms__category (id BIGINT AUTO_INCREMENT, created DATETIME, parent BIGINT, position MEDIUMINT, active BIGINT, INDEX index_parent_idx (parent), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB'
);
$this->assertTrue(in_array($this->adapter->pop(), $createTableSql));
$this->assertTrue(in_array($this->adapter->pop(), $createTableSql));
$this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');
}

View File

@ -120,7 +120,6 @@ class Doctrine_Hydrate_FetchMode_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Query();
$q->select('u.*, p.*')->from('User u')->innerJoin('u.Phonenumber p');
$count = count($this->conn);
$users = $q->execute(array(), Doctrine::FETCH_RECORD);
$this->assertEqual(count($users), 8);
@ -128,8 +127,6 @@ class Doctrine_Hydrate_FetchMode_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($users[0]->state(), Doctrine_Record::STATE_CLEAN);
$this->assertTrue($users instanceof Doctrine_Collection);
$this->assertTrue($users[0]->Phonenumber instanceof Doctrine_Collection);
$this->assertEqual(count($this->conn), $count + 1);
}
public function testFetchRecordSupportsSimpleFetching()

View File

@ -0,0 +1,189 @@
<?php
class Doctrine_Inheritance_Joined_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{ }
public function prepareTables()
{
$this->tables[] = 'CTI_User';
$this->tables[] = 'CTI_Manager';
$this->tables[] = 'CTI_Customer';
$this->tables[] = 'CTI_SuperManager';
parent::prepareTables();
}
public function setUp()
{
parent::setUp();
$this->prepareTables();
}
public function testMetadataSetup()
{
$suManagerTable = $this->conn->getTable('CTI_SuperManager');
$userTable = $this->conn->getTable('CTI_User');
$customerTable = $this->conn->getTable('CTI_Customer');
$managerTable = $this->conn->getTable('CTI_Manager');
$this->assertTrue($suManagerTable !== $userTable);
$this->assertTrue($suManagerTable !== $customerTable);
$this->assertTrue($userTable !== $customerTable);
$this->assertTrue($managerTable !== $suManagerTable);
// expected column counts
$this->assertEqual(2, count($suManagerTable->getColumns()));
$this->assertEqual(4, count($userTable->getColumns()));
$this->assertEqual(2, count($managerTable->getColumns()));
$this->assertEqual(2, count($customerTable->getColumns()));
// expected table names
$this->assertEqual('cti_user', $userTable->getTableName());
$this->assertEqual('cti_manager', $managerTable->getTableName());
$this->assertEqual('cti_customer', $customerTable->getTableName());
$this->assertEqual('cti_supermanager', $suManagerTable->getTableName());
// expected joined parents option
$this->assertEqual(array(), $userTable->getOption('joinedParents'));
$this->assertEqual(array('CTI_User'), $managerTable->getOption('joinedParents'));
$this->assertEqual(array('CTI_User'), $customerTable->getOption('joinedParents'));
$this->assertEqual(array('CTI_Manager', 'CTI_User'), $suManagerTable->getOption('joinedParents'));
// check inheritance map
$this->assertEqual(array(
'CTI_User' => array('type' => 1),
'CTI_Manager' => array('type' => 2),
'CTI_Customer' => array('type' => 3),
'CTI_SuperManager' => array('type' => 4)), $userTable->getOption('inheritanceMap'));
//$this->assertEqual(array('CTI_User', 'CTI_Manager', ''))
}
protected function _createManager()
{
$manager = new CTI_Manager();
$manager->salary = 80000;
$manager->name = 'John Smith';
try {
$manager->save();
$this->pass();
return $manager;
} catch (Exception $e) {
$this->fail("Inserting record in class table inheritance failed: " . $e->getMessage());
}
}
protected function _createSuperManager()
{
$manager = new CTI_SuperManager();
$manager->salary = 1000000;
$manager->name = 'Bill Gates';
$manager->gosutitle = 'BillyBoy';
try {
$manager->save();
$this->pass();
return $manager;
} catch (Exception $e) {
$this->fail("Inserting record in class table inheritance failed: " . $e->getMessage());
}
}
public function testSaveInsertsDataAcrossJoinedTablesTransparently()
{
$manager = $this->_createManager();
$this->assertEqual(1, $manager->id);
$this->assertEqual(80000, $manager->salary);
$this->assertEqual('John Smith', $manager->name);
$this->assertEqual(2, $manager->type);
$superManager = $this->_createSuperManager();
$this->assertEqual(2, $superManager->id);
$this->assertEqual(1000000, $superManager->salary);
$this->assertEqual('Bill Gates', $superManager->name);
$this->assertEqual('BillyBoy', $superManager->gosutitle);
$this->assertEqual(4, $superManager->type);
}
public function testUpdateUpdatesDataAcrossJoinedTablesTransparently()
{
$manager = $this->_createManager();
$manager->salary = 90000; // he got a pay rise...
$manager->name = 'John Locke'; // he got married ...
try {
$manager->save();
$this->pass();
} catch (Exception $e) {
$this->fail("Updating record in class table inheritance failed: " . $e->getMessage());
}
$this->assertEqual(1, $manager->id);
$this->assertEqual(90000, $manager->salary);
$this->assertEqual('John Locke', $manager->name);
$this->assertEqual(2, $manager->type);
$superManager = $this->_createSuperManager();
$superManager->salary = 0; // he got fired...
$superManager->name = 'Bill Clinton'; // he got married ... again
$superManager->gosutitle = 'Billy the Kid'; // ... and went mad
try {
$superManager->save();
$this->pass();
} catch (Exception $e) {
$this->fail("Updating record in class table inheritance failed: " . $e->getMessage());
}
$this->assertEqual(2, $superManager->id);
$this->assertEqual(0, $superManager->salary);
$this->assertEqual('Bill Clinton', $superManager->name);
$this->assertEqual('Billy the Kid', $superManager->gosutitle);
$this->assertEqual(4, $superManager->type);
}
}
class CTI_User extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED,
array('CTI_User' => array('type' => 1),
'CTI_Manager' => array('type' => 2),
'CTI_Customer' => array('type' => 3),
'CTI_SuperManager' => array('type' => 4))
);
$this->setTableName('cti_user');
$this->hasColumn('cti_id as id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
$this->hasColumn('cti_foo as foo', 'integer', 4);
$this->hasColumn('cti_name as name', 'string', 50);
$this->hasColumn('type', 'integer', 4);
}
}
class CTI_Manager extends CTI_User
{
public function setTableDefinition()
{
$this->setTableName('cti_manager');
$this->hasColumn('ctim_salary as salary', 'varchar', 50, array());
}
}
class CTI_Customer extends CTI_User
{
public function setTableDefinition()
{
$this->setTableName('cti_customer');
$this->hasColumn('ctic_bonuspoints as bonuspoints', 'varchar', 50, array());
}
}
class CTI_SuperManager extends CTI_Manager
{
public function setTableDefinition()
{
$this->setTableName('cti_supermanager');
$this->hasColumn('ctism_gosutitle as gosutitle', 'varchar', 50, array());
}
}

View File

@ -0,0 +1,104 @@
<?php
class Doctrine_Inheritance_SingleTable_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{ }
public function prepareTables()
{
$this->tables[] = 'STI_User';
$this->tables[] = 'STI_Manager';
$this->tables[] = 'STI_Customer';
$this->tables[] = 'STI_SuperManager';
parent::prepareTables();
}
public function testMetadataSetup()
{
$userTable = $this->conn->getTable('STI_User');
$superManagerTable = $this->conn->getTable('STI_SuperManager');
$managerTable = $this->conn->getTable('STI_Manager');
$customerTable = $this->conn->getTable('STI_Customer');
$this->assertTrue($superManagerTable === $userTable);
$this->assertTrue($customerTable === $managerTable);
$this->assertTrue($superManagerTable === $managerTable);
$this->assertTrue($userTable === $customerTable);
$this->assertEqual(7, count($userTable->getColumns()));
$this->assertEqual(array(), $userTable->getOption('joinedParents'));
$this->assertEqual(array(), $superManagerTable->getOption('joinedParents'));
$this->assertEqual(array(), $managerTable->getOption('joinedParents'));
$this->assertEqual(array(), $customerTable->getOption('joinedParents'));
// check inheritance map
$this->assertEqual(array(
'STI_User' => array('type' => 1),
'STI_Manager' => array('type' => 2),
'STI_Customer' => array('type' => 3),
'STI_SuperManager' => array('type' => 4)), $userTable->getOption('inheritanceMap'));
//var_dump($superManagerTable->getComponentName());
}
public function testSave()
{
$manager = new STI_Manager();
$manager->salary = 80000;
$manager->name = 'John Smith';
try {
$manager->save();
$this->assertEqual(1, $manager->id);
$this->assertEqual(80000, $manager->salary);
$this->assertEqual('John Smith', $manager->name);
$this->assertEqual(2, $manager->type);
} catch (Exception $e) {
$this->fail("Saving record in single table inheritance failed: " . $e->getMessage());
}
}
}
class STI_User extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setInheritanceType(Doctrine::INHERITANCETYPE_SINGLE_TABLE,
array('STI_User' => array('type' => 1),
'STI_Manager' => array('type' => 2),
'STI_Customer' => array('type' => 3),
'STI_SuperManager' => array('type' => 4))
);
$this->setTableName('sti_entity');
$this->hasColumn('sti_id as id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
$this->hasColumn('sti_foo as foo', 'integer', 4);
$this->hasColumn('sti_name as name', 'varchar', 50);
$this->hasColumn('type', 'integer', 4);
}
}
class STI_Manager extends STI_User
{
public function setTableDefinition()
{
$this->hasColumn('stim_salary as salary', 'varchar', 50, array());
}
}
class STI_Customer extends STI_User
{
public function setTableDefinition()
{
$this->hasColumn('stic_bonuspoints as bonuspoints', 'varchar', 50, array());
}
}
class STI_SuperManager extends STI_Manager
{
public function setTableDefinition()
{
$this->hasColumn('stism_gosutitle as gosutitle', 'varchar', 50, array());
}
}

View File

@ -0,0 +1,110 @@
<?php
/**
* Concrete Table Inheritance mapping tests.
*/
class Doctrine_Inheritance_TablePerClass_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{ }
public function setUp()
{
parent::setUp();
$this->prepareTables();
}
public function prepareTables()
{
$this->tables[] = 'CCTI_User';
$this->tables[] = 'CCTI_Manager';
$this->tables[] = 'CCTI_Customer';
$this->tables[] = 'CCTI_SuperManager';
parent::prepareTables();
}
public function testMetadataTableSetup()
{
$supMngrTable = $this->conn->getTable('CCTI_SuperManager');
$usrTable = $this->conn->getTable('CCTI_User');
$mngrTable = $this->conn->getTable('CCTI_Manager');
$customerTable = $this->conn->getTable('CCTI_Customer');
$this->assertTrue($supMngrTable !== $usrTable);
$this->assertTrue($supMngrTable !== $mngrTable);
$this->assertTrue($usrTable !== $mngrTable);
$this->assertTrue($customerTable !== $usrTable);
$this->assertEqual(3, count($usrTable->getColumns()));
$this->assertEqual(4, count($mngrTable->getColumns()));
$this->assertEqual(4, count($customerTable->getColumns()));
$this->assertEqual(5, count($supMngrTable->getColumns()));
$this->assertEqual('ccti_user', $usrTable->getTableName());
$this->assertEqual('ccti_manager', $mngrTable->getTableName());
$this->assertEqual('ccti_customer', $customerTable->getTableName());
$this->assertEqual('ccti_supermanager', $supMngrTable->getTableName());
//var_dump($mngrTable->getColumns());
}
public function testSave()
{
$manager = new CCTI_Manager();
$manager->salary = 80000;
$manager->name = 'John Smith';
try {
$manager->save();
$this->assertEqual(1, $manager->id);
$this->assertEqual(80000, $manager->salary);
$this->assertEqual('John Smith', $manager->name);
} catch (Exception $e) {
$this->fail("Saving record in concrete table inheritance failed: " . $e->getMessage());
}
}
public function testQuery()
{
//$manager = $this->conn->query("FROM CCTI_Manager")->getFirst();
//var_dump($manager);
}
}
class CCTI_User extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setInheritanceType(Doctrine::INHERITANCETYPE_TABLE_PER_CLASS);
$this->setTableName('ccti_user');
$this->hasColumn('ccti_id as id', 'integer', 4, array ('primary' => true, 'autoincrement' => true));
$this->hasColumn('ccti_foo as foo', 'integer', 4);
$this->hasColumn('ccti_name as name', 'varchar', 50, array ());
}
}
class CCTI_Manager extends CCTI_User
{
public function setTableDefinition()
{
$this->setTableName('ccti_manager');
$this->hasColumn('ccti_salary as salary', 'varchar', 50, array());
}
}
class CCTI_Customer extends CCTI_User
{
public function setTableDefinition()
{
$this->setTableName('ccti_customer');
$this->hasColumn('ccti_bonuspoints as bonuspoints', 'varchar', 50, array());
}
}
class CCTI_SuperManager extends CCTI_Manager
{
public function setTableDefinition()
{
$this->setTableName('ccti_supermanager');
$this->hasColumn('ccti_gosutitle as gosutitle', 'varchar', 50, array());
}
}

View File

@ -47,11 +47,11 @@ class Doctrine_Query_ApplyInheritance_TestCase extends Doctrine_UnitTestCase
public function testApplyInheritance()
{
$query = new Doctrine_Query();
$query->from('InheritanceDeal d, d.Users u');
$query->where('u.id = 1');
$query->from('InheritanceDeal deal, deal.Users usrs');
$query->where('usrs.id = 1');
$sql = 'SELECT i.id AS i__id, i.name AS i__name, i2.id AS i2__id, i2.username AS i2__username FROM inheritance_deal i LEFT JOIN inheritance_entity_user i3 ON i.id = i3.entity_id LEFT JOIN inheritance_user i2 ON i2.id = i3.user_id WHERE i2.id = 1 AND (i3.type = 1 OR i3.type IS NULL)';
$this->assertEqual($sql, $query->getSql());
}
}

View File

@ -269,7 +269,7 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase
}
public function testLimitWithNormalManyToMany()
{
$coll = new Doctrine_Collection($this->connection->getTable("Photo"));
$coll = new Doctrine_Collection('Photo');
$tag = new Tag();
$tag->tag = "Some tag";
$coll[0]->Tag[0] = $tag;

View File

@ -43,7 +43,7 @@ class Doctrine_Query_MultiJoin_TestCase extends Doctrine_UnitTestCase
$query = new Doctrine_Query($this->connection);
$user = $this->connection->getTable('User')->find(4);
$user = $this->connection->getMapper('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->getTable('User')->find(5);
$user = $this->connection->getMapper('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->getTable('User')->find(4);
$user = $this->connection->getMapper('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->getTable('User')->find(5);
$user = $this->connection->getMapper('User')->find(5);
$user->Book[0]->name = 'Zadig';
$user->Book[0]->Author[0]->name = 'Voltaire';
$user->Book[0]->Author[1]->name = 'Someone';

View File

@ -60,7 +60,7 @@ class Doctrine_Query_ReferenceModel_TestCase extends Doctrine_UnitTestCase {
$this->connection->flush();
$this->connection->clear();
$category = $category->getTable()->find($category->id);
$category = $category->getMapper()->find($category->id);
$this->assertEqual($category->name, 'Root');
$this->assertEqual($category->Subcategory[0]->name, 'Sub 1');

View File

@ -62,6 +62,6 @@ class Doctrine_Query_Registry_TestCase extends Doctrine_UnitTestCase
$user = new User();
$user->getTable()->execute('all');
$user->getMapper()->execute('all');
}
}

View File

@ -71,8 +71,9 @@ class Doctrine_Record_SerializeUnserialize_TestCase extends Doctrine_UnitTestCas
$this->assertIdentical($object_before->floattest, $object_after->floattest);
$this->assertIdentical($object_before->stringtest, $object_after->stringtest);
$this->assertIdentical($object_before->arraytest, $object_after->arraytest);
$this->assertIdentical($object_before->enumtest, $object_after->enumtest);
$this->assertEqual($object_before->objecttest, $object_after->objecttest);
//$this->assertEqual($object_before->objecttest, $object_after->objecttest);
$this->assertIdentical($object_before->blobtest, $object_after->blobtest);
$this->assertIdentical($object_before->clobtest, $object_after->clobtest);
$this->assertIdentical($object_before->gziptest, $object_after->gziptest);

View File

@ -77,18 +77,19 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$user->name = 'John Rambo';
$account = $user->Account;
$account->amount = 2000;
$this->assertEqual($account->getTable()->getColumnNames(), array('id', 'entity_id', 'amount'));
$this->connection->flush();
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
$this->assertTrue($account instanceof Account);
$this->assertEqual($account->getTable()->getColumnNames(), array('id', 'entity_id', 'amount'));
$this->assertEqual($account->entity_id, $user->id);
$this->assertEqual($account->amount, 2000);
$user = $user->getTable()->find($user->id);
$user = $user->getMapper()->find($user->id);
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
@ -125,9 +126,10 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$null->type = 1;
try {
$this->connection->beginTransaction();
$null->save();
$this->fail();
} catch(Exception $e) {
} catch (Exception $e) {
$this->pass();
$this->connection->rollback();
}
@ -146,7 +148,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($gzip->gzip, "compressed");
$this->connection->clear();
$gzip = $gzip->getTable()->find($gzip->id);
$gzip = $gzip->getMapper()->find($gzip->id);
$this->assertEqual($gzip->gzip, "compressed");
$gzip->gzip = "compressed 2";
@ -207,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->getTable()->find($user->id);
$user = $user->getMapper()->find($user->id);
$a = $user->toArray();
@ -229,7 +231,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
public function testUpdatingWithNullValue()
{
$user = $this->connection->getTable('User')->find(5);
$user = $this->connection->getMapper('User')->find(5);
$user->name = null;
$this->assertEqual($user->name, null);
@ -239,7 +241,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->connection->clear();
$user = $this->connection->getTable('User')->find(5);
$user = $this->connection->getMapper('User')->find(5);
$this->assertEqual($user->name, null);
@ -247,7 +249,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
public function testSerialize()
{
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
$str = serialize($user);
$user2 = unserialize($str);
@ -285,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->getTable()->find($record->identifier());
$record = $record->getMapper()->find($record->identifier());
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($record->entity2, 4);
$this->assertEqual($record->entity1, 3);
@ -304,7 +306,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($record->entity2, 5);
$this->assertEqual($record->entity1, 2);
$this->assertEqual($record->identifier(), array("entity1" => 2, "entity2" => 5));
$record = $record->getTable()->find($record->identifier());
$record = $record->getMapper()->find($record->identifier());
$this->assertEqual($record->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($record->entity2, 5);
@ -366,7 +368,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->connection->flush();
$task = $task->getTable()->find($task->identifier());
$task = $task->getMapper()->find($task->identifier());
$this->assertEqual($task->name, "Task 1");
$this->assertEqual($task->ResourceAlias[0]->name, "Resource 1");
@ -375,7 +377,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
}
public function testGet()
{
$user = new User();
@ -385,19 +387,19 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($user->updated, null);
$user->save();
$id = $user->identifier();
$user = $user->getTable()->find($id);
$user = $user->getMapper()->find($id);
$this->assertEqual($user->name, "Jack Daniels");
$this->assertEqual($user->created, null);
$this->assertEqual($user->updated, null);
$this->assertEqual($user->getTable()->getData(), array());
$this->assertEqual($user->getMapper()->getData(), array());
}
public function testNewOperator()
{
$table = $this->connection->getTable("User");
$this->assertEqual($this->connection->getTable("User")->getData(), array());
$this->assertEqual($this->connection->getMapper("User")->getData(), array());
$user = new User();
$this->assertEqual(Doctrine_Lib::getRecordStateAsString($user->state()), Doctrine_Lib::getRecordStateAsString(Doctrine_Record::STATE_TCLEAN));
$user->name = "John Locke";
@ -408,7 +410,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertTrue($user->state() == Doctrine_Record::STATE_CLEAN);
$this->assertTrue($user->name,"John Locke");
}
public function testTreeStructure()
{
$e = new Element();
@ -441,12 +443,12 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$elements = $this->connection->query("FROM Element");
$this->assertEqual($elements->count(), 5);
$e = $e->getTable()->find(1);
$e = $e->getMapper()->find(1);
$this->assertEqual($e->name,"parent");
$this->assertEqual($e->Child[0]->name,"child 1");
$c = $e->getTable()->find(2);
$c = $e->getMapper()->find(2);
$this->assertEqual($c->name, "child 1");
$this->assertEqual($e->Child[0]->parent_id, 1);
@ -555,7 +557,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
public function testUpdate()
{
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
$user->set("name","Jack Daniels",true);
@ -568,7 +570,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
public function testCopy()
{
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
$new = $user->copy();
$this->assertTrue($new instanceof Doctrine_Record);
@ -585,7 +587,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
public function testCopyAndModify()
{
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
$new = $user->copy();
$this->assertTrue($new instanceof Doctrine_Record);
@ -606,7 +608,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
public function testReferences()
{
$user = $this->connection->getTable('User')->find(5);
$user = $this->connection->getMapper('User')->find(5);
$this->assertTrue($user->Phonenumber instanceof Doctrine_Collection);
$this->assertEqual($user->Phonenumber->count(), 3);
@ -617,10 +619,10 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($user->Phonenumber->count(), 0);
$user->save();
$user->getTable()->clear();
$user->getMapper()->clear();
$user = $this->objTable->find(5);
$this->assertEqual($user->Phonenumber->count(), 0);
$this->assertEqual(get_class($user->Phonenumber), 'Doctrine_Collection');
@ -737,19 +739,42 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
public function testSaveAssociations()
{
$user = $this->objTable->find(5);
$gf = $this->connection->getTable("Group");
{
$userMapper = $this->connection->getMapper('User');
$user = $userMapper->find(5);
$this->assertTrue($userMapper === $user->getMapper());
$this->assertTrue($userMapper->getTable() === $user->getMapper()->getTable());
$this->assertTrue($userMapper->getTable() === $this->conn->getTable('User'));
$this->assertTrue($this->conn === $userMapper->getConnection());
$userTable = $userMapper->getTable();
$rel1 = $userTable->getRelation('GroupGroupuser');
$rel2 = $userTable->getRelation('UserGroupuser');
/*echo get_class($rel1) . "<br />";
echo get_class($rel2) . "<br />";
echo get_class($userTable->getRelation('Group'));
echo "........<br />";
echo "local:" . $rel1->getLocal() . "---foreign:" . $rel1->getForeign() . "<br />";
echo "local:" . $rel2->getLocal() . "---foreign:" . $rel2->getForeign() . "<br />";
echo "........<br />";*/
$gf = $this->connection->getMapper("Group");
//echo "start";
$this->assertTrue($user->Group instanceof Doctrine_Collection);
//echo "end";
/*$xrefMapper = $this->connection->getMapper('Groupuser');
$xrefs = $xrefMapper->findAll();
foreach ($xrefs as $xref) {
echo $xref->group_id . " -- ". $xref->user_id ."(state:".$xref->state().")<br />";
}*/
$this->assertEqual($user->Group->count(), 1);
$this->assertEqual($user->Group[0]->id, 3);
// ADDING ASSOCIATED REFERENCES
$group1 = $gf->find(1);
$group2 = $gf->find(2);
$user->Group[1] = $group1;
@ -758,19 +783,33 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($user->Group->count(), 3);
$user->save();
/*$xrefMapper = $this->connection->getMapper('Groupuser');
$xrefs = $xrefMapper->findAll();
foreach ($xrefs as $xref) {
echo $xref->group_id . " -- ". $xref->user_id ."(state:".$xref->state().")<br />";
}*/
$coll = $user->Group;
// UNSETTING ASSOCIATED REFERENCES
unset($user);
$query = new Doctrine_Query($this->conn);
$user = $this->objTable->find(5);
//echo get_class($user->Group);
$this->assertEqual($user->Group->count(), 3);
$this->assertEqual($user->Group[1]->id, 2);
$this->assertEqual($user->Group[2]->id, 3);
$pks = $user->Group->getPrimaryKeys();
$this->assertTrue(in_array(1, $pks));
$this->assertTrue(in_array(2, $pks));
$this->assertTrue(in_array(3, $pks));
$user->unlink('Group', array($group1->id, $group2->id));
$this->assertEqual($user->Group->count(), 1);
$user->save();
unset($user);
@ -805,41 +844,41 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
// ACCESSING ASSOCIATION OBJECT PROPERTIES
$user = new User();
$this->assertTrue($user->getTable()->getRelation("Groupuser") instanceof Doctrine_Relation_ForeignKey);
$this->assertTrue($user->getTable()->getRelation("UserGroupuser") instanceof Doctrine_Relation_ForeignKey);
$this->assertTrue($user->Groupuser instanceof Doctrine_Collection);
$this->assertTrue($user->Groupuser[0] instanceof Groupuser);
$this->assertTrue($user->UserGroupuser instanceof Doctrine_Collection);
$this->assertTrue($user->UserGroupuser[0] instanceof Groupuser);
$user->name = "Jack Daniels";
$user->Group[0]->name = "Group #1";
$user->Group[1]->name = "Group #2";
$t1 = time();
$t2 = time();
$user->Groupuser[0]->added = $t1;
$user->Groupuser[1]->added = $t2;
$user->UserGroupuser[0]->added = $t1;
$user->UserGroupuser[1]->added = $t2;
$this->assertEqual($user->Groupuser[0]->added, $t1);
$this->assertEqual($user->Groupuser[1]->added, $t2);
$this->assertEqual($user->UserGroupuser[0]->added, $t1);
$this->assertEqual($user->UserGroupuser[1]->added, $t2);
$user->save();
$user->refresh();
$this->assertEqual($user->Groupuser[0]->added, $t1);
$this->assertEqual($user->Groupuser[1]->added, $t2);
$this->assertEqual($user->UserGroupuser[0]->added, $t1);
$this->assertEqual($user->UserGroupuser[1]->added, $t2);
}
public function testCount()
{
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
$this->assertTrue(is_integer($user->count()));
}
public function testGetReference()
{
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
$this->assertTrue($user->Email instanceof Doctrine_Record);
$this->assertTrue($user->Phonenumber instanceof Doctrine_Collection);
@ -849,13 +888,13 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
}
public function testGetIterator()
{
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
$this->assertTrue($user->getIterator() instanceof ArrayIterator);
}
public function testRefreshRelated()
{
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
$user->Address[0]->address = "Address #1";
$user->Address[1]->address = "Address #2";
$user->save();
@ -866,11 +905,12 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
Doctrine_Query::create()->delete()->from('EntityAddress')->where('user_id = ? AND address_id = ?', array($user->id, $user->Address[0]->id))->execute();
$user->refreshRelated();
$this->assertEqual(count($user->Address), 0);
}
public function testRefreshDeep()
{
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
$user->Address[0]->address = "Address #1";
$user->Address[1]->address = "Address #2";
$user->save();
@ -892,5 +932,6 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$this->assertNotEqual(count($user->Address), 1);
$user->refresh(true);
$this->assertEqual(count($user->Address), 1);
}
}

View File

@ -27,6 +27,7 @@ class Doctrine_Relation_ManyToMany_TestCase extends Doctrine_UnitTestCase {
}
$this->assertEqual($rel->getLocal(), 'oid');
}
public function testJoinComponent() {
$component = new JC3();

View File

@ -117,7 +117,7 @@ class Doctrine_Relation_Nest_TestCase extends Doctrine_UnitTestCase
$this->connection->clear();
$e = $e->getTable()->find($e->id);
$e = $e->getMapper()->find($e->id);
$count = count($this->conn);
@ -126,23 +126,15 @@ class Doctrine_Relation_Nest_TestCase extends Doctrine_UnitTestCase
$this->assertTrue($e->Entity[0] instanceof Entity);
$this->assertTrue($e->Entity[1] instanceof Entity);
$this->assertEqual(count($this->conn), ($count + 1));
$this->assertEqual($e->Entity[0]->name, "Friend 1");
$this->assertEqual($e->Entity[1]->name, "Friend 2");
$this->assertEqual($e->Entity[0]->Entity[0]->name, "Entity test");
$this->assertEqual($e->Entity[0]->Entity[1]->name, "Friend 1 1");
$this->assertEqual(count($this->conn), ($count + 2));
$this->assertEqual($e->Entity[1]->Entity[0]->name, "Entity test");
$this->assertEqual($e->Entity[1]->Entity[1]->name, "Friend 2 1");
$this->assertEqual(count($this->conn), ($count + 3));
$this->assertEqual($e->Entity[0]->state(), Doctrine_Record::STATE_CLEAN);
$this->assertEqual($e->Entity[1]->state(), Doctrine_Record::STATE_CLEAN);

View File

@ -120,15 +120,15 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($d['foreign'], 'entity_id');
$this->assertEqual($d['local'], 'id');
}
public function testRelationParserSupportsForeignColumnGuessingForAssociations()
/*public function testRelationParserSupportsForeignColumnGuessingForAssociations()
{
$r = new Doctrine_Relation_Parser($this->conn->getTable('User'));
$d = $r->completeAssocDefinition(array('class' => 'Group',
'type' => Doctrine_Relation::MANY,
'local' => 'user_id',
'refClass' => 'GroupUser'));
'refClass' => 'Groupuser'));
$this->assertEqual($d['foreign'], 'group_id');
}
public function testRelationParserSupportsLocalColumnGuessingForAssociations()
@ -141,7 +141,8 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase
'refClass' => 'GroupUser'));
$this->assertEqual($d['local'], 'user_id');
}
}*/
public function testGetRelationReturnsForeignKeyObjectForOneToOneRelation()
{
$r = new Doctrine_Relation_Parser($this->conn->getTable('User'));
@ -168,15 +169,16 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase
public function testGetRelationReturnsForeignKeyObjectForManytToManyRelation()
{
$r = new Doctrine_Relation_Parser($this->conn->getTable('User'));
$p = array('type' => Doctrine_Relation::MANY,
'refClass' => 'GroupUser');
$p = array('type' => Doctrine_Relation::MANY, 'refClass' => 'GroupUser',
'refRelationName' => 'UserGroupuser',
'refReverseRelationName' => 'GroupGroupuser');
$r->bind('Group', $p);
$rel = $r->getRelation('Group');
$this->assertTrue($rel instanceof Doctrine_Relation_Association);
$rel = $r->getRelation('GroupUser');
$rel = $r->getRelation('UserGroupuser');
$this->assertTrue($rel instanceof Doctrine_Relation_ForeignKey);
}
public function testGetRelationReturnsForeignKeyObjectForNestRelation()

View File

@ -140,7 +140,7 @@ class Doctrine_Relation_TestCase extends Doctrine_UnitTestCase
// test that join table relations can be initialized even before the association have been initialized
try {
$user->Groupuser;
$user->UserGroupuser;
$this->pass();
} catch(Doctrine_Exception $e) {
$this->fail();

View File

@ -83,7 +83,7 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase
$this->connection->clear();
$t = $this->connection->getTable('FieldNameTest')->find(1);
$t = $this->connection->getMapper('FieldNameTest')->find(1);
$this->assertEqual($t->someColumn, 'abc');
$this->assertEqual($t->someEnum, 'php');
@ -96,14 +96,14 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase
public function testGetForeignKey()
{
$fk = $this->objTable->getRelation("Group");
$fk = $this->objTable->getTable()->getRelation("Group");
$this->assertTrue($fk instanceof Doctrine_Relation_Association);
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY_AGGREGATE);
$this->assertTrue($fk->getLocal() == "user_id");
$this->assertTrue($fk->getForeign() == "group_id");
$fk = $this->objTable->getRelation("Email");
$fk = $this->objTable->getTable()->getRelation("Email");
$this->assertTrue($fk instanceof Doctrine_Relation_LocalKey);
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
$this->assertTrue($fk->getType() == Doctrine_Relation::ONE_COMPOSITE);
@ -111,11 +111,11 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase
$this->assertTrue($fk->getForeign() == $fk->getTable()->getIdentifier());
$fk = $this->objTable->getRelation('Phonenumber');
$fk = $this->objTable->getTable()->getRelation('Phonenumber');
$this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey);
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY);
$this->assertTrue($fk->getLocal() == $this->objTable->getIdentifier());
$this->assertTrue($fk->getLocal() == $this->objTable->getTable()->getIdentifier());
$this->assertTrue($fk->getForeign() == 'entity_id');
@ -127,7 +127,7 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase
public function testGetTableName()
{
$this->assertTrue($this->objTable->tableName == 'entity');
$this->assertTrue($this->objTable->getTable()->getTableName() == 'entity');
}
public function testGetConnection()
@ -233,7 +233,7 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase
public function testGetColumns()
{
$columns = $this->objTable->getColumns();
$columns = $this->objTable->getTable()->getColumns();
$this->assertTrue(is_array($columns));
}

View File

@ -55,7 +55,7 @@ class Doctrine_Ticket_480_TestCase extends Doctrine_UnitTestCase
{
$this->conn->export->exportClasses(array('stComment'));
$queries = $this->dbh->getAll();
// (2nd|1st except transaction init.) executed query must be CREATE TABLE or CREATE SEQUENCE, not CREATE TRIGGER
// Trigger can be created after both CREATE TABLE and CREATE SEQUENCE
$this->assertFalse(preg_match('~^CREATE TRIGGER.*~', $queries[1]));

View File

@ -37,7 +37,7 @@ class Doctrine_Ticket_626D_TestCase extends Doctrine_UnitTestCase
$student1 = $this->newStudent('T626D_Student1', '07090002', 'First Student');
try {
$student = Doctrine::getTable('T626D_Student1')->find('07090002');
$student = $this->conn->getMapper('T626D_Student1')->find('07090002');
$this->pass();
} catch (Exception $e) {
$this->fail($e->__toString());

View File

@ -57,7 +57,7 @@ class Doctrine_Ticket_638_TestCase extends Doctrine_UnitTestCase
$course1 = $this->newCourse('MATH001', 'Maths');
$course2 = $this->newCourse('ENG002', 'English Literature');
$sc = new T638_StudentCourse;
$sc = new T638_StudentCourse;
$sc->set('Student', $student1);
$sc->set('Course', $course1);

View File

@ -23,6 +23,10 @@ class Doctrine_Ticket_697_TestCase extends Doctrine_UnitTestCase
public function testIdsAreSetWhenSavingSubclassInstancesInCTI()
{
$personTable = $this->conn->getTable('T697_Person');
$userTable = $this->conn->getTable('T697_User');
//var_dump($userTable->getColumns());
$p = new T697_Person();
$p['name']='Rodrigo';
$p->save();
@ -40,7 +44,11 @@ class T697_Person extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setInheritanceType(Doctrine::INHERITANCETYPE_JOINED,
array('T697_Person' => array('dtype' => 1), 'T697_User' => array('dtype' => 2)));
$this->setTableName('t697_person');
$this->hasColumn('name', 'string', 30);
$this->hasColumn('dtype', 'integer', 4);
}
}
@ -48,6 +56,7 @@ class T697_Person extends Doctrine_Record
class T697_User extends T697_Person {
public function setTableDefinition()
{
$this->setTableName('t697_user');
$this->hasColumn('password', 'string', 30);
}
}

View File

@ -52,8 +52,7 @@ class Doctrine_UnitOfWork_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($tree, $this->correct);
$tree = $this->unitOfWork->buildFlushTree(array('Assignment', 'Task', 'Resource'));
$this->assertEqual($tree, array('Resource', 'Task', 'ResourceType', 'Assignment', 'ResourceReference'));
$this->assertEqual($tree, $this->correct2);
}
public function testbuildFlushTree2() {
$this->correct = array('Forum_Category','Forum_Board','Forum_Thread');

View File

@ -139,7 +139,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
public function testValidate()
{
$user = $this->connection->getTable('User')->find(4);
$user = $this->connection->getMapper('User')->find(4);
$set = array('password' => 'this is an example of too long password',
'loginname' => 'this is an example of too long loginname',
@ -198,7 +198,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
public function testSave()
{
$this->manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
try {
$user->name = "this is an example of too long name not very good example but an example nevertheless";
$user->save();
@ -258,7 +258,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
}
// Tests validateOnUpdate()
$user = $this->connection->getTable("User")->find(4);
$user = $this->connection->getMapper("User")->find(4);
try {
$user->name = "The Saint"; // Set correct name
$user->password = "Top Secret"; // Set correct password
@ -335,7 +335,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
$r->identifier = '1234';
$r->save();
$r = $this->connection->getTable('ValidatorTest_Person')->findAll()->getFirst();
$r = $this->connection->getMapper('ValidatorTest_Person')->findAll()->getFirst();
$r->identifier = 1234;
try {
$r->save();
@ -409,6 +409,7 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
$this->fail();
$this->conn->commit();
} catch (Doctrine_Validator_Exception $dve) {
$this->conn->rollback();
$s = $dve->getInvalidRecords();
$this->assertEqual(1, count($dve->getInvalidRecords()));
$stack = $client->ValidatorTest_AddressModel[0]->getErrorStack();

View File

@ -229,12 +229,11 @@ $test->addTestCase($record);
$test->addTestCase(new Doctrine_CustomPrimaryKey_TestCase());
$test->addTestCase(new Doctrine_CustomResultSetOrder_TestCase());
$test->addTestCase(new Doctrine_CtiColumnAggregation_TestCase());
//$test->addTestCase(new Doctrine_CtiColumnAggregation_TestCase());
$test->addTestCase(new Doctrine_ColumnAggregationInheritance_TestCase());
$test->addTestCase(new Doctrine_ClassTableInheritance_TestCase());
//$test->addTestCase(new Doctrine_ClassTableInheritance_TestCase());
$test->addTestCase(new Doctrine_ColumnAlias_TestCase());
$test->addTestCase(new Doctrine_RawSql_TestCase());
$test->addTestCase(new Doctrine_NewCore_TestCase());
@ -242,13 +241,20 @@ $test->addTestCase(new Doctrine_NewCore_TestCase());
$test->addTestCase(new Doctrine_Template_TestCase());
//$test->addTestCase(new Doctrine_Import_Builder_TestCase());
// Inheritance mapping tests
$test->addTestCase(new Doctrine_Inheritance_SingleTable_TestCase());
$test->addTestCase(new Doctrine_Inheritance_Joined_TestCase());
$test->addTestCase(new Doctrine_Inheritance_TablePerClass_TestCase());
// nestedset tests
$test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase());
// Search tests
$search = new GroupTest('Search tests','search');
$search->addTestCase(new Doctrine_Search_TestCase());
$search->addTestCase(new Doctrine_Search_Query_TestCase());
$search->addTestCase(new Doctrine_Search_File_TestCase());
//$search->addTestCase(new Doctrine_Search_TestCase());
//$search->addTestCase(new Doctrine_Search_Query_TestCase());
//$search->addTestCase(new Doctrine_Search_File_TestCase());
$test->addTestCase($search);
@ -267,7 +273,7 @@ $test->addTestCase($cache);
// Migration Tests
$migration = new GroupTest('Migration tests','migration');
$migration->addTestCase(new Doctrine_Migration_TestCase());
$migration->addTestCase(new Doctrine_Migration_Mysql_TestCase());
//$migration->addTestCase(new Doctrine_Migration_Mysql_TestCase());
$test->addTestCase($migration);
$test->addTestCase(new Doctrine_Query_ApplyInheritance_TestCase());