[TYPO3-mvc] extbase query - contains() and in()

Marc Bastian Heinrichs typo3 at mbh-web.de
Mon Jan 23 10:54:49 CET 2012

Hi Christian,

Am 20.01.12 12:00, schrieb Christian Essl:
> I have a model with a field named "tags" which contains an array of values.
> Now I want to find all objects by a list of tags, but there is a problem with the provided in() and contains()-methods.
> contains() searches a property-array for ONE value.
> In() searches a property for an ARRAY of values.
> But what I want is to search a property-array for an ARRAY of values. (where only one of the searched values would have to be true)
> Arrays on both sides. But how do I accomplish that?
> I could not find any functions for this purpose.
> For example, this wouldn't work because contains() excepts a plain value for the operand:
>   public function findByTags($tags)
>   {
>    // $tags = '1,2,3,4'
>     $tags = explode(',', $tags);
>     $query = $this->createQuery();
>     $query->matching(
>       $query->contains('tags', $tags)
>     );
>     return $query->execute();
>   }
> But my approach would be very similar to contains(). I only need to find all objects which have at least _one_ of the tags from $tags.

build an OR ($query->logicalOr()) with a contains for every tag

Marc Bastian

More information about the TYPO3-project-typo3v4mvc mailing list