I create a custom module for product question. I added in my db the customer_id
, but in the grid I want to show the name of customer. For that I did a join with customer_entity_varchar
and got the full name of customer.
When I want to filter the grid by customer name:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where clause is ambiguous.
$this->addColumn('customer_name', [
'header' => $this->__('Customer Name'),
'align' => 'left',
'index' => 'customer_name',
'filter_index' => 'value',
]);
$first = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'firstname');
$last = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'lastname');
$this->getSelect()->join(['ce1' => 'customer_entity_varchar'], 'ce1.entity_id=main_table.customer_id', ['firstname' => 'value'])
->where('ce1.attribute_id='.$first->getAttributeId())
->join(['ce2' => 'customer_entity_varchar'], 'ce2.entity_id=main_table.customer_id', ['lastname' => 'value'])
->where('ce2.attribute_id='.$last->getAttributeId())
->columns(new Zend_Db_Expr("CONCAT(`ce1`.`value`, ' ',`ce2`.`value`) AS customer_name"));
UPDATE:
I changed value
with main_table.value
$this->addColumn('customer_name', [
'header' => $this->__('Customer Name'),
'align' => 'left',
'index' => 'customer_name',
'filter_index' => 'main_table.value',
]);
and receive:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.value' in 'where clause'