Re: DB_DataObjects save method

From: Date: Fri, 29 Oct 2004 19:34:22 +0000
Subject: Re: DB_DataObjects save method
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-34155@lists.php.net to get a copy of this message
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

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