Having read Fixing Magento Flat Collections with Chaos by Alan Storm and finding a similar SO question here I am trying to return products that are in a category but without using Magento's "flat" data.
Here is the code that I originally used:
$category_model = Mage::getModel('catalog/category')->load($cid);
$collection = Mage::getModel('catalog/product_collection');
$collection->addCategoryFilter($category_model);
$collection->addAttributeToSort('entity_id','DESC');
$collection->addAttributeToSelect('*');
$collection->printLogQuery(true);
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:
app/code/local/Mynamespace/Mymodule/Model/Category.php:
class Mynamespace_Mymodule_Model_Category extends Mage_Catalog_Model_Category
{
protected function _construct()
{
$this->_init('catalog/category');
}
}
And:
app/code/local/Mynamespace/Mymodule/Model/Productcollection.php:
class Mynamespace_Mymodule_Model_Productcollection
extends Mage_Catalog_Model_Resource_Product_Collection
{
protected function _construct()
{
$this->_init('catalog/product');
$this->_initTables();
}
}
And then change my query code:
$category_model = Mage::getModel('mymodule/category')->load($cid);
$collection = Mage::getModel('mymodule/productcollection');
$collection->addCategoryFilter($category_model);
$collection->addAttributeToSort('entity_id','DESC');
$collection->addAttributeToSelect('*');
$collection->printLogQuery(true);
However the above code is still querying the flat data table. What is it I may be doing wrong?