From 4e99dcb51f9e87725f1327db8d0415e41ea76905 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Sat, 24 May 2008 18:51:47 +0000 Subject: [PATCH] Fixes for test case in DQL --- lib/Doctrine/ClassMetadata.php | 45 +++++++++++++++++++++++ lib/Doctrine/Connection.php | 2 +- lib/Doctrine/Query/Production/IndexBy.php | 4 +- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ClassMetadata.php b/lib/Doctrine/ClassMetadata.php index c47fa72b1..1305af98a 100644 --- a/lib/Doctrine/ClassMetadata.php +++ b/lib/Doctrine/ClassMetadata.php @@ -338,6 +338,51 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab return in_array($fieldName, $this->_identifier); } + /** + * Check if the field is unique + * + * @param string $fieldName The field name + * @return boolean TRUE if the field is unique, FALSE otherwise. + */ + public function isIdentifierComposite() + { + return ($this->_identifierType == Doctrine::IDENTIFIER_COMPOSITE); + } + + /** + * Check if the field is unique + * + * @param string $fieldName The field name + * @return boolean TRUE if the field is unique, FALSE otherwise. + */ + public function isUniqueField($fieldName) + { + $mapping = $this->getColumnMapping($fieldName); + + if ($mapping !== false) { + return isset($mapping['unique']) && $mapping['unique'] == true; + } + + return false; + } + + /** + * Check if the field is not null + * + * @param string $fieldName The field name + * @return boolean TRUE if the field is not null, FALSE otherwise. + */ + public function isNotNull($fieldName) + { + $mapping = $this->getColumnMapping($fieldName); + + if ($mapping !== false) { + return isset($mapping['notnull']) && $mapping['notnull'] == true; + } + + return false; + } + /** * addIndex * diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 1403bfbfd..a287f0db3 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -853,7 +853,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * * @return string */ - public function modifyLimitQuery($query, $query, $limit = false, $offset = false, $isManip = false) + public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false) { return $query; } diff --git a/lib/Doctrine/Query/Production/IndexBy.php b/lib/Doctrine/Query/Production/IndexBy.php index b3eaf2ad3..adbd7e653 100644 --- a/lib/Doctrine/Query/Production/IndexBy.php +++ b/lib/Doctrine/Query/Production/IndexBy.php @@ -79,7 +79,7 @@ class Doctrine_Query_Production_IndexBy extends Doctrine_Query_Production // The INDEXBY field must be either the (primary && not part of composite pk) || (unique && notnull) $columnMapping = $classMetadata->getColumnMapping($this->_fieldName); - if ( ! $classMetadata->isIdentifier($field) && ! $classMetadata->isUniqueField($field) && ! $classMetadata->isNotNull($field)) { + if ( ! $classMetadata->isIdentifier($this->_fieldName) && ! $classMetadata->isUniqueField($this->_fieldName) && ! $classMetadata->isNotNull($this->_fieldName)) { $this->_parser->semanticalError( "Field '" . $this->_fieldName . "' of component '" . $classMetadata->getClassName() . "' must be unique and notnull to be used as index.", @@ -87,7 +87,7 @@ class Doctrine_Query_Production_IndexBy extends Doctrine_Query_Production ); } - if ($classMetadata->isIdentifier($field) && $classMetadata->isIdentifierComposite()) { + if ($classMetadata->isIdentifier($this->_fieldName) && $classMetadata->isIdentifierComposite()) { $this->_parser->semanticalError( "Field '" . $this->_fieldName . "' of component '" . $classMetadata->getClassName() . "' must be primary and not part of a composite primary key to be used as index.",