Skip to main content
3 of 3
replaced http://magento.stackexchange.com/ with https://magento.stackexchange.com/

Magento Custom Grid Left Join ID Conflict with Custom Table

I've got the following left join in my _prepareCollection(); method:

$collection->getSelect()->joinLeft(
        array('views_index' => "my_views_table"),
        'views_index.entity_id = main_table.entity_id',
        array('views'=>'count')
);

And then in my _prepareColumns() method I have:

$this->addColumn('views',
        array(
            'header'=> $this->__('Views'),
            'index' => 'views',
            'width' => '5%',
            'filter_index'  => 'views_index.count'
        )
);

When I load this page though, I get an error:

Item (Namespace_Module_Model_Mymodel) with the same id "{ID}" already exist

How is this conflict occurring?

Some background: Magento Custom Grid Redirect Error (On Join Attributes ONLY)

Would appreciate any help

Edit 1 The my_views_table consists of 3 columns, namely:

  1. id (primary key)
  2. entity_id
  3. count
Moose
  • 7.5k
  • 7
  • 49
  • 92