[Flow] Fwd: Doctrine/Query notContains() for Collections

Alexander Berl a.berl at outlook.com
Fri Feb 14 17:37:51 CET 2014


Hey Georg,

there is a generic logicalNot method on the query object, which allows
to negate query constraints.

Hence your method would look something like this:

$query->logicalNot($query->contains('groups', $group));

Regards,
Alexander

Am 14.02.2014 17:06, schrieb Georg Tiefenbrunn:
> Hi Flow Gurus!
> 
> I'm trying to get to like TYPO3 Flow as I do love TYPO3 CMS but I'm
> stuck at many-to-many relations.
> 
> In my repository I created a custom findByXy() method to do some
> filtering. I use $query = $this->createQuery(); and not DQL to return
> a \TYPO3\Flow\Persistence\QueryResultProxy to be able to use
> pagination widget.
> 
> Let's assume I have a many-to-many relation between users and groups.
> After looking at the source I finally found the way to find all groups
> a user is assigned to:
> 
>   $query->contains('groups', $group);
> 
> But I can't find a way to query for all groups, a user isn't assigned
> to. It would be very nice to have
> 
>   $query->notContains('groups', $group);
> 
> The contains() function is defined in [1]
> 
>   public function contains($propertyName, $operand) {
>     return '(' . $this->getParamNeedle($operand) . ' MEMBER OF ' .
> $this->getPropertyNameWithAlias($propertyName) . ')';
>   }
> 
> So I tried a dirty hack and added notContains() and got what I was looking for.
> 
>   public function notContains($propertyName, $operand) {
>     return '(' . $this->getParamNeedle($operand) . ' NOT MEMBER OF ' .
> $this->getPropertyNameWithAlias($propertyName) . ')';
>   }
> 
> After looking at all the dependencies I got lost and decided to ask
> for help. Is there an easy way to use a custom/modified Query.php
> without implementing the whole Query/QueryResult/Repository/etc.
> stuff? Or is notContains() implemented somewhere else I'm simply too
> blind to see?
> 
> I wanted to ask before creating a silly feature request at the forge.
> 
> Thanks for any help you may be able to share!
> 
> Georg
> 
> [1] https://git.typo3.org/Packages/TYPO3.Flow.git/blob/HEAD:/Classes/TYPO3/Flow/Persistence/Doctrine/Query.php#l417
> 


More information about the Flow mailing list