How to add new db field where you can store values seperated by commas?
Posted Date: September 8, 2009It took me some time to find out that how to do it ![]()
But believe me it was really easy, here you go:
Suppose if you are calling the following method in your controller:
$brands = Mage::getModel(’brands/brands’)->setData($data);
it means that you are calling the the brands.php in brands module model->Mysql4 folder.
Now in brands.php suppose we have category_ids field which was multiselect field and return us array then how to convert those values into seperated by commas.
Before saving _beforeSave(Mage_Core_Model_Abstract $object) can be called in brands.php as follows:
protected function _beforeSave(Mage_Core_Model_Abstract $object)
{
// format categories
$cats = ”;
foreach ((array)$object->getData(’category_ids’) as $cat) {
$cats .= $cat.’,';
}
$cats = ($cats!=”)?substr($cats,0,strlen($cats)-1):”;$object->setCategoryIds($cats);
return parent::_beforeSave($object);
}

