2

I have created a table abc_bar/baz Here, I want that it's filed name should be unique, is there an easy way in magento to check this.

2

In your controller saveAction method you can do the following:

// Retrieve the possible entities with same name
$existingEntities = Mage::getResourceModel('abc_bar/baz_collection')->addFieldToFilter('name',$postData['name']);
if ($existingEntities->getSize())
{
        Mage::getSingleton('adminhtml/session')->addError($this->__('Sorry the entity name must be unique and it seems like another entity has the same name'));
        $this->_redirectReferer();
}
// Only add the data if the test pass
$model->setData($postData)

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.