Hey there, there doesn't really seem to be a clean way with Propel 1.2, but a possible solution isn't too complex.
CO2 schrieb: > I have trouble finding a good solution to the following tasks: > > Schema 1: > item: > id: > customer: > item_id: > > I need to output a list of customers with assigned items: > > customer1 > itemA > itemB > customer2 > itemC > > Of course I can retrieve customers and items in two arrays and do some > dirty stuff in the action or template using php but I know there are > better solutions. Something's wrong with your schema and the output you are looking for, since each customer can have only one item assigned. Anyway, suppose your schema looks like this: item: customer_id: customer: id: you can build a criteria, fetch the rows and then manually loop through the resultset adding the items to the customers as you go. Something like this: $c = new Criteria(); $c->addJoin(CustomerPeer::ID, ItemPeer::CUSTOMER_ID); $rs = CustomerPeer::doSelectRs($c); $customers = array(); while ($rs->next()) { $customer = new Customer(); $id = $rs->getInt(1) if (!isset($customers[$id])) { $customer->hydrate($rs); $customers[$id] = $customer; } $item = new Item(); $item->hydrate($rs, CustomerPeer::NUM_COLUMNS); $customers[$id]->addItem($item); } > > ------------------------------------- > Schema2: > > user: > id: > group: > id: > user_in_group: > user_id: > group_id: > > Users can be memebers of multiple groups. I need to output a list of > groups with assigned users: > group1 > userA > userB > group2 > userB > userC > > Again I'm looking for a better solution than getting two array and > going through them in several loops ;-) > Sorry for posting very basic questions more related to db queries than > symfony but I will have to find a solution to use within symfony right > away. Should work quite similar to the 1:n case with a slightly different JOIN condition. Cheers, Georg > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---