Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.11.5

Request #5790 Automatically determine insert/update for an object
Submitted: 2005-10-26 16:17 UTC
From: richtl at arscognita dot com Assigned:
Status: Open Package: DB_DataObject
PHP Version: 5.1.0 OS: Linux
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 27 + 46 = ?

 
 [2005-10-26 16:17 UTC] richtl at arscognita dot com
Description: ------------ The MyObjects library has a store() function that automatically determines whether an object should be inserted or updated depending on whether it exists in the database. I find I'm writing a log of "if this->find() then update else insert" sorts of structures. It would make sense to move this into the DB_DataObjects code. What I'm proposing is essentially, function store() { if( object exists in the database ) { // update it from object properties } else { // insert it as a new row } }

Comments

 [2005-10-28 01:15 UTC] alan_k
I've never been that keen to add this a) because it's trival to add in code.. b) it's not actually required that often. c) not keen to make the api too big, and waste it on minor methods.. Leaving it open for a while - to think about..
 [2006-02-05 23:10 UTC] mz+pear at dago dot de
Indeed, it may be a kind of useless implementing a lot of 'little' methods, but i'm also using Hibernate (as a database-abstraction for Java), which also provides this feature. At least every database-abstraction uses this behaviour. After thinking about why, it seems clearly to me now: it's a matter of fact, that abstraction layers are used to make things easier to programmers. They should also hide some 'internals' that aren't neccessary to know from him (I think, nobody wants to handle a floppy-disk-drive in the matter a operating system does, writing to /dev/fd0 is the easy way). In this case, the programmer wants to _persist_ data - in which way isn't that interesting for him, this should be decided by the database abstraction layer.