Re: DB_DataObject and multiple column primary keys

From: Date: Sun, 06 Feb 2005 02:24:20 +0000
Subject: Re: DB_DataObject and multiple column primary keys
References: 1 2 3  Groups: php.pear.general php.pear.general 
Request: Send a blank email to pear-general+get-17406@lists.php.net to get a copy of this message
At present update favours sequence columns over keys, and AFAIR the generator will skip writing keys for all other columns if it finds the auto increment column. - Obviously this behaviour may need modifying. Regards Alan Olivier Guilyardi wrote:
Alan wrote:
I ran this on it, update facture set currency='GBP' where id=1; seemed ok.
No it isn't. The primary key is not id. There may be two _unique_ rows with id = 1. This, because the primary key is a couple or fields : (status,id). MySQL allows you to make a primary key from up to 15 fields. See: http://dev.mysql.com/doc/mysql/en/multiple-column-indexes.html The fix I'm currently using consists in overloading update() with : function update() {
    $this->whereAdd("status = '{$this->status}'");
    return parent::update();
} Which, according to the $this->status value, will turn your above query into : update facture set currency='GBP' where id=1 and status='pending'; OR update facture set currency='GBP' where id=1 and status='validated'; Given that I did use createTables.php, there may some way to tweak the schema file, so that it supports my multiple column key. However, I haven't figured out how.
If you have a look at the current code for all this, it's horrifically complex, so I want to try and make this as simple (and predicatable as possible in the future..)
Before I take a look, I'd like to be sure we understand each other on what exactly my problem is. -- og


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