[TYPO3-mvc] $query-count() bei suche mit JOIN / Sortierung deutscher Wörter

Cornelius Illi cornelius.illi at student.hpi.uni-potsdam.de
Tue Aug 10 08:40:18 CEST 2010


  Am 09.08.2010 17:40, schrieb Martin Kutschker:
> Am 09.08.2010 10:53, schrieb Illi, Cornelius:
>> I added some code to the getObjectCountByQuery() method in Typo3DbBackend.php:
>>
>> 		if( !isset($statementParts['keywords']['distinct']) ) {
>> 			$statementParts['fields'] = array( 'COUNT(*)' );
>> 		} else {
>> 			$className = $query->getSource()->getNodeTypeName();
>> 			$tableName = $this->dataMapper->getDataMap($className)->getTableName();
>> 			$statementParts['fields'] = array( 'COUNT(DISTINCT '.$tableName.'.uid)' );
>> 			unset( $statementParts['keywords']['distinct'] );
>> 		}
> Why is the COUNT() in the two clauses different (* vs<table>.uid)?
If you join tables that are connected through a 1-M-relation, you end up 
getting the same object listed serveral times (as often as it has 
another join-partner).
So the count(*) would return all join-possibilities, but not the number 
of differnet/distinct objects, therefore it is necessary to provide a 
new solution.
> Masi
>
> PS: What about the proposals to allow tables without a uid column?
The UID-column has to be used by convention ("Convention over 
Configuration"). It does no harm having it, doesn't it?

Cornelius
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc



More information about the TYPO3-project-typo3v4mvc mailing list