Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-13-2008, 11:29 AM
Junior Member
 
Join Date: Aug 2008
Posts: 3
Unhappy insert() without primary key

Hi,
im trying to add a row to a table which has no primary keys. could anyone tell me why i get the following exception:

Uncaught exception 'Zend_Db_Table_Exception' with message 'A table must have a primary key, but none was found

thanks for helping

pete



PHP Code:
class Subscribers extends App_Db_Table_Abstract 
{
       protected   
$_primary null;
    protected 
$_sequence false
 
    public function 
__construct($dbName,$tableName)
    {
        
parent::__construct(null$dbName,$tableName);
    } 
    
    public function 
add()
        {
           
$this->_sequence false;
            
$newUser = array(
                
'id_subscriber' => 1,
                
'id_subscriber_list' => 1       
            
);

            
$userId $this->insert($newUser);

           
            return 
$userId;        
        }
    

TABLE
no primary keys
2 columns "id_subscriber_list", "id_subscriber"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-13-2008, 12:47 PM
Junior Member
 
Join Date: Aug 2007
Posts: 9
Send a message via ICQ to Mike
Default

Did you read the message of the exception? You need a primary key!
Quote:
Originally Posted by http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.defining.primary-key
Every table class must know which column(s) can be used to address rows uniquely. If no primary key column(s) are specified in the table class definition or the table constructor arguments, or discovered in the table metadata provided by describeTable(), then the table cannot be used with Zend_Db_Table.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-14-2008, 12:41 AM
Member
 
Join Date: Jul 2008
Posts: 60
Default

Your primary key will probably be a complex key using both of the fields, assuming they are jointly unique (a subscriber can only subscribe to a list once?). If they are not, you should add an artificial key.
__________________
Brenton Alker
Brisbane, Australia

http://blog.tekerson.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:15 AM.