cachingtypo3filereferencefal

TYPO3 cache behaviour with updated models


I have this weird behaviour from Typo3 6.2 LTS. In my extension I have a Model with a FileReference Property. This property has a vaule != 0. This value does exist in sys_file_reference table.

Not the weird magic happens. If I try to access this file, I do only get a nullvalue instead of a FileReference- / FileObject.

We already cleared our cache (server and browser) but nothing. It's still null.

I appreciate every kind of help!

Greetz, Paddaels


Solution

  • I remember it was always hard to make a 1:1 relation from a domain model to a FileReference. I suggest you to use existing patterns and work with a ObjectStorage for that purpose.

    You can copy the neccessary TCA from the existing tca of the tt_content table (field image for example). The Property annotation should look like:

    /**
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Extension\Domain\Model\FileReference>
     * @lazy
     * @cascade remove
     */
     protected $propName;
    

    Of course you have to create the FileReference Model in your own namespace. But you can extend the Extbase basemodel, so you dont have to write any methods.

    To map your model to the sys_file_reference table you have to add some typoscript.

    For that purpose create a ext_typoscript_setup.txt in your extensions folder and insert the following code (adjust namespace and modelname)

    config.tx_extbase.persistence.classes {
        Vendor\Extension\Domain\Model\FileReference.mapping {
            tableName = sys_file_reference
        }
    }
    

    After clearing the caches in the install tool (and making database migrations of course) it should work.

    Explanations:

    @lazy: Typo3 wont fetch all references at once, only if the property is accessed.

    @cascade remove: Extbase will delete all sys_file_reference records related to your domain model once the model is deleted.