[TYPO3-mvc] Using SQL count function in ExtBase query

Daniel Dimitrov danielsd_bg at yahoo.fr
Wed Aug 18 16:28:54 CEST 2010


Hey Michael,

"Michael Knoll" <mimi at kaktusteam.de> wrote in message 
news:mailman.1.1282135536.26931.typo3-project-typo3v4mvc at lists.typo3.org...
> Hi there,
>
> I would like to do a query like
>
>
> SELECT group.name, count(*) as row_count FROM users
> JOIN group ON users.group_id = group.id
> GROUP BY group.id
>
> (might not be syntactically correct, but I hope you get the idea).
>
> Is there any possibility to do that with extbase query object?
>
> The only workaround I can think of would be to select all groups first and 
> then do a count using group ID for each record what would end up with lots 
> of queries sent to the database...
>
What I did for my project was - I created my own count function in the 
repository like this:

	public function count($cat = 0, $kws = array()) {
		$query = $this->createQuery();

		$match = null;

		if($kws) {
			if($match) {
				$match = $query->logicalAnd($match, $query->equals('keywords.uid', 
$kws));
			} else {
				$match = $query->equals('keywords.uid', $kws);
			}
		}

		return $query->matching($match)->count();
	}

in the same way - you could create your own count function and just call it 
with
$myrepository->count(); and it will return what you need.


>
> Thanks for your help!
>
>
> Greetings
>
> MImi


Kind regards,
Daniel 



More information about the TYPO3-project-typo3v4mvc mailing list