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
const ATTR_USE_NATIVE_ENUM = 117;
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_BATCH_SIZE = 119;
const ATTR_LOCKMODE = 120;
const ATTR_NAME_PREFIX = 121;
const ATTR_CREATE_TABLES = 122;
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_LIFESPAN = 151;
......@@ -512,7 +495,7 @@ final class Doctrine
{
$loadedModels = self::getLoadedModels();
foreach ($loadedModels AS $name) {
foreach ($loadedModels as $name) {
$model = new $name();
$table = $model->getTable();
......@@ -669,4 +652,4 @@ final class Doctrine
return true;
}
}
\ No newline at end of file
}
......@@ -72,7 +72,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*
* @param Doctrine_Table|string $table
*/
public function __construct($table)
public function __construct($table, $keyColumn = null)
{
if ( ! ($table instanceof Doctrine_Table)) {
$table = Doctrine_Manager::getInstance()
......@@ -80,9 +80,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
$this->_table = $table;
$name = $table->getAttribute(Doctrine::ATTR_COLL_KEY);
if ($name !== null) {
$this->keyColumn = $name;
if ($keyColumn === null) {
$keyColumn = $table->getBoundQueryPart('indexBy');
}
if ($keyColumn !== null) {
$this->keyColumn = $keyColumn;
}
}
/**
......@@ -152,12 +155,14 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->$name = $values;
}
$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 ($name !== null) {
$this->keyColumn = $name;
if ($keyColumn !== null) {
$this->keyColumn = $keyColumn;
}
}
/**
......@@ -224,9 +229,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->reference = $record;
$this->relation = $relation;
if ($relation instanceof Doctrine_Relation_ForeignKey
|| $relation instanceof Doctrine_Relation_LocalKey
) {
if ($relation instanceof Doctrine_Relation_ForeignKey ||
$relation instanceof Doctrine_Relation_LocalKey) {
$this->referenceField = $relation->getForeign();
......@@ -318,6 +322,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->data[$key] = $record;
}
if (isset($this->keyColumn)) {
$record->set($this->keyColumn, $key);
}
return $record;
}
......@@ -716,4 +725,4 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
{
return Doctrine_Lib::getCollectionAsString($this);
}
}
\ No newline at end of file
}
......@@ -80,9 +80,6 @@ abstract class Doctrine_Configurable extends Doctrine_Object
}
switch ($attribute) {
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');
case Doctrine::ATTR_LISTENER:
$this->setEventListener($value);
......@@ -102,10 +99,6 @@ abstract class Doctrine_Configurable extends Doctrine_Object
}
}
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_QUERY_LIMIT:
case Doctrine::ATTR_QUOTE_IDENTIFIER:
......@@ -348,4 +341,4 @@ abstract class Doctrine_Configurable extends Doctrine_Object
{
return $this->parent;
}
}
\ No newline at end of file
}
......@@ -83,6 +83,7 @@ class Doctrine_I18n extends Doctrine_Plugin
foreach ($cols as $column => $definition) {
if (in_array($column, $this->_options['fields'])) {
$columns[$column] = $definition;
$table->removeColumn($column);
}
}
......@@ -101,7 +102,8 @@ class Doctrine_I18n extends Doctrine_Plugin
$columns += $fk;
$options = array('className' => $this->_options['className']);
$options = array('className' => $this->_options['className'],
'queryParts' => array('indexBy' => 'lang'));
$builder = new Doctrine_Import_Builder();
......@@ -111,7 +113,9 @@ class Doctrine_I18n extends Doctrine_Plugin
eval($def);
}
$this->_options['pluginTable'] = $table->getConnection()->getTable($this->_options['className']);
$this->_options['pluginTable']->bindQueryPart('indexBy', 'lang');
return true;
}
}
\ No newline at end of file
}
......@@ -1503,15 +1503,27 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
}
$parent = $prevPath;
}
$table = $this->_aliasMap[$componentAlias]['table'];
$indexBy = null;
if (isset($mapWith)) {
$e = explode('.', $mapWith);
$table = $this->_aliasMap[$componentAlias]['table'];
if ( ! $table->hasColumn($e[1])) {
throw new Doctrine_Query_Exception("Couldn't use key mapping. Column " . $e[1] . " does not exist.");
if (isset($e[1])) {
$indexBy = $e[1];
}
} elseif ($table->getBoundQueryPart('indexBy') !== null) {
$indexBy = $table->getBoundQueryPart('indexBy');
}
$this->_aliasMap[$componentAlias]['map'] = $table->getColumnName($e[1]);
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($indexBy);
}
return $this->_aliasMap[$componentAlias];
}
......@@ -1677,4 +1689,4 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this->_dqlParts = array();
$this->_enumParams = array();
}
}
\ No newline at end of file
}
This diff is collapsed.
......@@ -71,6 +71,7 @@ class Doctrine_I18n_TestCase extends Doctrine_UnitTestCase
public function testTranslationTableIsInitializedProperly()
{
$i = new I18nTest();
$i->id = 1;
$i->Translation['EN']->name = 'some name';
$i->Translation['EN']->title = 'some title';
......@@ -96,7 +97,7 @@ class Doctrine_I18n_TestCase extends Doctrine_UnitTestCase
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);
print_r($i);
$this->assertEqual($i['Translation']['EN']['name'], 'some name');
$this->assertEqual($i['Translation']['EN']['title'], 'some title');
$this->assertEqual($i['Translation']['EN']['lang'], 'EN');
......
......@@ -32,18 +32,75 @@
*/
class Doctrine_Query_TestCase extends Doctrine_UnitTestCase
{
public function testGetQueryHookResetsTheManuallyAddedDqlParts()
{
$q = new MyQuery();
$q->from('User u');
$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)');
// test consequent calls
$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
{
......
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