[TYPO3-dev] extbase and SQL functions

Xavier Perseguers xavier at typo3.org
Tue May 31 11:15:20 CEST 2011


Hi,

> <?php
> class Tx_Newsletter_Domain_Repository_EmailRepository extends
> Tx_Newsletter_Domain_Repository_AbstractRepository {
>      public function findByAuthcode($authcode) {
>          $query = $this->createQuery();
>          $query->setLimit(1);
>          $c = $query->equals('md5(concat(`uid`, `recipient_address`))',
> $authcode);
>          $query->matching($c);
>          return $query->execute()->getFirst();
>      }
> }
>
>
> I debugged the whole thing and figured out that
> sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php will
> enventually append tablename to any function used. So the query executed
> will be similar to:
> SELECT tx_newsletter_domain_model_email.* FROM
> tx_newsletter_domain_model_email WHERE
> tx_newsletter_domain_model_email.md5(concat(`uid`, `recipient_address`)) =
> 'abc';
>
> instead of :
> SELECT tx_newsletter_domain_model_email.* FROM
> tx_newsletter_domain_model_email WHERE md5(concat(`uid`,
> `recipient_address`)) = 'abc';
>
> I can't find any way to change this behavior and inheriting seems very heavy
> (involving inheriting Typo3DbBackend and probably implementing another
> Tx_Extbase_Persistence_QOM_SelectorInterface).

I'd say authorizing this would imply some huge refactoring and is not 
DDD-wise as you try to inject SQL code whereas you should only deal with 
field names.

> Did I miss an obvious way to achieve this simple goal ?

Either switch to pure SQL and do not use query building from Extbase or 
add an extra column with the computed value and then use it as any other 
standard field.

HTH

-- 
Xavier Perseguers
Release Manager TYPO3 4.6

TYPO3 .... inspiring people to share!
Get involved: http://typo3.org





More information about the TYPO3-dev mailing list