Yes, see http://book.cakephp.org/view/449/find for how to use the GROUP condition! Enjoy, John
On Jun 1, 5:43 pm, glastoveteran <[email protected]> wrote: > Hi CakePHP gurus... > > I'm trying to suss out the GROUP BY functions in cake and I'm hoping > for a couple of pointers. > > In my app I have the following relationship - Vehicle hasMany Image > and Image belongsTo Vehicle. > > CREATE TABLE `images` ( > `id` int(11) NOT NULL auto_increment, > `filename` varchar(255) NOT NULL default '', > `vehicle_id` int(11) default NULL, > PRIMARY KEY (`id`) > ); > > CREATE TABLE `vehicles` ( > `id` int(11) NOT NULL auto_increment, > `name` varchar(255) NOT NULL default '', > PRIMARY KEY (`id`) > ); > > What I'd like to do is use GROUP BY to get a complete list of vehicles > with a count of images for that vehicle, even if it's none. > > The raw SQL it would be something like this (but this won't take into > account vehicles with no images): > > SELECT COUNT(*), vehicles.name FROM images LEFT OUTER JOIN vehicles ON > images.vehicle_id = vehicles.id GROUP BY images.vehicle_id; > > Any ideas how to do what I'm trying to achieve with find and group? > > Thanks all, > > Alex --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
