Hi Adam,

Thanks so much, $this->id definitely gives me the right piece of
information.

I'm still curious though if I'm using Model::getLastInsertId() wrong,
or I've stumbled on a bug in the core. Model::getLastInsertId()
returns $this->__insertID correctly but it only has a value if a new
record in the DB was created, not on an update. Here was my test that
figured this out:

function afterSave($created) {
        if (! $created) {
                // Updated existing record
                $id = $this->getLastInsertId();
                echo debug($id);
                // $id is empty
        } else {
                // Created new record
                $id = $this->getLastInsertId();
                echo debug($id);
                // $id shows the id of the last record created
        }
        parent::afterSave($created);
}

Is this the expected behavior of the method? The API says, "Returns
the ID of the last record this Model inserted." Am I reading this
wrong? Its it only supposed to return the Id of a CREATE not an
UPDATE?

Again, I tested this with cake_1.2.0.6311-beta and a recent nightly
build (cake_1.2.x.x_16.04.2008).

Best,
Joshua

> Use $this->id and it will be either the record that was updated or the
> record just added.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to