PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject » Bug #5790

Automatically determine insert/update for an object

Details

Request #5790Automatically determine insert/update for an object
Submitted2005-10-26 16:17 UTC
Fromrichtl at arscognita dot com
StatusOpen
PackageDB_DataObject
PHP Version5.1.0
OSLinux
Roadmaps(Not assigned)

Comments

[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
}
}

[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.