From 07b5727c52b2255cefc8166e093aeb674d26709a Mon Sep 17 00:00:00 2001 From: zYne Date: Sat, 1 Sep 2007 16:11:58 +0000 Subject: [PATCH] severe export bug fix: classes using column aggregation inheritance not properly exported --- lib/Doctrine/Export.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index 4746ba636..a56a96d2d 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -1042,20 +1042,31 @@ class Doctrine_Export extends Doctrine_Connection_Module // check if class is an instance of Doctrine_Record and not abstract // class must have method setTableDefinition (to avoid non-Record subclasses like symfony's sfDoctrineRecord) - if ($class->isSubclassOf($parent) && ! $class->isAbstract() && $class->hasMethod('setTableDefinition') - && $class->getMethod('setTableDefinition')->getDeclaringClass()->getName() == $class->getName()) { - $record = new $name(); - $table = $record->getTable(); - $data = $table->getExportableFormat(); - - $query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']); + // we have to recursively iterate through the class parents just to be sure that the classes using for example + // column aggregation inheritance are properly exporterd to database + while ($class->isAbstract() && + ! $class->isSubclassOf($parent) && + ! $class->hasMethod('setTableDefinition') && + $class->getMethod('setTableDefinition')->getDeclaringClass()->getName() !== $class->getName()) { - if (is_array($query)) { - $sql = array_merge($sql, $query); - } else { - $sql[] = $query; + $class = $class->getParent(); + + if ($class === null) { + break; } } + + $record = new $name(); + $table = $record->getTable(); + $data = $table->getExportableFormat(); + + $query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']); + + if (is_array($query)) { + $sql = array_merge($sql, $query); + } else { + $sql[] = $query; + } } $sql = array_unique($sql); rsort($sql);