Commit d9112ad1 authored by romanb's avatar romanb

Merged current state of my experimental branch back to trunk.

parent 344ab02d
......@@ -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
*/
......
This diff is collapsed.
......@@ -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
*/
......
This diff is collapsed.
This diff is collapsed.
......@@ -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);
}
}
......
......@@ -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) {
......
......@@ -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);
}
......
......@@ -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);
}
......@@ -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);
......@@ -574,6 +569,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
* this is the same as Doctrine_Connection::getTable() except
......
This diff is collapsed.
<?php
class Doctrine_Mapper_Exception extends Doctrine_Exception {}
\ No newline at end of file
<?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;
}
}
<?php
class Doctrine_Mapper_SingleTable extends Doctrine_Mapper
{
public function getDiscriminatorColumn($domainClassName)
{
$inheritanceMap = $this->_table->getOption('inheritanceMap');
return isset($inheritanceMap[$domainClassName]) ? $inheritanceMap[$domainClassName] : array();
}
}
<?php
class Doctrine_Mapper_TablePerClass extends Doctrine_Mapper
{
}
......@@ -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,
//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);
'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;
......@@ -1535,8 +1536,14 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
}
$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());
......@@ -1596,7 +1603,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
}
}
$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,59 +1675,16 @@ 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
* fetches the count of the query
......@@ -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) : '';
......
......@@ -152,7 +152,7 @@ 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(),
......@@ -522,21 +522,59 @@ abstract class Doctrine_Query_Abstract
}
/**
* applyInheritance
* applies column aggregation inheritance to DQL / SQL query
* Creates the SQL snippet for additional joins.
*
* @return string
* @return string The created SQL snippet.
*/
public function applyInheritance()
protected function _createCustomJoinSql($componentName, $componentAlias)
{
// get the inheritance maps
$array = array();
$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 ($this->_queryComponents as $componentAlias => $data) {
$tableAlias = $this->getSqlTableAlias($componentAlias);
$array[$tableAlias][] = $data['table']->inheritanceMap;
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()
{
$array = array();
foreach ($this->_queryComponents as $componentAlias => $data) {
$tableAlias = $this->getSqlTableAlias($componentAlias);
//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();
}
......
......@@ -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));
}
......
......@@ -99,6 +99,7 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
}
}
return $condition;
}
}
\ No newline at end of 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,11 +312,14 @@ 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(),
$this->_queryComponents[$componentAlias] = array(
'table' => $relation->getTable(),
'mapper' => $this->_conn->getMapper($component),
'parent' => $parent,
'relation' => $relation);
}
......
This diff is collapsed.
......@@ -37,10 +37,17 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
*/
protected $_table;
/**
*
* @var Doctrine_Mapper_Abstract
*/
protected $_mapper;
public function setTableDefinition()
{
}
public function setUp()
{
......@@ -58,6 +65,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);
......@@ -345,6 +363,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
* adds a check constraint
......
......@@ -60,23 +60,37 @@ 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,
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,
'refTable' => 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'];
......@@ -214,6 +230,11 @@ abstract class Doctrine_Relation implements ArrayAccess
return $this->definition['alias'];
}
public function getRelationName()
{
return $this->definition['relName'];
}
/**
* getType
* returns the relation type, either 0 or 1
......@@ -321,6 +342,11 @@ abstract class Doctrine_Relation implements ArrayAccess
return $dql;
}
public function getForeignComponentName()
{
return $this->definition['class'];
}
/**
* fetchRelatedFor
*
......
......@@ -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
......@@ -47,6 +46,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);
......
......@@ -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 . ')';
};
......
......@@ -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);
}
$related->setReference($record, $this);
}
return $related;
}
......
......@@ -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();
......
......@@ -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();
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
class Doctrine_Table_Factory_Exception extends Doctrine_Table_Exception {}
......@@ -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++;
}
......
......@@ -160,6 +160,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
* Start a transaction or set a savepoint.
......@@ -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.");
}
......
......@@ -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'));
}
}
......@@ -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',
......
......@@ -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'
));*/
}
}
......@@ -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()
......
......@@ -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,
));
}
}
\ No newline at end of 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 */
......
......@@ -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');
......
......@@ -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
......
......@@ -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()
......
......@@ -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));
}
......
......@@ -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() {
......
......@@ -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');
......
......@@ -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';
......
......@@ -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);
}
}
......
......@@ -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');
}
......
......@@ -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()
......
<?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());
}
}
<?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());
}
}
<?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());
}
}
......@@ -47,8 +47,8 @@ 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)';
......
......@@ -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;
......
......@@ -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';
......
......@@ -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');
......
......@@ -62,6 +62,6 @@ class Doctrine_Query_Registry_TestCase extends Doctrine_UnitTestCase
$user = new User();
$user->getTable()->execute('all');
$user->getMapper()->execute('all');
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment