Commit 7ecc82fd authored by zYne's avatar zYne

removed deprecated attributes, added bound query part functionality, fixed remaining I18n issues

parent 11e8bfed
...@@ -169,27 +169,10 @@ final class Doctrine ...@@ -169,27 +169,10 @@ final class Doctrine
const ATTR_USE_NATIVE_ENUM = 117; const ATTR_USE_NATIVE_ENUM = 117;
const ATTR_DEFAULT_SEQUENCE = 133; const ATTR_DEFAULT_SEQUENCE = 133;
/** TODO: REMOVE THE FOLLOWING CONSTANTS AND UPDATE THE DOCS ! */
const ATTR_VLD = -1;
const ATTR_AUTO_LENGTH_VLD = -2;
const ATTR_AUTO_TYPE_VLD = -3;
const ATTR_FETCHMODE = 118; const ATTR_FETCHMODE = 118;
const ATTR_BATCH_SIZE = 119;
const ATTR_LOCKMODE = 120;
const ATTR_NAME_PREFIX = 121; const ATTR_NAME_PREFIX = 121;
const ATTR_CREATE_TABLES = 122; const ATTR_CREATE_TABLES = 122;
const ATTR_COLL_LIMIT = 123; const ATTR_COLL_LIMIT = 123;
const ATTR_ACCESSORS = 124;
const ATTR_ACCESSOR_PREFIX_GET = 125;
const ATTR_ACCESSOR_PREFIX_SET = 126;
/**
* NESTED SET CONSTANTS
*/
const ATTR_NS_ROOT_COLUMN_NAME = 130;
const ATTR_NS_GAP_SIZE = 131;
const ATTR_NS_GAP_DECREASE_EXP = 132;
const ATTR_CACHE = 150; const ATTR_CACHE = 150;
const ATTR_CACHE_LIFESPAN = 151; const ATTR_CACHE_LIFESPAN = 151;
...@@ -512,7 +495,7 @@ final class Doctrine ...@@ -512,7 +495,7 @@ final class Doctrine
{ {
$loadedModels = self::getLoadedModels(); $loadedModels = self::getLoadedModels();
foreach ($loadedModels AS $name) { foreach ($loadedModels as $name) {
$model = new $name(); $model = new $name();
$table = $model->getTable(); $table = $model->getTable();
......
...@@ -72,7 +72,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -72,7 +72,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* *
* @param Doctrine_Table|string $table * @param Doctrine_Table|string $table
*/ */
public function __construct($table) public function __construct($table, $keyColumn = null)
{ {
if ( ! ($table instanceof Doctrine_Table)) { if ( ! ($table instanceof Doctrine_Table)) {
$table = Doctrine_Manager::getInstance() $table = Doctrine_Manager::getInstance()
...@@ -80,9 +80,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -80,9 +80,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
} }
$this->_table = $table; $this->_table = $table;
$name = $table->getAttribute(Doctrine::ATTR_COLL_KEY); if ($keyColumn === null) {
if ($name !== null) { $keyColumn = $table->getBoundQueryPart('indexBy');
$this->keyColumn = $name; }
if ($keyColumn !== null) {
$this->keyColumn = $keyColumn;
} }
} }
/** /**
...@@ -154,10 +157,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -154,10 +157,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->_table = $connection->getTable($this->_table); $this->_table = $connection->getTable($this->_table);
if ($keyColumn === null) {
$keyColumn = $table->getBoundQueryPart('indexBy');
}
$name = $this->_table->getAttribute(Doctrine::ATTR_COLL_KEY); if ($keyColumn !== null) {
if ($name !== null) { $this->keyColumn = $keyColumn;
$this->keyColumn = $name;
} }
} }
/** /**
...@@ -224,9 +229,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -224,9 +229,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->reference = $record; $this->reference = $record;
$this->relation = $relation; $this->relation = $relation;
if ($relation instanceof Doctrine_Relation_ForeignKey if ($relation instanceof Doctrine_Relation_ForeignKey ||
|| $relation instanceof Doctrine_Relation_LocalKey $relation instanceof Doctrine_Relation_LocalKey) {
) {
$this->referenceField = $relation->getForeign(); $this->referenceField = $relation->getForeign();
...@@ -318,6 +322,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -318,6 +322,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->data[$key] = $record; $this->data[$key] = $record;
} }
if (isset($this->keyColumn)) {
$record->set($this->keyColumn, $key);
}
return $record; return $record;
} }
......
...@@ -80,9 +80,6 @@ abstract class Doctrine_Configurable extends Doctrine_Object ...@@ -80,9 +80,6 @@ abstract class Doctrine_Configurable extends Doctrine_Object
} }
switch ($attribute) { switch ($attribute) {
case Doctrine::ATTR_FETCHMODE: case Doctrine::ATTR_FETCHMODE:
case Doctrine::ATTR_COLL_LIMIT:
case Doctrine::ATTR_ACCESSOR_PREFIX_GET:
case Doctrine::ATTR_ACCESSOR_PREFIX_SET:
throw new Doctrine_Exception('Deprecated attribute. See http://doctrine.pengus.net/doctrine/manual/new/?chapter=configuration'); throw new Doctrine_Exception('Deprecated attribute. See http://doctrine.pengus.net/doctrine/manual/new/?chapter=configuration');
case Doctrine::ATTR_LISTENER: case Doctrine::ATTR_LISTENER:
$this->setEventListener($value); $this->setEventListener($value);
...@@ -102,10 +99,6 @@ abstract class Doctrine_Configurable extends Doctrine_Object ...@@ -102,10 +99,6 @@ abstract class Doctrine_Configurable extends Doctrine_Object
} }
} }
break; break;
case Doctrine::ATTR_VLD:
case Doctrine::ATTR_AUTO_LENGTH_VLD:
case Doctrine::ATTR_AUTO_TYPE_VLD:
throw new Doctrine_Exception('Deprecated attribute. See http://doctrine.pengus.net/doctrine/manual/new/?chapter=configuration#validation-attributes');
case Doctrine::ATTR_VALIDATE: case Doctrine::ATTR_VALIDATE:
case Doctrine::ATTR_QUERY_LIMIT: case Doctrine::ATTR_QUERY_LIMIT:
case Doctrine::ATTR_QUOTE_IDENTIFIER: case Doctrine::ATTR_QUOTE_IDENTIFIER:
......
...@@ -83,6 +83,7 @@ class Doctrine_I18n extends Doctrine_Plugin ...@@ -83,6 +83,7 @@ class Doctrine_I18n extends Doctrine_Plugin
foreach ($cols as $column => $definition) { foreach ($cols as $column => $definition) {
if (in_array($column, $this->_options['fields'])) { if (in_array($column, $this->_options['fields'])) {
$columns[$column] = $definition; $columns[$column] = $definition;
$table->removeColumn($column);
} }
} }
...@@ -101,7 +102,8 @@ class Doctrine_I18n extends Doctrine_Plugin ...@@ -101,7 +102,8 @@ class Doctrine_I18n extends Doctrine_Plugin
$columns += $fk; $columns += $fk;
$options = array('className' => $this->_options['className']); $options = array('className' => $this->_options['className'],
'queryParts' => array('indexBy' => 'lang'));
$builder = new Doctrine_Import_Builder(); $builder = new Doctrine_Import_Builder();
...@@ -112,6 +114,8 @@ class Doctrine_I18n extends Doctrine_Plugin ...@@ -112,6 +114,8 @@ class Doctrine_I18n extends Doctrine_Plugin
} }
$this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']); $this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']);
$this->_options['pluginTable']->bindQueryPart('indexBy', 'lang');
return true; return true;
} }
} }
...@@ -1503,15 +1503,27 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -1503,15 +1503,27 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
} }
$parent = $prevPath; $parent = $prevPath;
} }
$table = $this->_aliasMap[$componentAlias]['table'];
$indexBy = null;
if (isset($mapWith)) { if (isset($mapWith)) {
$e = explode('.', $mapWith); $e = explode('.', $mapWith);
$table = $this->_aliasMap[$componentAlias]['table'];
if ( ! $table->hasColumn($e[1])) { if (isset($e[1])) {
throw new Doctrine_Query_Exception("Couldn't use key mapping. Column " . $e[1] . " does not exist."); $indexBy = $e[1];
}
} elseif ($table->getBoundQueryPart('indexBy') !== null) {
$indexBy = $table->getBoundQueryPart('indexBy');
}
if ($indexBy !== null) {
if ( ! $table->hasColumn($indexBy)) {
throw new Doctrine_Query_Exception("Couldn't use key mapping. Column " . $indexBy . " does not exist.");
} }
$this->_aliasMap[$componentAlias]['map'] = $table->getColumnName($e[1]); $this->_aliasMap[$componentAlias]['map'] = $table->getColumnName($indexBy);
} }
return $this->_aliasMap[$componentAlias]; return $this->_aliasMap[$componentAlias];
} }
......
This diff is collapsed.
...@@ -71,6 +71,7 @@ class Doctrine_I18n_TestCase extends Doctrine_UnitTestCase ...@@ -71,6 +71,7 @@ class Doctrine_I18n_TestCase extends Doctrine_UnitTestCase
public function testTranslationTableIsInitializedProperly() public function testTranslationTableIsInitializedProperly()
{ {
$i = new I18nTest(); $i = new I18nTest();
$i->id = 1;
$i->Translation['EN']->name = 'some name'; $i->Translation['EN']->name = 'some name';
$i->Translation['EN']->title = 'some title'; $i->Translation['EN']->title = 'some title';
...@@ -96,7 +97,7 @@ class Doctrine_I18n_TestCase extends Doctrine_UnitTestCase ...@@ -96,7 +97,7 @@ class Doctrine_I18n_TestCase extends Doctrine_UnitTestCase
public function testDataFetching() public function testDataFetching()
{ {
$i = Doctrine_Query::create()->from('I18nTest i')->innerJoin('i.Translation t INDEXBY t.lang')->orderby('t.lang')->fetchOne(array(), Doctrine::HYDRATE_ARRAY); $i = Doctrine_Query::create()->from('I18nTest i')->innerJoin('i.Translation t INDEXBY t.lang')->orderby('t.lang')->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
print_r($i);
$this->assertEqual($i['Translation']['EN']['name'], 'some name'); $this->assertEqual($i['Translation']['EN']['name'], 'some name');
$this->assertEqual($i['Translation']['EN']['title'], 'some title'); $this->assertEqual($i['Translation']['EN']['title'], 'some title');
$this->assertEqual($i['Translation']['EN']['lang'], 'EN'); $this->assertEqual($i['Translation']['EN']['lang'], 'EN');
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
*/ */
class Doctrine_Query_TestCase extends Doctrine_UnitTestCase class Doctrine_Query_TestCase extends Doctrine_UnitTestCase
{ {
public function testGetQueryHookResetsTheManuallyAddedDqlParts() public function testGetQueryHookResetsTheManuallyAddedDqlParts()
{ {
$q = new MyQuery(); $q = new MyQuery();
...@@ -44,6 +45,62 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase ...@@ -44,6 +45,62 @@ class Doctrine_Query_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id = 4 AND (e.type = 0)'); $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id = 4 AND (e.type = 0)');
} }
public function testParseClauseSupportsArithmeticOperators()
{
$q = new Doctrine_Query();
$str = $q->parseClause('2 + 3');
$this->assertEqual($str, '2 + 3');
$str = $q->parseClause('2 + 3 - 5 * 6');
$this->assertEqual($str, '2 + 3 - 5 * 6');
}
public function testParseClauseSupportsArithmeticOperatorsWithFunctions()
{
$q = new Doctrine_Query();
$str = $q->parseClause('ACOS(2) + 3');
$this->assertEqual($str, 'ACOS(2) + 3');
}
public function testParseClauseSupportsArithmeticOperatorsWithParenthesis()
{
$q = new Doctrine_Query();
$str = $q->parseClause('(3 + 3)*3');
$this->assertEqual($str, '(3 + 3)*3');
$str = $q->parseClause('((3 + 3)*3 - 123) * 12 * (13 + 31)');
$this->assertEqual($str, '((3 + 3)*3 - 123) * 12 * (13 + 31)');
}
public function testParseClauseSupportsArithmeticOperatorsWithParenthesisAndFunctions()
{
$q = new Doctrine_Query();
$str = $q->parseClause('(3 + 3)*ACOS(3)');
$this->assertEqual($str, '(3 + 3)*ACOS(3)');
$str = $q->parseClause('((3 + 3)*3 - 123) * ACOS(12) * (13 + 31)');
$this->assertEqual($str, '((3 + 3)*3 - 123) * ACOS(12) * (13 + 31)');
}
public function testParseClauseSupportsComponentReferences()
{
$q = new Doctrine_Query();
$q->from('User u')->leftJoin('u.Phonenumber p');
$q->getQuery();
$this->assertEqual($q->parseClause("CONCAT('u.name', u.name)"), "CONCAT('u.name', e.name)");
}
} }
class MyQuery extends Doctrine_Query class MyQuery extends Doctrine_Query
{ {
......
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