title: Do not use "flat" data in magento
body: <p>Having read <a href="http://alanstorm.com/magento_flat_collection_chaos" rel="nofollow noreferrer">Fixing Magento Flat Collections with Chaos</a> by Alan Storm and finding a similar SO question <a href="https://stackoverflow.com/questions/5976496/how-to-select-from-magento-eav-tables-when-flat-catalog-product-data-is-on">here</a> I am trying to return products that are in a category but without using Magento's "flat" data. </p>
  
  <p>Here is the code that I originally used:</p>
  
  <pre><code>        $category_model = Mage::getModel('catalog/category')-&gt;load($cid);
          $collection = Mage::getModel('catalog/product_collection');
          $collection-&gt;addCategoryFilter($category_model);
          $collection-&gt;addAttributeToSort('entity_id','DESC'); 
          $collection-&gt;addAttributeToSelect('*');
  
          $collection-&gt;printLogQuery(true);
  </code></pre>
  
  <p>When this code gets fired through AJAX I get different results than when I run it from an observer and the reason is because of flat data. So I have written my own classes that are meant to use the EAV model:</p>
  
  <pre><code>app/code/local/Mynamespace/Mymodule/Model/Category.php:
  
  class Mynamespace_Mymodule_Model_Category extends Mage_Catalog_Model_Category
  {
      protected function _construct()
      {
  
          $this-&gt;_init('catalog/category');
  
      }
  
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>app/code/local/Mynamespace/Mymodule/Model/Productcollection.php:
  
  class Mynamespace_Mymodule_Model_Productcollection 
  extends Mage_Catalog_Model_Resource_Product_Collection
  {
      protected function _construct()
      {
  
          $this-&gt;_init('catalog/product');
          $this-&gt;_initTables();
      }
  
  }
  </code></pre>
  
  <p>And then change my query code:</p>
  
  <pre><code>        $category_model = Mage::getModel('mymodule/category')-&gt;load($cid);
          $collection = Mage::getModel('mymodule/productcollection');
          $collection-&gt;addCategoryFilter($category_model);
          $collection-&gt;addAttributeToSort('entity_id','DESC'); 
          $collection-&gt;addAttributeToSelect('*');
  
          $collection-&gt;printLogQuery(true);
  </code></pre>
  
  <p>However the above code is still querying the flat data table. What is it I may be doing wrong?</p>