Ok, thank you very much! All are working right! But I have another question. Now my result looks like: Array ( [0] => Array ( [Vendor] => Array ( [name] => Sony )
[0] => Array ( [count] => 10 ) ) ... ) Is it possible to move [count] from [0] to [Vendor]? Current result's array structure is not useful for Views On Apr 27, 1:47 pm, thequietlab <[EMAIL PROTECTED]> wrote: > ahh.. and if you want to sort it then, just : > > $this->Vendor->bindModel(array('hasOne'=>array('Model'))); > $fields = array('Vendor.id','COUNT(Model.vendor_id)'); > $conditions = 'GROUP BY Vendor.id'; > $order = 'COUNT(Model.vendor_id) DESC'; > $this->Vendor->findAll( $conditions, $fields, $order ); > > On Apr 27, 9:44 am, thequietlab <[EMAIL PROTECTED]> wrote: > > > hey guys, > > > try this : > > > $this->Vendor->bindModel(array('hasOne'=>array('Model'))); > > $fields = array('Vendor.id','COUNT(Model.vendor_id)'); > > $conditions = 'GROUP BY Vendor.id'; > > $this->Vendor->findAll( $conditions, $fields ); > > > This should make a query like this : > > > SELECT `Vendor`.`id`, COUNT(`Model`.`vendor_id`) FROM `vendors` AS > > `Vendor` LEFT JOIN `models` AS `Model` ON (`Model`.`vendor_id` = > > `Vendor`.`id`) WHERE 1=1 GROUP BY `Vendor`.`id` > > > Hope it helps > > > On Apr 26, 7:22 pm, rtconner <[EMAIL PROTECTED]> wrote: > > > > Yeah I'm wondering this also. Is there a cake way of going this? Get > > > some sort of count(*)/GROUP BY select using cake associations? > > > > On Apr 26, 8:50 am, Alexey Kuimov <[EMAIL PROTECTED]> wrote: > > > > > Hello. I'm a beginner in CakePHP and have a question: > > > > > I have two tables: Vendors (id, name) and Models (id, vendor_id, > > > > name). Could somebody tell me how to get in query result Vendors names > > > > and a number of their Model. Also I need sort result by Vendors names > > > > or by a number of Models. Now I'm using hasMany association and count > > > > Models in my controller. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---