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

Elmar A. oxyfodu at googlemail.com
Fri Sep 10 14:45:35 CEST 2010


Hi

I'm currently creating my first Extbase Typo3 Extension. I'm a little
bit stuck at querying some data.

The relevant parts of my domain model look like this (in pseudo-ascii-uml):

Category 1 <---- * Subcategory 1 <---- * Collection * <----- * Product

Now, I want to fetch all categories (and subcategories, collections)
with products whose property "gender" is set to "f" or "m".

In SQL this is query is a join on all four tables (and the
collection_product_mm table), which works also with the query
statement() method.

If I'm now iterating on the result-set (of categories), e.g. in a
(Fluid-) template, all subcategories, collections etc. are being
displayed, too - independently of the products (and their
gender-property).

This seems to be sensible as I'm using e.g.
$categories->getSubcategories() and it brings me ALL subcategories of
the category, no only the subcategories from the original query.

I can't really think of a good way to solve this problem:
- I could check in the template if I want to output a
category/collection etc., but the decision WHAT to display belongs to
the controller IMO
- 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)
- best solution I could think of so far, is to reconstruct the object
tree with just the objects in question - but this would be error prone
or at least a lot of work.

Is there no better way to do this, or am I missing something?

Thanks in advance

Elmar Athmer


More information about the TYPO3-project-typo3v4mvc mailing list