Re: Re: DB_DataObjects save method
| From: | Mika Tuupola | Date: | Fri, 29 Oct 2004 21:07:55 +0000 |
| Subject: | Re: Re: DB_DataObjects save method | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-34166@lists.php.net to get a copy of this message | ||
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?
IMO determining from primary key is quite simple and
convenient method to find out whether you should
do an UPDATE or INSERT.
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?>
--
Mika Tuupola http://www.appelsiini.net/~tuupola/