A recent client was getting a strange behavior on the customer account page. When they would click on the product review link, the following error would be thrown:
SQLSTATE[42S22]: Column not found: 1054 Unkown column 'product_id' in 'field list'' in ...
At first, this looks like an easy issue to debug. Find the faulty custom code in the stack trace, and modify whatever query is blowing up. To my surprise, there was no custom (local) code that was referenced from the stack trace. Every referenced class was within core.
I’m not usually quick to assume cure bugs in the software platforms I use, but this looked like a pretty obvious case. After searching through the stack trace, I was able to pinpoint the error at line 1647 in app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php. Without going into too much detail, the problem was that the Review module product collection subclasses the previously mentioned class, but it doesn’t instantiate itself the same as its parent. Meaning, in the parent class, a field called _productCategoryTable is getting initialized, but in the Review module’s subclass, this isn’t the case. All is fine so far, but the Magento Enterprise CatalogEvent module is listing for an event that eventually calls the addCategoryIds() method, which in turn executes a query with the _productCategoryTable. Since the subclass doesn’t initialize this value, the sql error is thrown.
To remedy this, I simply copied over the Mage_Review_Model_Mysql4_Review_Product_Collection class to my code/local/Mage directory, and I included the following line at the end of the constructor method:
$this->_productCategoryTable = $this->getResource()->getTable('catalog/category_product');
There are probably more elegant solutions, but since this seems to be a core Magento bug, I’m fine with the solution.