/**
  * Update relation products
  *
  * @param int $storeId
  * @param int|array $productIds Update child product(s) only
  * @return Enterprise_Catalog_Model_Index_Action_Product_Flat_Refresh
  */
 protected function _updateRelationProducts($storeId, $productIds = null)
 {
     if (!$this->_productHelper->getFlatHelper()->isAddChildData() || !$this->_isFlatTableExists($storeId)) {
         return $this;
     }
     foreach ($this->_getProductTypeInstances() as $typeInstance) {
         if (!$typeInstance->isComposite()) {
             continue;
         }
         $relation = $typeInstance->getRelationInfo();
         if ($relation && $relation->getTable() && $relation->getParentFieldName() && $relation->getChildFieldName()) {
             $columns = $this->_productHelper->getFlatColumns();
             $fieldList = array_keys($columns);
             unset($columns['entity_id']);
             unset($columns['child_id']);
             unset($columns['is_child']);
             $select = $this->_connection->select()->from(array('t' => $this->_productHelper->getTable($relation->getTable())), array($relation->getParentFieldName(), $relation->getChildFieldName(), new Zend_Db_Expr('1')))->join(array('e' => $this->_productHelper->getFlatTableName($storeId)), "e.entity_id = t.{$relation->getChildFieldName()}", array_keys($columns));
             if ($relation->getWhere() !== null) {
                 $select->where($relation->getWhere());
             }
             if ($productIds !== null) {
                 $cond = array($this->_connection->quoteInto("{$relation->getChildFieldName()} IN(?)", $productIds), $this->_connection->quoteInto("{$relation->getParentFieldName()} IN(?)", $productIds));
                 $select->where(implode(' OR ', $cond));
             }
             $sql = $select->insertFromSelect($this->_productHelper->getFlatTableName($storeId), $fieldList);
             $this->_connection->query($sql);
         }
     }
     return $this;
 }