Question: I am looping through products results, and if the product is a grouped product, I want to get all products in that group. I'm doing this:

```
$products = Mage::getModel('catalog/product')
                    ->getCollection()
                    ->addAttributeToSelect('*');
foreach ($products as $product) {
    if ($product->getTypeId() == 'grouped'){
        // how do I now get associated products of $product?
    }
}

```

Answer: 
Or if you want just to get ids of associated products, you can use the following method (it is much faster):  

```
public function getAssociatedProductIds($groupedProductId)
{
    $coreResource = Mage::getSingleton('core/resource');
    $conn = $coreResource->getConnection('core_read');
    $select = $conn->select()
        ->from($coreResource->getTableName('catalog/product_relation'), array('child_id'))
        ->where('parent_id = ?', $groupedProductId);

    return $conn->fetchCol($select);
}

```
To get product collection by type:

```
$product = Mage::getModel('catalog/product')
   ->getCollection()
   ->addAttributeToFilter('type_id', array('eq' => 'grouped'))
   ->load();

$parentProductId = array();

foreach($product as $simpleProducts) {
  $simpleProducts->loadParentProductIds();
  array_push($parentProductId,$simpleProducts->getParentProductIds();
}

```