title: Magento: Build custom product collection of all configurable products in stock
body: <p>I'm trying to build a product collection of all configurable products which are 'in-stock' or 'is-saleable'. These require two different models to be used. My working method is:</p>
  
  <pre><code>$collectionConfigurable = Mage::getResourceModel('catalog/product_collection')-&gt;addAttributeToFilter('type_id', array('eq' =&gt; 'configurable'));
  
  foreach ($collectionConfigurable as $_configurableproduct) {
      $product = Mage::getModel('catalog/product')-&gt;load($_configurableproduct-&gt;getId());
  
      if ($product-&gt;isSaleable()) { 
  // do something
  }
  }
  </code></pre>
  
  <p>However this script is REALLY slow and I have a feeling it's wasting resources running as it will be loading and going through EVERY configurable product.</p>
  
  <p>What I'm trying to achieve is to get the $collectionConfigurable and make it in-stock items only. </p>
  
  <p>Another resource cites this as a method to get in stock items. </p>
  
  <pre><code>Mage::getSingleton('cataloginventory/stock')-&gt;addInStockFilterToCollection($this-&gt;_productCollection);
  </code></pre>
  
  <p>But I'm not sure how to combine them or use it properly, I've tried this:</p>
  
  <pre><code>$collectionConfigurable = Mage::getResourceModel('catalog/product_collection')-&gt;addAttributeToFilter('type_id', array('eq' =&gt; 'configurable'));
  $instockConfigs = Mage::getSingleton('cataloginventory/stock')-&gt;addInStockFilterToCollection($collectionconfigurable);
  </code></pre>
  
  <p>This returns with the following error:</p>
  
  <pre><code>  Fatal error: Call to a member function joinField() on a non-object in /srv/magento/app/code/core/Mage/CatalogInventory/Model/Resource/Stock.php on line 197
  </code></pre>