[TYPO3-mvc] Concrete Table Inheritance

Christian Kartnig office at hahnepeter.de
Sat May 3 10:55:54 CEST 2014


Hey Eike,

Thanks for your answer. Clever approach!
I settled for Single Table inheritance now, but thanks anyway!

best regards,
Christian


Am 29.04.14 13:03, schrieb Eike Starkmann:
> BTW, you can also write a Hook that your SQL View is created when the
> extension is installed, because you can not declare views in your
> ext_tables.sql.
>
> That looks like this, assuming your view definition is located at
> Configuration/SQL:
>
> namespace TYPO3\Publications\Hooks;
>
> class PostInstallHook {
> 	
> 	const EXTKEY = 'publications';
> 	
> 	public function updateView() {
> 	
> if(@file_exists(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::EXTKEY)
> . 'Configuration/SQL') &&
> @is_dir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::EXTKEY)
> . 'Configuration/SQL')) {
> 			// GET all *.sql Files in Configuration/SQL folder
> 			$sqlFiles =
> \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::EXTKEY)
> . 'Configuration/SQL', 'sql', TRUE);
> 			// run those files in DB
> 			foreach ($sqlFiles as $sqlFile) {
> 				$sql = file_get_contents($sqlFile);
> 				$GLOBALS['TYPO3_DB']->sql_query($sql);
> 			}
> 		}
> 	}
> }
>
>
> Regards, Eike
>
> On 29.04.2014 12:53, Eike Starkmann wrote:
>> Hi Christian,
>>
>> lest say you have a table "publication" and you have the table "news".
>> And both classes should inherit from a class item. So item would be a
>> view that unions both tables. The advantage of a view is that if e.g new
>> publication are created they are immediately available in the table
>> item. BUT you have to take care that the uids are unique here is an example:
>>
>> CREATE OR REPLACE VIEW tx_publications_domain_model_item AS SELECT
>> 	((uid * 2) + 1) AS uid,
>> 	uid AS original_uid,
>> 	title AS title,
>> 	teaser AS teaser,
>> 	...
>> FROM tx_publications_domain_model_publication
>> UNION SELECT
>>   	(uid * 2) AS uid,
>> 	uid AS original_uid,
>> 	title AS title,
>> 	teaser AS teaser,
>> 	...
>> FROM tx_news_domain_model_news WHERE no_publication = '0';
>>
>> Regards, Eike
>>
>> P.S.: Please try to also replay to list. (Had to copy your email)
>>
>>
>>> Hi Eike,
>>>
>>> thanks for your answer!
>>> For your workaround you needed to write native SQL statements, right?
>>> I thought about doing that with UNION queries. How would you do that
>>> with a view?
>>
>>> best regards,
>>> Christian
>>> On 28.04.2014 15:48, Eike Starkmann wrote:
>>> Hi Christian,
>>>
>>> concrete table inheritance is not possible in extbase out of the box, as
>>> far as i know.
>>>
>>> I once had the same problem and did a workaround via a sql view:
>>>
>>> Every table has its own class, and supertables are view(joins) of other
>>> subtables.
>>>
>>> Works nice and you can use class inheritance.
>>>
>>> Regards, Eike
>>>
>>> On 28.04.2014 14:56, Christian Kartnig wrote:
>>>> Hi there,
>>>>
>>>> I just wanted to ask if Concrete Table Inheritance exists in Extbase
>>>> (yet)? The extbase book says yes, but I didn't find any information on
>>>> how to set it up. Everywhere there is only Single Table Inheritance
>>>> described.
>>>>
>>>> I just want every subclass to have its own table. I tried to add
>>>> "extends" statements in the php model classes of the subclasses, but
>>>> that obviously isn't enough.
>>>>
>>>> Can somebody please throw a light on this mystery?
>>>>
>>>> Thanks a lot,
>>>> Christian
>>>
>>
>



More information about the TYPO3-project-typo3v4mvc mailing list