PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB_DataObject » Bug #3255

Set Id for new objects

Details

Request #3255Set Id for new objects
Submitted2005-01-20 21:57 UTC
Frominfo at rhalff dot com
StatusFeedback
PackageDB_DataObject
PHP VersionIrrelevant
OSDebian
Roadmaps(Not assigned)

Comments

[2005-01-20 21:57 UTC] info at rhalff dot com

Description:
------------
I needed support to add a key manually for newly created objects (not using auto_increment or sequences)

Here's the diff against the stable version 1.7.2.
I'm using this in many dataObjects, so I consider it well tested :)

Basically it allows me to set the key for new objects.
Like:

$item = new Item();
$item->insert();

$document = new Document()
$document->setId($item->id);
$document->insert();

In this case documentID references itemID (innodb reference);

The only change needed to support this is within the insert method.

========================================================

laptop:~/DataObject# diff DataObject.orig DataObject.php

873,874c873,874
<
< if (($key !== false) && !$useNative) {
---
> /* added !isset($this->$key)) */
> if (($key !== false) && !$useNative && !isset($this->$key)) {
889c889
<
---
>
891c891,892
< if ($key && ($k == $key) && $useNative) {
---
> // if $v is set also continue..
> if ($key && ($k == $key) && $useNative && empty($this->$k)) {
894d894
<
969a970
> // if $this->key is not empty don't fill it (for innodb references)
971c972
< if ($key && $useNative) {
---
> if ($key && $useNative && !isset($this->$key)) {