Re: Re: DB_DataObjects save method

From: Date: Fri, 29 Oct 2004 21:13:53 +0000
Subject: Re: Re: DB_DataObjects save method
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-34167@lists.php.net to get a copy of this message
Hi Mike, Mika Tuupola wrote:
On Fri, 29 Oct 2004, Hans L wrote:
To illustrate, with typical mutator method: function setName($v) { if ($v !== $this->name) {
     $this->modifiedColumns[] = "name";
     $this->name = $v;
} } That way when you actually perform the UPDATE, you can quickly build the column list from the $modifiedColumns array. Plus this give you an easy way to check whether objects are modified: $obj->isModified() or $obj->getModifiedColumns().
    Only works if the object was originally loaded from the database.
    What about if you created the object from for example
    $_POST array and later modified it. Would you then
    do an UPDATE?
Yeah, that's pretty easy to handle. When you save() you reset your $modifiedColumns array and $isNew, if applicable.
    IMO determining from primary key is quite simple and
    convenient method to find out whether you should
    do an UPDATE or INSERT.
Yeah, that works fine, but Aurthur's post I was responding to was a suggestion that only modified columns get updated. The use of pkey to determine update/insert doesn't address that need.
    This is of course if you have a primary key, but most
    of the time you do anyway.
Of course this doesn't account for possibility that someone else changed record in the background, but PHP in general is going to suck at those scenarious without an SRM solution and lots of hard-to-debug code to debug persistence code. Doing a SELECT before the update would be possible, but would add a lot of overhead. Plus this approach would
    Why not just store a timestamp and compare that before
    saving?>
Yeah -- optimistic locking would work, but would still require doing a SELECT, but it's a pretty good compromise. Again, though, this doesn't address Aurthur's suggestion, since this wouldn't indicate which cols had changed. -Hans

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