i am trying to delete record from database is there any opposite methode of setdata to delete record from DB

$postModel = Mage::getModel('brainvire_brand/post');

  • Plz do not suggest me to add blank data – Vaibhav Ahalpara Mar 25 '15 at 11:22
  • vaibhav,is flat table i.e single table model? ... not a eav tbale – Amit Bera Mar 25 '15 at 13:12

First,i Guss you have using flat stucture

Better way to delete there any model by function delete(); By this you can delete model one by one.

$postModel = Mage::getModel('brainvire_brand/post');


Example. For delete an product you can use:

$productObject = Mage::getModel('catalog/product');

According you comment you can unset a field value by unsetData('index')

just: $postModel->unsetData('image'); then $postModel->save();

| improve this answer | |
  • i just want to delete one attribute value like i just want to delete value of image – Vaibhav Ahalpara Mar 25 '15 at 13:25

is there any opposite method of setData to delete record from DB.

No, I don't believe you can delete EAV table records using any Magento or magic methods. However, doing setImage(null) will effectively achieve what you want (removing image data, but not the actual DB record).

| improve this answer | |

There is unsetData() which unsets the attribute in your PHP model but this results in the attribute just being ignored during save. To delete the attribute value, you need to set it to a value that is considered empty. What this can be depends on the backend type, but "null" always works.

Take a look at Mage_Eav_Model_Entity_Attribute_Abstract::isValueEmpty():

public function isValueEmpty($value)
    $attrType = $this->getBackend()->getType();
    $isEmpty = is_array($value)
        || ($value === null)
        || $value === false && $attrType != 'int'
        || $value === '' && ($attrType == 'int' || $attrType == 'decimal' || $attrType == 'datetime');

    return $isEmpty;

I assume, "image" has the type 'varchar', so setImage('') will just set the value to an empty string, but setImage(null) will actually remove it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.