smitrovic
smitrovic

Reputation: 461

TYPO3 Extbase query with JOIN

I have table items, and table item_categories. Every Item can have more than one category. I have created Extbase extension with those two models. I want to filter items by category, how can I create query for that? It should look like this:

LEFT JOIN item_categories ON items.uid = item_categories.item_uid

Upvotes: 0

Views: 2285

Answers (1)

lorenz
lorenz

Reputation: 4558

You have to create an own query in your itemsRepository:

protected function findByCategory($category) {
  $query = $this->createQuery();
  $query->matching(
    $query->contains('category', $category)
  );
  return $query->execute();
}

This will return all items with at least the given category, assuming that you have an 1:n relation between items and category.

Upvotes: 1

Related Questions