TL;DR: you need a unique index on the following combination of columns: entity_id
,attribute_id
,store_id
.
Long answer:
On an EAV entity (let's take products for example) your table could never look like that.
You have 2 records for the same combination of attribute_id | store_id | entity_id
.
On the product tables (catalog_product_entity_varchar
for example but it's the same for _int
and others) there is a unique constraint on these 3 columns.
UNIQUE KEY `UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID` (`entity_id`,`attribute_id`,`store_id`),
This is created in the install script (see install-1.6.0.0.php
)
->addIndex(
$installer->getIdxName(
array('catalog/product', 'varchar'),
array('entity_id', 'attribute_id', 'store_id'),
Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
),
array('entity_id', 'attribute_id', 'store_id'),
array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE))
And when saving an attribute value (insert or update) a call to the method insertOnDuplicate
is made.
This method tries to insert the values you provide to it and if there is a unique key duplicate it just updates the values you specify. In the case of the EAV tables only the value
field is updated.
Since you don't have that unique constraint on the table it just inserts an other row.
Try adding that constraint and I have a feeling the problem will go away.
Best Answer
I've been able to do this within the admin section. You need to have your ResourceModel collection extend from the
\Magento\Eav\Model\Entity\Collection\AbstractCollection
class. Within your Grid Data provider, load the collection and useaddAttributeToSelect('*')
:which will load up the attribute values, then you need to specify the columns in the grid in your
[Namespace][Module]/view/[loc]/ui_component/[ui_component_grid_name].xml
layout: