Commit 85cb20f6 authored by romanb's avatar romanb

made sure every caller of getIdentifier can handle an array. getIdentifier now...

made sure every caller of getIdentifier can handle an array. getIdentifier now always returns an array.
parent edcc8be2
...@@ -24,8 +24,9 @@ ...@@ -24,8 +24,9 @@
* These informations are used for the proper object-relational mapping of the class. * These informations are used for the proper object-relational mapping of the class.
* *
* @package Doctrine * @package Doctrine
* @author Roman Borschel <roman@code-factory.org> * @subpackage ClassMetadata
* @since 1.0 * @author Roman Borschel <roman@code-factory.org>
* @since 1.0
*/ */
class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializable class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializable
{ {
...@@ -299,8 +300,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -299,8 +300,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
*/ */
public function isIdentifier($fieldName) public function isIdentifier($fieldName)
{ {
return ($fieldName === $this->getIdentifier() || return in_array($fieldName, (array)$this->getIdentifier());
in_array($fieldName, (array) $this->getIdentifier()));
} }
/** /**
...@@ -572,10 +572,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -572,10 +572,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
} }
if ( ! empty($options['primary'])) { if ( ! empty($options['primary'])) {
if (isset($this->_identifier)) { if ( ! in_array($fieldName, $this->_identifier)) {
$this->_identifier = $this->_identifier;
}
if ( ! in_array($fieldName, (array) $this->_identifier)) {
$this->_identifier[] = $fieldName; $this->_identifier[] = $fieldName;
} }
} }
...@@ -657,7 +654,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab ...@@ -657,7 +654,7 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab
return $this->_identifier; return $this->_identifier;
} }
public function setIdentifier($identifier) public function setIdentifier(array $identifier)
{ {
$this->_identifier = $identifier; $this->_identifier = $identifier;
} }
......
...@@ -206,7 +206,7 @@ class Doctrine_ClassMetadata_Factory ...@@ -206,7 +206,7 @@ class Doctrine_ClassMetadata_Factory
*/ */
protected function _initIdentifier(Doctrine_ClassMetadata $class) protected function _initIdentifier(Doctrine_ClassMetadata $class)
{ {
switch (count($class->getIdentifier())) { switch (count((array)$class->getIdentifier())) {
case 0: case 0:
if ($class->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED && if ($class->getInheritanceType() == Doctrine::INHERITANCETYPE_JOINED &&
count($class->getOption('parents')) > 0) { count($class->getOption('parents')) > 0) {
...@@ -242,12 +242,12 @@ class Doctrine_ClassMetadata_Factory ...@@ -242,12 +242,12 @@ class Doctrine_ClassMetadata_Factory
'autoincrement' => true, 'autoincrement' => true,
'primary' => true); 'primary' => true);
$class->setColumn('id', $definition['type'], $definition['length'], $definition, true); $class->setColumn('id', $definition['type'], $definition['length'], $definition, true);
$class->setIdentifier('id'); $class->setIdentifier(array('id'));
$class->setIdentifierType(Doctrine::IDENTIFIER_AUTOINC); $class->setIdentifierType(Doctrine::IDENTIFIER_AUTOINC);
} }
break; break;
case 1: case 1:
foreach ($class->getIdentifier() as $pk) { foreach ((array)$class->getIdentifier() as $pk) {
$columnName = $class->getColumnName($pk); $columnName = $class->getColumnName($pk);
$thisColumns = $class->getColumns(); $thisColumns = $class->getColumns();
$e = $thisColumns[$columnName]; $e = $thisColumns[$columnName];
...@@ -291,7 +291,7 @@ class Doctrine_ClassMetadata_Factory ...@@ -291,7 +291,7 @@ class Doctrine_ClassMetadata_Factory
} }
} }
$class->setIdentifier($pk); $class->setIdentifier(array($pk));
break; break;
default: default:
......
...@@ -426,15 +426,30 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -426,15 +426,30 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public function getPrimaryKeys() public function getPrimaryKeys()
{ {
$list = array(); $list = array();
$name = $this->_mapper->getTable()->getIdentifier(); $idFieldNames = (array)$this->_mapper->getClassMetadata()->getIdentifier();
foreach ($this->data as $record) { foreach ($this->data as $record) {
if (is_array($record) && isset($record[$name])) { if (is_array($record)) {
$list[] = $record[$name]; if (count($idFieldNames) > 1) {
$id = array();
foreach ($idFieldNames as $fieldName) {
if (isset($record[$fieldName])) {
$id[] = $record[$fieldName];
}
}
$list[] = $id;
} else {
$idField = $idFieldNames[0];
if (isset($record[$idField])) {
$list[] = $record[$idField];
}
}
} else { } else {
// @todo does not take composite keys into account
$list[] = $record->getIncremented(); $list[] = $record->getIncremented();
} }
} }
return $list; return $list;
} }
...@@ -615,7 +630,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -615,7 +630,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this->data[$key]->setRelated($name, $sub); $this->data[$key]->setRelated($name, $sub);
} }
} else if ($rel instanceof Doctrine_Relation_Association) { } else if ($rel instanceof Doctrine_Relation_Association) {
$identifier = $this->_mapper->getTable()->getIdentifier(); // @TODO composite key support
$identifier = (array)$this->_mapper->getClassMetadata()->getIdentifier();
$asf = $rel->getAssociationFactory(); $asf = $rel->getAssociationFactory();
$name = $table->getComponentName(); $name = $table->getComponentName();
...@@ -625,7 +641,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -625,7 +641,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
} }
$sub = new Doctrine_Collection($rel->getForeignComponentName()); $sub = new Doctrine_Collection($rel->getForeignComponentName());
foreach ($coll as $k => $related) { foreach ($coll as $k => $related) {
if ($related->get($local) == $record[$identifier]) { $idField = $identifier[0];
if ($related->get($local) == $record[$idField]) {
$sub->add($related->get($name)); $sub->add($related->get($name));
} }
} }
......
...@@ -145,11 +145,7 @@ class Doctrine_Data_Export extends Doctrine_Data ...@@ -145,11 +145,7 @@ class Doctrine_Data_Export extends Doctrine_Data
} }
// skip single primary keys, we need to maintain composite primary keys // skip single primary keys, we need to maintain composite primary keys
$keys = $record->getTable()->getIdentifier(); $keys = (array)$record->getTable()->getIdentifier();
if ( ! is_array($keys)) {
$keys = array($keys);
}
if (count($keys) <= 1 && in_array($key, $keys)) { if (count($keys) <= 1 && in_array($key, $keys)) {
continue; continue;
......
...@@ -300,11 +300,7 @@ class Doctrine_Data_Import extends Doctrine_Data ...@@ -300,11 +300,7 @@ class Doctrine_Data_Import extends Doctrine_Data
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."); with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.");
$columns = array_keys($record->toArray()); $columns = array_keys($record->toArray());
$pks = $record->getTable()->getIdentifier(); $pks = (array)$record->getTable()->getIdentifier();
if ( ! is_array($pks)) {
$pks = array($pks);
}
foreach ($columns as $column) { foreach ($columns as $column) {
......
...@@ -344,11 +344,7 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable ...@@ -344,11 +344,7 @@ class Doctrine_Mapper extends Doctrine_Configurable implements Countable
public function getRecord(array $data) public function getRecord(array $data)
{ {
if ( ! empty($data)) { if ( ! empty($data)) {
$identifierFieldNames = $this->_classMetadata->getIdentifier(); $identifierFieldNames = (array)$this->_classMetadata->getIdentifier();
if ( ! is_array($identifierFieldNames)) {
$identifierFieldNames = array($identifierFieldNames);
}
$found = false; $found = false;
foreach ($identifierFieldNames as $fieldName) { foreach ($identifierFieldNames as $fieldName) {
......
...@@ -77,14 +77,14 @@ class Doctrine_Mapper_DefaultStrategy extends Doctrine_Mapper_Strategy ...@@ -77,14 +77,14 @@ class Doctrine_Mapper_DefaultStrategy extends Doctrine_Mapper_Strategy
$seq = $class->getTableOption('sequenceName'); $seq = $class->getTableOption('sequenceName');
if ( ! empty($seq)) { if ( ! empty($seq)) {
$id = $conn->sequence->nextId($seq); $id = $conn->sequence->nextId($seq);
$seqName = $class->getIdentifier(); $seqName = $identifier[0];
$fields[$seqName] = $id; $fields[$seqName] = $id;
$record->assignIdentifier($id); $record->assignIdentifier($id);
} }
$this->_insertRow($class->getTableName(), $fields); $this->_insertRow($class->getTableName(), $fields);
if (empty($seq) && count($identifier) == 1 && $identifier[0] == $class->getIdentifier() && if (empty($seq) && count($identifier) == 1 &&
$class->getIdentifierType() != Doctrine::IDENTIFIER_NATURAL) { $class->getIdentifierType() != Doctrine::IDENTIFIER_NATURAL) {
if (strtolower($conn->getName()) == 'pgsql') { if (strtolower($conn->getName()) == 'pgsql') {
$seq = $class->getTableName() . '_' . $identifier[0]; $seq = $class->getTableName() . '_' . $identifier[0];
......
...@@ -33,8 +33,9 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy ...@@ -33,8 +33,9 @@ class Doctrine_Mapper_JoinedStrategy extends Doctrine_Mapper_Strategy
} else if ($identifierType == Doctrine::IDENTIFIER_SEQUENCE) { } else if ($identifierType == Doctrine::IDENTIFIER_SEQUENCE) {
$seq = $record->getClassMetadata()->getTableOption('sequenceName'); $seq = $record->getClassMetadata()->getTableOption('sequenceName');
if ( ! empty($seq)) { if ( ! empty($seq)) {
$identifier = $conn->sequence->nextId($seq); $id = $conn->sequence->nextId($seq);
$dataSet[$parent][$parentClass->getIdentifier()] = $identifier; $identifierFields = (array)$parentClass->getIdentifier();
$dataSet[$parent][$identifierFields[0]] = $id;
$this->_insertRow($parentClass->getTableName(), $dataSet[$parent]); $this->_insertRow($parentClass->getTableName(), $dataSet[$parent]);
} }
} else { } else {
......
...@@ -1133,7 +1133,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -1133,7 +1133,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
if ($needsSubQuery) { if ($needsSubQuery) {
$subquery = $this->getLimitSubquery(); $subquery = $this->getLimitSubquery();
// what about composite keys? // what about composite keys?
$idColumnName = $table->getColumnName($table->getIdentifier()); $idFieldNames = (array)$table->getIdentifier();
$idColumnName = $table->getColumnName($idFieldNames[0]);
switch (strtolower($this->_conn->getDriverName())) { switch (strtolower($this->_conn->getDriverName())) {
case 'mysql': case 'mysql':
// mysql doesn't support LIMIT in subqueries // mysql doesn't support LIMIT in subqueries
...@@ -1198,7 +1199,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -1198,7 +1199,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
// get short alias // get short alias
$alias = $this->getTableAlias($componentAlias); $alias = $this->getTableAlias($componentAlias);
// what about composite keys? // what about composite keys?
$primaryKey = $alias . '.' . $table->getColumnName($table->getIdentifier()); $idFieldNames = (array)$table->getIdentifier();
$primaryKey = $alias . '.' . $table->getColumnName($idFieldNames[0]);
// initialize the base of the subquery // initialize the base of the subquery
$subquery = 'SELECT DISTINCT ' . $this->_conn->quoteIdentifier($primaryKey); $subquery = 'SELECT DISTINCT ' . $this->_conn->quoteIdentifier($primaryKey);
...@@ -1507,18 +1509,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -1507,18 +1509,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$assocAlias = $this->getTableAlias($assocPath, $asf->getTableName()); $assocAlias = $this->getTableAlias($assocPath, $asf->getTableName());
$queryPart = $join . $assocTableName . ' ' . $assocAlias; $queryPart = $join . $assocTableName . ' ' . $assocAlias;
$localTableIdFieldNames = (array)$localTable->getIdentifier();
$queryPart .= ' ON ' . $localAlias $queryPart .= ' ON ' . $localAlias
. '.' . '.'
. $localTable->getColumnName($localTable->getIdentifier()) // what about composite keys? . $localTable->getColumnName($localTableIdFieldNames[0]) // what about composite keys?
. ' = ' . ' = '
. $assocAlias . '.' . $relation->getLocal(); . $assocAlias . '.' . $relation->getLocal();
$tableIdFieldNames = (array)$table->getIdentifier();
if ($relation->isEqual()) { if ($relation->isEqual()) {
// equal nest relation needs additional condition // equal nest relation needs additional condition
$queryPart .= ' OR ' . $localAlias $queryPart .= ' OR ' . $localAlias
. '.' . '.'
. $table->getColumnName($table->getIdentifier()) . $table->getColumnName($tableIdFieldNames[0])
. ' = ' . ' = '
. $assocAlias . '.' . $relation->getForeign(); . $assocAlias . '.' . $relation->getForeign();
} }
...@@ -1535,19 +1539,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -1535,19 +1539,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
} }
$relationTable = $relation->getTable(); $relationTable = $relation->getTable();
$queryPart .= $this->_conn->quoteIdentifier($foreignAlias . '.' . $relationTable->getColumnName($relationTable->getIdentifier())) $relationTableIdFieldNames = (array)$relationTable->getIdentifier();
$queryPart .= $this->_conn->quoteIdentifier($foreignAlias . '.' . $relationTable->getColumnName($relationTableIdFieldNames[0]))
. ' = ' . ' = '
. $this->_conn->quoteIdentifier($assocAlias . '.' . $relation->getForeign()); . $this->_conn->quoteIdentifier($assocAlias . '.' . $relation->getForeign());
if ($relation->isEqual()) { if ($relation->isEqual()) {
$queryPart .= ' OR ' $queryPart .= ' OR '
. $this->_conn->quoteIdentifier($foreignAlias . '.' . $table->getColumnName($table->getIdentifier())) . $this->_conn->quoteIdentifier($foreignAlias . '.' . $table->getColumnName($tableIdFieldNames[0]))
. ' = ' . ' = '
. $this->_conn->quoteIdentifier($assocAlias . '.' . $relation->getLocal()) . $this->_conn->quoteIdentifier($assocAlias . '.' . $relation->getLocal())
. ') AND ' . ') AND '
. $this->_conn->quoteIdentifier($foreignAlias . '.' . $table->getColumnName($table->getIdentifier())) . $this->_conn->quoteIdentifier($foreignAlias . '.' . $table->getColumnName($tableIdFieldNames[0]))
. ' != ' . ' != '
. $this->_conn->quoteIdentifier($localAlias . '.' . $table->getColumnName($table->getIdentifier())); . $this->_conn->quoteIdentifier($localAlias . '.' . $table->getColumnName($tableIdFieldNames[0]));
} }
} }
} else { } else {
......
...@@ -536,10 +536,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -536,10 +536,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
case Doctrine::IDENTIFIER_AUTOINC: case Doctrine::IDENTIFIER_AUTOINC:
case Doctrine::IDENTIFIER_SEQUENCE: case Doctrine::IDENTIFIER_SEQUENCE:
case Doctrine::IDENTIFIER_NATURAL: case Doctrine::IDENTIFIER_NATURAL:
$name = $this->_table->getIdentifier(); $name = (array)$this->_table->getIdentifier();
if (is_array($name)) { $name = $name[0];
$name = $name[0];
}
if ($exists) { if ($exists) {
if (isset($this->_data[$name]) && $this->_data[$name] !== self::$_null) { if (isset($this->_data[$name]) && $this->_data[$name] !== self::$_null) {
$this->_id[$name] = $this->_data[$name]; $this->_id[$name] = $this->_data[$name];
...@@ -547,7 +545,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -547,7 +545,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
} }
break; break;
case Doctrine::IDENTIFIER_COMPOSITE: case Doctrine::IDENTIFIER_COMPOSITE:
$names = $this->_table->getIdentifier(); $names = (array)$this->_table->getIdentifier();
foreach ($names as $name) { foreach ($names as $name) {
if ($this->_data[$name] === self::$_null) { if ($this->_data[$name] === self::$_null) {
...@@ -581,7 +579,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -581,7 +579,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
unset($vars['_filter']); unset($vars['_filter']);
unset($vars['_node']); unset($vars['_node']);
$name = $this->_table->getIdentifier(); //$name = (array)$this->_table->getIdentifier();
$this->_data = array_merge($this->_data, $this->_id); $this->_data = array_merge($this->_data, $this->_id);
foreach ($this->_data as $k => $v) { foreach ($this->_data as $k => $v) {
...@@ -1005,7 +1003,9 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1005,7 +1003,9 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
if ( ! $rel->isOneToOne()) { if ( ! $rel->isOneToOne()) {
// one-to-many relation found // one-to-many relation found
if ( ! ($value instanceof Doctrine_Collection)) { if ( ! ($value instanceof Doctrine_Collection)) {
throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references."); throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second"
. " argument should be an instance of Doctrine_Collection when"
. " setting one-to-many references.");
} }
if (isset($this->_references[$name])) { if (isset($this->_references[$name])) {
$this->_references[$name]->setData($value->getData()); $this->_references[$name]->setData($value->getData());
...@@ -1019,10 +1019,13 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1019,10 +1019,13 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
// one-to-one relation found // one-to-one relation found
if ( ! ($value instanceof Doctrine_Record)) { if ( ! ($value instanceof Doctrine_Record)) {
throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Record or Doctrine_Null when setting one-to-one references."); throw new Doctrine_Record_Exception("Couldn't call Doctrine::set(),"
. " second argument should be an instance of Doctrine_Record"
. " or Doctrine_Null when setting one-to-one references.");
} }
if ($rel instanceof Doctrine_Relation_LocalKey) { if ($rel instanceof Doctrine_Relation_LocalKey) {
if ( ! empty($foreignFieldName) && $foreignFieldName != $value->getTable()->getIdentifier()) { $idFieldNames = (array)$value->getTable()->getIdentifier();
if ( ! empty($foreignFieldName) && $foreignFieldName != $idFieldNames[0]) {
$this->set($localFieldName, $value->rawGet($foreignFieldName), false); $this->set($localFieldName, $value->rawGet($foreignFieldName), false);
} else { } else {
$this->set($localFieldName, $value, false); $this->set($localFieldName, $value, false);
...@@ -1271,8 +1274,9 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1271,8 +1274,9 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
} }
if ($this->_table->getIdentifierType() == Doctrine::IDENTIFIER_AUTOINC) { if ($this->_table->getIdentifierType() == Doctrine::IDENTIFIER_AUTOINC) {
$i = $this->_table->getIdentifier(); $idFieldNames = (array)$this->_table->getIdentifier();
$a[$i] = $this->getIncremented(); $id = $idFieldNames[0];
$a[$id] = $this->getIncremented();
} }
if ($deep) { if ($deep) {
...@@ -1465,8 +1469,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1465,8 +1469,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$data = $this->_data; $data = $this->_data;
if ($this->_table->getIdentifierType() === Doctrine::IDENTIFIER_AUTOINC) { if ($this->_table->getIdentifierType() === Doctrine::IDENTIFIER_AUTOINC) {
$id = $this->_table->getIdentifier(); $idFieldNames = (array)$this->_table->getIdentifier();
$id = $idFieldNames[0];
unset($data[$id]); unset($data[$id]);
} }
...@@ -1519,7 +1523,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1519,7 +1523,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
$this->_data[$fieldName] = $value; $this->_data[$fieldName] = $value;
} }
} else { } else {
$name = $this->_table->getIdentifier(); $idFieldNames = (array)$this->_table->getIdentifier();
$name = $idFieldNames[0];
$this->_id[$name] = $id; $this->_id[$name] = $id;
$this->_data[$name] = $id; $this->_data[$name] = $id;
} }
...@@ -1734,7 +1739,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1734,7 +1739,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
->addWhere($rel->getForeign() . ' = ?', array_values($this->identifier())); ->addWhere($rel->getForeign() . ' = ?', array_values($this->identifier()));
if (count($ids) > 0) { if (count($ids) > 0) {
$q->whereIn($rel->getTable()->getIdentifier(), $ids); $relTableIdFieldNames = (array)$rel->getTable()->getIdentifier();
$q->whereIn($relTableIdFieldNames[0], $ids);
} }
$q->execute(); $q->execute();
...@@ -1802,7 +1808,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1802,7 +1808,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
->set($rel->getForeign(), '?', array_values($this->identifier())); ->set($rel->getForeign(), '?', array_values($this->identifier()));
if (count($ids) > 0) { if (count($ids) > 0) {
$q->whereIn($rel->getTable()->getIdentifier(), $ids); $relTableIdFieldNames = (array)$rel->getTable()->getIdentifier();
$q->whereIn($relTableIdFieldNames[0], $ids);
} }
$q->execute(); $q->execute();
...@@ -1815,7 +1822,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count ...@@ -1815,7 +1822,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
->set($rel->getLocalFieldName(), '?', $ids); ->set($rel->getLocalFieldName(), '?', $ids);
if (count($ids) > 0) { if (count($ids) > 0) {
$q->whereIn($rel->getTable()->getIdentifier(), array_values($this->identifier())); $relTableIdFieldNames = (array)$rel->getTable()->getIdentifier();
$q->whereIn($relTableIdFieldNames[0], array_values($this->identifier()));
} }
$q->execute(); $q->execute();
......
...@@ -336,14 +336,14 @@ class Doctrine_Relation_Parser ...@@ -336,14 +336,14 @@ class Doctrine_Relation_Parser
public function getIdentifiers($table) public function getIdentifiers($table)
{ {
$componentNameToLower = strtolower($table->getComponentName()); $componentNameToLower = strtolower($table->getComponentName());
if (is_array($table->getIdentifier())) { $idFieldNames = (array)$table->getIdentifier();
$columns = array(); if (count($idFieldNames) > 1) {
$columns = array();
foreach ((array) $table->getIdentifierColumnNames() as $identColName) { foreach ((array) $table->getIdentifierColumnNames() as $identColName) {
$columns[] = $componentNameToLower . '_' . $identColName; $columns[] = $componentNameToLower . '_' . $identColName;
} }
} else { } else {
$columns = $componentNameToLower . '_' . $table->getColumnName( $columns = $componentNameToLower . '_' . $table->getColumnName($idFieldNames[0]);
$table->getIdentifier());
} }
return $columns; return $columns;
...@@ -405,15 +405,6 @@ class Doctrine_Relation_Parser ...@@ -405,15 +405,6 @@ class Doctrine_Relation_Parser
$localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getClassName())); $localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getClassName()));
$localIdentifierColumnNames = $this->_table->getIdentifierColumnNames(); $localIdentifierColumnNames = $this->_table->getIdentifierColumnNames();
if ((count($localIdentifierColumnNames) - 1) < 0) {
echo $this->_table->getClassName();
var_dump($this->_table->getIdentifier());
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString() . "<br />";
}
}
$localIdColumnName = $localIdentifierColumnNames[count($localIdentifierColumnNames) - 1]; $localIdColumnName = $localIdentifierColumnNames[count($localIdentifierColumnNames) - 1];
$foreignIdentifierColumnNames = $def['table']->getIdentifierColumnNames(); $foreignIdentifierColumnNames = $def['table']->getIdentifierColumnNames();
$foreignIdColumnName = $foreignIdentifierColumnNames[count($foreignIdentifierColumnNames) - 1]; $foreignIdColumnName = $foreignIdentifierColumnNames[count($foreignIdentifierColumnNames) - 1];
......
...@@ -41,7 +41,7 @@ class Doctrine_Validator_Unique ...@@ -41,7 +41,7 @@ class Doctrine_Validator_Unique
public function validate($value) public function validate($value)
{ {
$table = $this->invoker->getTable(); $table = $this->invoker->getTable();
$pks = $table->getIdentifier(); $pks = (array)$table->getIdentifier();
if ( is_array($pks) ) { if ( is_array($pks) ) {
$pks = join(',', $pks); $pks = join(',', $pks);
......
...@@ -40,7 +40,8 @@ class Doctrine_Collection_Offset_TestCase extends Doctrine_UnitTestCase { ...@@ -40,7 +40,8 @@ class Doctrine_Collection_Offset_TestCase extends Doctrine_UnitTestCase {
$this->connection->setAttribute(Doctrine::ATTR_COLL_LIMIT, 1); $this->connection->setAttribute(Doctrine::ATTR_COLL_LIMIT, 1);
$users = $this->connection->query("FROM User-b, User.Phonenumber-o WHERE User.".$this->objTable->getIdentifier()." = 5"); $idFieldNames = (array)$this->objTable->getIdentifier();
$users = $this->connection->query("FROM User-b, User.Phonenumber-o WHERE User.".$idFieldNames[0]." = 5");
$this->assertEqual(count($users), 1); $this->assertEqual(count($users), 1);
......
...@@ -269,7 +269,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase ...@@ -269,7 +269,7 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
public function testCompositePK() { public function testCompositePK() {
$record = new EntityReference(); $record = new EntityReference();
$this->assertEqual($record->getTable()->getIdentifier(), array("entity1","entity2")); $this->assertEqual((array)$record->getTable()->getIdentifier(), array("entity1","entity2"));
$this->assertEqual($record->getTable()->getIdentifierType(), Doctrine::IDENTIFIER_COMPOSITE); $this->assertEqual($record->getTable()->getIdentifierType(), Doctrine::IDENTIFIER_COMPOSITE);
$this->assertEqual($record->identifier(), array("entity1" => null, "entity2" => null)); $this->assertEqual($record->identifier(), array("entity1" => null, "entity2" => null));
$this->assertEqual($record->state(), Doctrine_Record::STATE_TCLEAN); $this->assertEqual($record->state(), Doctrine_Record::STATE_TCLEAN);
......
...@@ -110,14 +110,16 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase ...@@ -110,14 +110,16 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase
$this->assertTrue($fk->getType() == Doctrine_Relation::ONE_AGGREGATE); $this->assertTrue($fk->getType() == Doctrine_Relation::ONE_AGGREGATE);
$this->assertTrue($fk->getLocal() == "email_id"); $this->assertTrue($fk->getLocal() == "email_id");
$this->assertTrue($fk->getForeign() == $fk->getTable()->getIdentifier()); $fkIdFieldNames = (array)$fk->getTable()->getIdentifier();
$this->assertTrue($fk->getForeign() == $fkIdFieldNames[0]);
$fk = $this->objTable->getTable()->getRelation('Phonenumber'); $fk = $this->objTable->getTable()->getRelation('Phonenumber');
$this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey); $this->assertTrue($fk instanceof Doctrine_Relation_ForeignKey);
$this->assertTrue($fk->getTable() instanceof Doctrine_ClassMetadata); $this->assertTrue($fk->getTable() instanceof Doctrine_ClassMetadata);
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY); $this->assertTrue($fk->getType() == Doctrine_Relation::MANY);
$this->assertTrue($fk->getLocal() == $this->objTable->getTable()->getIdentifier()); $objTableIdFieldNames = (array)$this->objTable->getTable()->getIdentifier();
$this->assertTrue($fk->getLocal() == $objTableIdFieldNames[0]);
$this->assertTrue($fk->getForeign() == 'entity_id'); $this->assertTrue($fk->getForeign() == 'entity_id');
......
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