Q:

TYPO3 relation query - relational fluid rendering

I have a nested for loop in my fluid. 
First for print all Parent Items. 
the nested for loop should print all child elements related to the parent Item. 
But the child loop dosn't work ... how should this look like? 
I Have The Model Modul 
and The Model Fach
and there is a 1:n Relation From Fach to Modul
And I Want to print a list like this:
Modul A
 - Fach 1
 - Fach 2
Modul B
 - Fach ysd

A:

For starters, if there is a relation between the objects "modules" and "fachs" there is no need to call two separate "findAll" methods.  It is enougth to just call
$moduls = $this->modulRepository->findAll();

Extbase will get the relation between the two objects for you. 
Your template should look like this (I don't know the property names, but you should get the context here):
<f:for each="{moduls}" as="modul"> 
    {module.name}
    <f:for each="{modul.fachs}" as="fach"> 
       {fach.fachname} 
    </f:for> 
</f:for>

The output of this should give the results you are looking for. 
Regarding your filtering question.  You should only get the data you from your database.  So the best way to do this is your repository. 
Depending on the kind of filtering you want to do there might be different options.  But in general I would always go for the repository first.  And maybe do some additional stuff after that.