As the question title states, I am using setData and then save to update/add data to my table, but whenever I save my custom product nothing gets written to the database even when the data is 'set' in the table. I followed this post http://alanstorm.com/magento_models_orm and added a set up block under resources.

This is my config.xml file

<?xml version="1.0"?>

                    <cron_expr>0,30 * * * *</cron_expr>

I have FPM/TrackProcessor/Model/TrackProcessor.php

class FPM_TrackProcessor_Model_TrackProcessor extends Mage_Core_Model_Abstract{

  protected function _construct(){



class FPM_TrackProcessor_Model_Mysql4_TrackProcessor extends Mage_Core_Model_Mysql4_Abstract {

  protected function _construct(){
    $this->_init('fpm_trackprocessor/trackprocessor', 'entity_id');


class FPM_TrackProcessor_Model_Mysql4_TrackProcessor_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
    protected function _construct()

And FPM/TrackProcessor/Model/Resource/Setup.php

class FPM_TrackProcessor_Model_Resource_Setup
    extends Mage_Catalog_Model_Resource_Setup {

Finally in the controller of my custom module at


I have this code, to write to the db, inside the saveAction function

        $volumeFiles = $_FILES['volume']['name'];
        $trackFiles = $volumeFiles['track'];
        $editsFiles = $volumeFiles['edits'];
        $currentVolume = $this->getRequest()->getPost('volume');
        $volumeName = str_replace(' ', '_',$currentVolume['volume_name']);
        $trackDir = 'media/volume/tracks/'.$volumeName.'/';
        $volumeId = $this->getRequest()->getParam('id');
        $entityId = $volumeId = $volumeId + 0;
        $status = 0;
        $trackModel = Mage::getModel('fpm_trackprocessor/trackprocessor');

        //TRACK DB WRITE
        $trackType = 0;
        $trackNumIndex = 0;
        foreach($trackFiles as $track){
          $tmpStrArray = explode('.',$track);
          $trackName = $tmpStrArray[0];
          $tmpStrArray = str_split($trackName, 1); 
          $trackDir = $trackDir.$tmpStrArray[0].'/';
          $trackNum = $currentVolume['order'][$trackNumIndex] + 0;
          //WRITING TO DB
          $dbData = array(
            'volume_id'         => $volumeId,
            'entity_id'         => $entityId,
            'input_track_path'  => $trackDir,
            'status'            => $status,
            'track_num'         => $trackNum,
            'track_type'        => $trackType,
            $insertId = $trackModel->save()->getId();
            echo "Data inserted. Insert ID: ".$insertId;
          }catch(Exception $e){
            echo $e->getMessage();  

Currently, the code works, my echoed success message appears and nothing breaks, per say, when the custom product(volume) is saved, but when I check my table using mysql bench, all the fields are still null. I've also cleared the cache countless times, and have gone as far as to delete the install script from core_resources in my table and also dropping my fpm_trackprocessor_trackprocessor table from my schema, but nothing seems to work. Would anyone please point out what I am doing wrong and explain why nothing is being saved to my db?


Try to step-up xdebug and work your way into the save function to see what is happening. Magento will do a desc table before a save to make sure it only tries to save columns that are on the table.

Check out Mage_Core_Model_Resource_Db_Abstract::_prepareDataForTable.

 * Prepare data for passed table
 * @param Varien_Object $object
 * @param string $table
 * @return array
protected function _prepareDataForTable(Varien_Object $object, $table)
    $data = array();
    $fields = $this->_getWriteAdapter()->describeTable($table);
    foreach (array_keys($fields) as $field) {
        if ($object->hasData($field)) {
            $fieldValue = $object->getData($field);
            if ($fieldValue instanceof Zend_Db_Expr) {
                $data[$field] = $fieldValue;
            } else {
                if (null !== $fieldValue) {
                    $fieldValue   = $this->_prepareTableValueForSave($fieldValue, $fields[$field]['DATA_TYPE']);
                    $data[$field] = $this->_getWriteAdapter()->prepareColumnValue($fields[$field], $fieldValue);
                } else if (!empty($fields[$field]['NULLABLE'])) {
                    $data[$field] = null;
    return $data;

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.