Thursday, September 1, 2011

Magento You cannot define a correlation name more than once

I got the error when adding color option to the sorting dropdown "You cannot define a correlation name 'color_t1' more than once". Here is the solution which works fine.
Go to the file "/lib/Zend/Db/select.php"
Comment the below line
throw new Zend_Db_Select_Exception("You cannot define a correlation name '$correlationName' more than once");

2 comments:

  1. Seriously? You 'fixed' the problem by removing the exception? That's like treating a fever by throwing away the thermometer.

    ReplyDelete
  2. The correct way to handle this error is outlined below:

    adding the same attribute to the sort twice when building a collection:

    ...
    ->addAttributeToSort('color', 'asc')
    ->addAttributeToSort('color', 'asc');

    NOTE: calling setCollection($this->getMyCollection); on the template caused my error, because 'color' was already added to the sort order as the default sort order.

    SOLUTION:a quick way to fix this is to remove the default sort order from the request after obtain the value:

    $this->getRequest()->setParam('order','');

    otherwise extend the Block and override the setCollection() method for your particular needs.
    http://stackoverflow.com/questions/10524017/magento-layered-navigation-you-cannot-define-a-correlation-name-mycustomattrib/14805672#14805672

    ReplyDelete