On 9/4/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > I guess I'm being too vague here. My original code is fine for doing > both inserts and updates. Let me illustrate the problem with more > code: > > addFooToDb( 'Bob Jones', '04/05/2007 12:00:00' ); > addFooToDb( 'Sam Smith', '04/05/2007 12:01:24' ); > addFooToDb( 'Bob Jones', '04/05/2007 01:38:02' ); > > - CASE 1: There is already a record in the Foo table where name = > "Bob Jones", but nothing else. > > In this case, the final contents of Foo will be something like this: > > id name text > 1 'Bob Jones' '04/05/2007 01:38:02' > 2 'Sam Smith' '04/05/2007 12:01:24' > > This is the behavior I'm expecting. Sadly, this isn't always the > case...
There is no reason why the code I've provided shouldn't work, unless I've made such a glaring mistake that it shouldn't. Seems to me the method is 1) check to see if you have any records that match 'name' 2) if there is a match, get the id for that record 3) when you go to do a save, try setting $this->Foo->id = id of record to update 4) do your $this->Foo->save(...) and that should either create a new record or update an existing one Here's a stupid question for you: if getFooId is *always* returning a 0, then have you verified that getFooId is actually returning a correct value? That seems to me to be the only place where this chain breaks down: if getFooId doesn't return the proper value but returns 0 instead, then it simply isn't working. -- 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 -~----------~----~----~----~------~----~------~--~---
