custom EAV model saving attributes
-
30-10-2019 - |
Question
I have a custom EAV model that uses custom tables for comments that can be set on either products or categories. I have created an admin for these using the standard EAV admin form.
In my controller, I have a save action:
public function saveAction()
{
if ($data = $this->getRequest()->getPost()) {
try {
$model = Mage::getModel('module/comment');
$model->setData($data)->setId($this->getRequest()->getParam('id'));
$model->save();
$this->_getSession()->addSuccess(
Mage::helper('module')->__('The comment has been saved.'));
$this->_redirect('*/*/edit',
array('id' => $this->getRequest()->getParam('id')));
}
catch (Exception $e) {
Mage::logException($e);
$this->_getSession()->addError(Mage::helper('module')->__('There was an error saving the comment'));
}
}
$this->_redirect('*/*/index');
}
When I save the form with a new comment, the grid page shows the new comment. But, when I look in the database with the following query:
SELECT * FROM eav_comment_text WHERE entity_id = 1;
I see the following:
+----------+----------------+--------------+----------+-----------+-------------------------+
| value_id | entity_type_id | attribute_id | store_id | entity_id | value |
+----------+----------------+--------------+----------+-----------+-------------------------+
| 1 | 31 | 964 | 0 | 1 | test |
| 4 | 31 | 964 | 0 | 1 | test adding another one |
+----------+----------------+--------------+----------+-----------+-------------------------+
Can anyone explain why (a) Magento does not replace the existing value and (b) how Magento knows which one to show in the grid?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange