On 9/4/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Almost there. I want addFooToDb() to either create a record if it
> doesn't exist or update an existing record. What you provided here
> will only update a record that's been found.
Well, that's what the example you had was doing anyway. :) Here's a
tweaked version.
function addFooToDb($name, $ext) {
$retVal = 0;
$fooId = $this->getFooId( $name );
if( $fooId > 0 ) {
$newFoo['Foo']['id'] = $fooId;
} else {
$this->Foo->create();
}
$newFoo['Foo']['name'] = $name;
$newFoo['Foo']['text'] = $text;
if( $this->Foo->save( $newFoo ) ) {
$retVal = $this->Foo->field('id');
}
return $retVal;
}
That *should* create a new record if getFooId() returns zero, and
update an existing record otherwise.
--
Chris Hartjes
Senior Developer
Cake Development Corporation
My motto for 2007: "Just build it, damnit!"
@TheBallpark - http://www.littlehart.net/attheballpark
@TheKeyboard - http://www.littlehart.net/atthekeyboard
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---