[TYPO3-mvc] Query constraints using MM relations

Franz Kugelmann franz.kugelmann at elementare-teilchen.de
Wed Aug 10 12:18:23 CEST 2011


> Hey Jacob,
>
>> But I would like to make a custom filter in the Domain Repository for
>> Tx_Churchbase_Bygning, so I added a method in the repository class:
>>
>> public function findBySogne() {
>> return $query->matching(
>> $query->in('sogne', array(1, 2))
>> )->execute();
>>
>> }
> ...
>> Btw. sorry for the long post
>
> long post, short answer.
>
> $query->in('sogne.uid', array(1, 2))
>
> Try this, should do the trick, but probably the way you tried it should  
> also work.

Hi Franz,

that is exactly the trick i search for, thanks a lot!
Very useful if you want to select categories in the plugin Flexform (where  
you only have the uids and not the whole objects) and filter for the  
selected categories in your Repository.
Here our code in case someone is looking for the same thing, if you want  
to combine selection fields in the flexform, just collect the constraints  
in an array first:


if ($settings['flexform']['categories']) {
   $constraints[] =  
$query->in('categories.uid',explode(',',$settings['flexform']['categories']));
}
if (count($constraints)) {
   $query = $query->matching($query->logicalAnd($constraints));
}

Greetings!
Franz
-- 
Franz Kugelmann, www.elementare-teilchen.de


More information about the TYPO3-project-typo3v4mvc mailing list