Discussion:
[TYPO3-english] extbase, custom queries and intersection table
Éric Thibault
2017-10-26 20:23:47 UTC
Permalink
Hello to all!

I need some help in using the query API inside my extbase plugin. Here is my situation:

1. We have 3 tables, events, categories an events-categories (intersection table n-m relation)
2. We can filter the events by categories via flexform field

When we shoose multilple categories to filter, our constraint is relatively straightforward, retrieving all events that have at least one of the categories:

$uidlist = explode(',', $settings['categories']);
$constraints[] = $query->in('categorie.uid', $uidlist);//matches all events with a least one category in the list

It's fine if we want an OR but what can we use if we want all categories that have all our chosen categories? If we want an AND?

We've tried a foreach loop :

$uidlist = explode(',', $settings['categories']);
foreach($uidlist AS $categorie) {
$constraintsAND[] = $query->equals('categorie.uid', intval($categorie));//match all events with a specific category
}
$constraints[] = $query->logicalAnd($constraintsAND);

But no events are returned even if our test event has all the categories selected!

I'm lost here so if someone can shed a little light I would be eternaly gratefull!

Thank you a million times!

Eric Thibault
Mikel
2017-10-27 07:26:11 UTC
Permalink
Hi,

you can use „contains" or „in".

Like:

$query = $this->createQuery();
$query->matching(
$query->logicalAnd(
$query->contains('categories', $categories)
)
);
return $query->execute();
or

$query = $this->createQuery();
$query->matching(
$query->logicalAnd(
$query->in('categories', explode(',', $categories))
)
);
return $query->execute();
Mikel
Mikel
2017-10-27 13:29:57 UTC
Permalink
Nachtrag: Gibt Dein Installtool hier nichts aus, wenn Du einen Compare der Datenbank ausführst?
Ohne die Anzeige des Fehlers ist eine Fehlersuche ja recht mühselig...
Loading...