logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

[Zend_Db_Table- ZF9.3 & ZF1.0RC1] cannot get anymore the id when insert dat: msg#00465

Subject: [Zend_Db_Table- ZF9.3 & ZF1.0RC1] cannot get anymore the id when insert data
Hi,

I update my project, and now when i insert my data from a table, i cannot
get anymore the id.

So i check the source code, and it appears with the modification of the
composed key. The code of my Zend_table

class MpMedia extends Zend_Db_Table_Abstract {  
                
   protected function _setup()  {
        $this->_name = 'mp_media';
        $this->_primary = 'media_id';
        parent::_setup();
    }
        
        public function insert($data)    { 
        $data['media_date_update'] = date('Y-m-d H:i:s');
        return parent::insert($data);

    } 
 
    public function update($data, $where )     { 
        $data['media_date_update'] = date('Y-m-d H:i:s');
        return parent::update($data, $where); 
    } 
}

and when i call the insert method no retreive the id !


The source code in which doesn't is in bold 0.9.3 abd 1.0RC1 in
Zend_Db_Table_Abstract

public function insert(array $data)
{

  public function insert(array $data)
    {
        Zend_Debug::dump("table abstract","insert: ",true);
        
        /**
         * Zend_Db_Table assumes that if you have a compound primary key
         * and one of the columns in the key uses a sequence,
         * it's the _first_ column in the compound key.
         */
        $primary = (array) $this->_primary;
        $pk0 = current($primary);

        /**
         * If this table uses a database sequence object and the data does
not
         * specify a value, then get the next ID from the sequence and add
it
         * to the row.  We assume that only the first column in a compound
         * primary key takes a value from a sequence.
         */
        if (is_string($this->_sequence) && !isset($data[$pk0])) {
            $data[$pk0] = $this->_db->nextSequenceId($this->_sequence);
        }

        /**
         * INSERT the new row.
         */
        $this->_db->insert($this->_name, $data);
                
                
                
        if (isset($data[$pk0])) {
                        
            /**
             * Return the primary key value or array of values(s) if the
             * primary key is compound.  This handles the case of natural
keys
             * and sequence-driven keys.  This also covers the case of
             * auto-increment keys when the user specifies a value, thus
             * overriding the auto-increment logic.
             */
          if (count($primary) == 1) {
                return $data[$pk0];
            } else {
                return array_intersect_key($data, array_flip($primary));
            }
        }
                
                                
        if ($this->_sequence === true) {
            /**
             * Return the most recent ID generated by an auto-increment
             * or IDENTITY column.
             */
             
             Zend_Debug::dump($this->_db->lastInsertId(),"lastInsertId:
",true); 
            return $this->_db->lastInsertId();
        } 

        /**
         * The last case:  the user did not specify a value for the primary
         * key, nor is this table class declared to use an auto-increment
key.
         * Since the insert did not fail, we can assume this is one of the
edge
         * cases, which may include:
         * - the table has no primary key defined;
         * - the database table uses a trigger to set a primary key value;
         * - the RDBMS permits primary keys to be NULL or have a value set
         *   to the column's DEFAULT
         */
        return null;
    }

}

If i comment all the bold part, it works very well, maybe i have to create a
ticket in the trac zend system.

-- 
View this message in context: 
http://www.nabble.com/-Zend_Db_Table--ZF9.3---ZF1.0RC1--cannot-get-anymore-the-id-when-insert-data-tf3841573s16154.html#a10877839
Sent from the Zend Framework mailing list archive at Nabble.com.




<Prev in Thread] Current Thread [Next in Thread>