Re: Re: DB_DataObjects save method
| From: | Andrew S. Nagy | Date: | Fri, 29 Oct 2004 20:45:24 +0000 |
| Subject: | Re: Re: DB_DataObjects save method | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-34162@lists.php.net to get a copy of this message | ||
Justin Patrin wrote:
On Fri, 29 Oct 2004 15:45:49 -0400, Andrew S. Nagy <asnagy@webitecture.org> wrote:function replaceInto() {Hans L wrote: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:'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?
// 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)) {
$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();
}
}