hi for the first part, use this .....
$c = new Criteria(); $c->addJoin(ProductPeer::CATEGORY_ID, CategoryPeer::ID); $c->setDistinct(); $categories = CategoryPeer::doSelect($c); now the $categories variable contains the categories that have at least one product On Tue, Dec 1, 2009 at 5:58 AM, Gareth McCumskey <gmccums...@gmail.com>wrote: > First, you will always have a category with at least one product because > you have set cascade on delete. > > For the second part, in your CategoryPeer class: > > public static function getProductCountPerCategory() > { > //Get all categories > $category_obj_arr = self::doSelect(new Criteria()); > > //Get count of products per category > $product_per_category_count = array(); > > foreach ($category_obj_arr as $category_obj) > { > $product_c = new Criteria(); > $product_c->add(ProductPeer::CATEGORY_ID, $category_obj->getId()); > $product_per_category_count[$category_obj->getTitle()] = > ProductPeer::doCount($product_c); > } > > return $product_per_category_count; > } > > Thats one example. You don't always have to do everything in a query using > joins and to be honest we have often seen massive performance improvements > NOT using switching away from joins. > > > On Tue, Dec 1, 2009 at 2:56 PM, g0d br <g0d...@gmail.com> wrote: > >> Hi, >> >> I dont even know how to ask that but i want to show what i need. >> >> my schema.yml >> category: >> id: ~ >> title: { type: varchar(100), required: true, index: unique } >> >> product: >> id:~ >> category_id: { type: integer, foreignTable: category, foreignReference: >> id, onDelete: cascade } >> name: { type: varchar(100), required: true, index: unique } >> >> i want to retrieve all categories that have a least one product and i want >> to show how many products each category. >> >> thank you. >> >> Celso >> >> ps. sorry about my english i dont know if the question is understandable. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "symfony users" group. >> To post to this group, send email to symfony-us...@googlegroups.com. >> To unsubscribe from this group, send email to >> symfony-users+unsubscr...@googlegroups.com<symfony-users%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/symfony-users?hl=en. >> > > > > -- > Gareth McCumskey > http://garethmccumskey.blogspot.com > twitter: @garethmcc > > -- > You received this message because you are subscribed to the Google Groups > "symfony users" group. > To post to this group, send email to symfony-us...@googlegroups.com. > To unsubscribe from this group, send email to > symfony-users+unsubscr...@googlegroups.com<symfony-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/symfony-users?hl=en. > -- Regards, Dheeraj -- You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-us...@googlegroups.com. To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en.