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.
1 Answer
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)