Re: DataObject and update()

From: Date: Thu, 18 Nov 2004 18:01:49 +0000
Subject: Re: DataObject and update()
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-15644@lists.php.net to get a copy of this message
On Thu, 18 Nov 2004 12:18:57 +0100 (MET), kundert@mysunrise.ch <kundert@mysunrise.ch> wrote: > Hi all > > I allways wondering about the generated update sql strings from Dataobject. Even I changed one > column in the table, all columns are included in the update sql string. Then I saw in the source > from Dataobject.php function update() the follwing code: > > // dont write things that havent changed.. > if (($dataObject !== false) && isset($dataObject->$k) && ($dataObject->$k > == $this->$k)) > { > continue; > } > > So, I tried this: > > $do_herde_kosten_old = clone $do_herde_kosten; > $do_herde_kosten->setFrom($values,'frm_%s'); > $do_herde_kosten->update($do_herde_kosten_old); > > and it works, only the changed columns are in the update SQL. But is this the right way? > Shouldn't update() do this by it self? And for what else should the update() parameter be > usefully? > Nope, update() has no way of knowing what you changed short of re-selecting it from the DB. DBDO (the extension) should be able to handle this. Until then you have to pass the old dataobject in if you want the SQL to only update what has changed. -- Justin Patrin

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