[TYPO3-mvc] Fetching objects from repository having specific related objects

Elmar A. oxyfodu at googlemail.com
Fri Sep 10 18:39:37 CEST 2010


Hi

> Have you tried something like this?
> $query->in('subcategory1.collection.product', array('f','m'));
> (or whatever you have called the relations in TCA)

Now I did. But I don't even get the result I expect, I think because
collection <-> product is an n:m relationship.
But even if this would work, the problem would stay the same:
$category->getSubcategory() would still fetch ALL subcategories…

> Do you use lazy loading? I would guess that the related objects get

No.

>> - traversing all categories (in PHP Code), I could remove all
>> subcategories/collections etc. without products in question. But using
>> the Tx_Extbase_Persistence_ObjectStorage's detach method would persist
>> the changes (if I get the docs correctly)
>
> That's right. But you could create a simple array where you *insert* all
> objects you want to use.

But the array wouldn't be as simple: I have a complete tree of
objects: categories, subcategories and collections. Building this as
an array is error prone (and not necessary as OO exists), but building
Objects to just hold the information is to much work and not really
DRY.

I made a workaround now, a little bit like you suggested:

I have additional fields, e.g. in category it's filteredSubcategory,
which I return in case it's set, when getting the subcategory:

    public function getSubcategories() {
        if($this->filteredSubcategories instanceof
Tx_Extbase_Persistence_ObjectStorage) {
            return $this->filteredSubcategories;
        }

        return $this->subcategories;
    }

I set these "filtered" fields in the CategoryRepository: By fetching
all Categories, then traversing them all and select the objects I
want.

So it's transparent to the controller and especially the view.

Performancewise it's not great, as I fetch nearly all objects from the
database, but as the database is small, and the action is very good
cacheable this is an acceptable work-around.

Thanks for your help so far, Christian.

Elmar Athmer


More information about the TYPO3-project-typo3v4mvc mailing list