[TYPO3-mvc] Abstract Classes and the DB

Zalán Somogyváry zalan at gmx.net
Tue May 17 15:20:39 CEST 2011


Hello list,

Am 16.05.2011 um 08:06 schrieb Franz Koch:

> Hey,
> 
>> The error I get is:
>> Fatal error: Cannot instantiate abstract class Tx_TuBaCore_Domain_Model_MediaItem in /path/to/typo/typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php on line 224
> 
> well, don't delcare your "AbsstractMediaItem" as "abstract" then - I knew there was at least one issue I stumbled across with abstract classes. Currently there's unfortunately no other fix for this then dropping the "abstract" declaration, except you like to rewrite some parts in Extbase.


I've debugged and debugged and in the end i've found the following reason:

In the Class Tx_Extbase_Persistence:Mapper_DataMapper the following method
 public function getTargetType($className, array $row) {
00180         $dataMap = $this->getDataMap($className);
00181         $targetType = $className;
00182         if ($dataMap->getRecordTypeColumnName() !== NULL) {
00183             foreach ($dataMap->getSubclasses() as $subclassName) {
00184                 $recordSubtype = $this->getDataMap($subclassName)->getRecordType();
00185                 if ($row[$dataMap->getRecordTypeColumnName()] === $recordSubtype) {
00186                     $targetType =  $subclassName;
00187                     break;
00188                 }
00189             }
00190         }
00191         return $targetType;
00192     }
does check for a subclass so you can do things like this with Extbase:

			AbstractMediaItem
				/		\
		ConcreteItem	ConcreteItem2

but you can't do things like this:

			AbstractMediaItem
				/			\
		AbstractStream	AbstractFile
			/					\
	ConcreteClass1		ConcreteClass2

because this method only gets the subclasses once instead of iterating on until the next non abstract class is found (this could be handled by the name of the class???). I will issue a feature request for this. Thank for every feedback!

Best regards,
Zalán Somogyváry


More information about the TYPO3-project-typo3v4mvc mailing list