Re: DB_DataObject skip sequence

From: Date: Wed, 13 Apr 2005 17:00:10 +0000
Subject: Re: DB_DataObject skip sequence
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18731@lists.php.net to get a copy of this message
On 4/13/05, Robin Ericsson <robin.ericsson@profecta.se> wrote: > Justin Patrin wrote: > > On 4/13/05, Robin Ericsson <robin.ericsson@profecta.se> wrote: > > > >>Hi, > >> > >>Is it possible to tell DB_DataObject to just skip using sequence on a > >>field defined as primary key? > > > > > > I'm not sure what you're asking. Is this field set up as a PK in your > > table? Is it set up as a sequence? Is DB_DO using DB's sequence > > methods and you don't want that? > > Mysql table: > CREATE TABLE person_tokens ( > person_id bigint(20) NOT NULL default '0', > token char(40) NOT NULL default '', > expire datetime default NULL, > PRIMARY KEY (person_id), > KEY idx_token (token) > ); > > This is the table from DB_DO: > var $__table = 'person_tokens'; // table name > var $person_id; // int(20) not_null primary_key > var $token; // string(40) not_null > multiple_key > var $expire; // datetime(19) > > $po = new Person_Tokens; > $po->person_id = 3; > $po->token = $token; > > $po->insert(); > > this causes DB_DO to create a sequence and try to add "1" as person_id > instead of the 3 I've put in it. Why are you manually putting in a value in your primary key? This is generally bad practice. Why not use an auto incremented field? > > > >>I've tried to add a method called sequenceKey() which returned > >>array('field', true, false), but in that case the field wasn't used at > >>all in the query. > >> > > > > > > perhaps try array('field', false, false)? > > That results as DB_DO still using a sequence instead of "3". > You can also try array(false, false, false). I suggest, however, that you change the id to an autoincremented field and let mysql set the value. DB_DO is smart enough to pick this id back up and put it back in the DO. -- Justin Patrin

« previous php.pear.general (#18731) next »