RE: [PEAR-DEV] Re: DB_DataObjects save method

From: Date: Fri, 29 Oct 2004 20:34:51 +0000
Subject: RE: [PEAR-DEV] Re: DB_DataObjects save method
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-34160@lists.php.net to get a copy of this message
A nice option would to have the UPDATE operation first do a SELECT and then only update the record if something has actually changed. The idea is that a select is generally faster than an update so performance can be improved by avoiding unnecessary updates. Of course it has to be optional since sometimes you know for certain the record has changed. -----Original Message----- From: Hans L [mailto:hans@velum.net] Sent: Friday, October 29, 2004 2:34 PM To: Andrew Nagy Cc: pear-dev@lists.php.net Subject: [PEAR-DEV] Re: DB_DataObjects save method Hi Andrew, > I know this is a little late in the game since DB_DataObjects is a > mature package and this suggestion is not thought out in depth, but what > about a method called "save"? > > The method would check to see if the primary key is set and if so call > update otherwise call insert. > > I find myself writing this simple if statement everywhere in my > "controller" classes and for some reason (after 2 years of DO use!) > thought about making a method that did such. > > Has this topic ever been debated? I haven't researched other DO > abstraction models (I remember an ex co-worker of mine had written a DO > class for MONO and was thinking about this). I'd imagine this would work great. This is roughly how Propel save() method works. Of course you might have to deal with the exceptional objects that do not have primary keys. Another option would just be to have a isNew() method that is false if the method is hydrated from database and true if the method is created via "new Objname()". 'Course it's been awhile since I looked at DBDO's design, but seems like either of these would be pretty straightforward to implement. Hans -- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

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