[TYPO3-mvc] Help needed for DISTINCT using QOM
Franz Koch
typo3.RemoveForMessage at elements-net.de
Thu Apr 21 23:43:03 CEST 2011
Hey,
> With extbase 1.2, we could do the code above. However $query->statement does not seem to work well with extbase 1.3. Basically, when I loop in the template, it appears to be the same record at every loop.
>
> public function findAllCountries() {
> $query = $this->createQuery();
> $query->statement('SELECT DISTINCT country FROM tx_typo3agencies_domain_model_agency');
> return $query->execute();
> }
How should that work? This query will only return the "country" field
form the DB. And because you're actually querying for agency models
Extbase tries to build agency objects out of the result which will of
course drastically fail (I guess there should be a exception when the
UID field is missing in the result row).
> Found a solution with:
>
> $query->getQuerySettings()->setReturnRawQueryResult(TRUE);
Yes, that's the correct solution for this use case. You only like to
receive certain db fields and not objects, thus you have to tell the QOM
to return the raw query result and not mapped objects. No need for the
other hack using the storageBackend you referred to.
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list