Magento Customer Review Module and “Unknown column ‘product_id’ in ‘field list'”

Home / Blog / Magento Customer Review Module and “Unknown column ‘product_id’ in ‘field list'”

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 buy yasmin no rx 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.

Showing 5 comments
  • Nithin

    Thanks for the post , it works fine in all magento versions.

  • Jason

    Thanks, my head was getting sore from banging it on the desk thinking what have I done to break it. This fix works well!

  • tmillhouse

    haha … I’m glad this helped you.

  • Dan Shields

    Thanks, I just came across this as well and noticed that class wasn’t being instantiated and instead of figuring out why or what to do I just googled first to see if someone else had the solution and boom there you were, thanks!

  • huong

    Thank a lot. Your post is great. It is helped me resolve my problem.

Leave a Comment