Re: Re: DB_DataObjects save method

From: Date: Fri, 29 Oct 2004 20:51:27 +0000
Subject: Re: Re: DB_DataObjects save method
References: 1 2 3 4 5  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-34164@lists.php.net to get a copy of this message
On Fri, 29 Oct 2004 16:45:24 -0400, Andrew S. Nagy <asnagy@webitecture.org> wrote: > Justin Patrin wrote: > > >On Fri, 29 Oct 2004 15:45:49 -0400, Andrew S. Nagy > ><asnagy@webitecture.org> wrote: > > > > > >>Hans L wrote: > >> > >> > >>>'Course it's been awhile since I looked at DBDO's design, but seems > >>>like either of these would be pretty straightforward to implement. > >>> > >>> > >>This is an interesting idea, Alan, any thoughts? > >> > >> > >> > > > >BTW, DB_DataObject_FormBuilder does exactly this kind of thing in its > >processForm method. > > > > > After looking at how others do it, what about something like this: > > function replaceInto() > { > // This should call the replaceInto directly to the DB if it is > // supported; otherwise use the following logic: > > // Determine if keys are set > $update = 0; > $keys = $this->keys(); > foreach($keys as $k => $v) { > if (!isset($this->$k)) { Don't you mean if (isset($this->$k)) ? This will only call $update if all keys are *not* set. Maybe you meant to reverse update() and insert() below? > $update++; > } > } > > // Determine whether to call update or insert > if ($update == count($keys)) { > $this->update(); > } elseif ($update) { > $this->raiseError("replaceInto: Not all keys are defined", > DB_DATAOBJECT_ERROR_NODATA); > } else { > $this->insert(); > } > > } > -- paperCrane --Justin Patrin--

« previous php.pear.dev (#34164) next »