lufi
lufi

Reputation: 670

Using Concat in TYPO3 Extbase Query

i am struggling a little challenge and i am wondering what the solution might be as I couldn't find an answer in the documentation.

Here is my current working query (part):

$constraints[] = $query->like('kategorie', '%'.$kategorie.'%');

What I want to do is something like:

$constraints[] = $query->like(CONCAT(',', kategorie, ','), '%,'.$kategorie.',%');

Which obviously doesn't work at all. : -)

Every Help is really appriciated. Hope someone know the right syntax. TYPO3 Version is latest 6.1

Thank's alot!

Upvotes: 2

Views: 1152

Answers (1)

lorenz
lorenz

Reputation: 4558

First of all, Extbase query generation didn't change in 6.0, so it's the same for 4.x and 6.x.

Maybe you misunderstand the way Extbase is builing the query.

$query->like('property', '%value%');

will return an object when %value% is contained in "property". Such a property must be defined in the domain model. You can only query properties that have a "getProperty" method in their domain model.

Looking at your code, I think you're finding a way to query for a value being present in a comma-separated value list? Then you would use

$query->in('kategorien', $kategorie);

EDIT:

Your specific problem seems to be that you are not using a true relation for assigning "Kategorien" to your entity. You're using a comma-separated list to hold references to another model. You're discouraged to do so, but it is technically possible and used in the TYPO3 core: The FrontendUser model has a property "usergroup" that works in the same way.

Please have a look at the FrontendUser model: https://git.typo3.org/Packages/TYPO3.CMS.git/blob/HEAD:/typo3/sysext/extbase/Classes/Domain/Model/FrontendUser.php

The annotation of your Kategorien must be correct, e.g.:

/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\My\Extension\Domain\Model\Kategorien>
*/
protected $kategorien;

Also make sure that getKategorien is correct.

If you still have problems, keep in mind that the TCA definition must be working to have Extbase work correctly.

In my opinion, a best practise would be to use the category API introduced in TYPO3 6.0: http://wiki.typo3.org/TYPO3_6.0#Category

Upvotes: 2

Related Questions