to back up what robert is saying in your function definition you are
declaring $id=null. if your function is not getting an $id passed to
it
that would cause an insert not an update.

in short you should make sure you are passing an id and also put a
conditional check on $id such as:

//if we find an item with this id
//you could use read() instead of find
if($this->find('first', array('conditions'=>array('Model.id'=>$id))))
{
$this->Model->id = $id;

}

else {
//failed to get model id
//now this acts like an add form
//or die
}

On Aug 12, 11:37 am, Robert P <[email protected]> wrote:
> Model::saveField() still requires a valid primary key, which I suspect
> he is setting to NULL at the beginning of his method.
>
> On Aug 12, 9:30 pm, eusef <[email protected]> wrote:
>
> > If you know which field you need to update perhaps you could try
> > using :
>
> >    saveField(string $fieldName, string $fieldValue, $validate = false)
>
> > From
> >  :http://book.cakephp.org/view/75/Saving-Your-Data
>
> > GL - Phil
>
> > On Aug 11, 8:03 pm, tron <[email protected]> wrote:
>
> > > I have a problem with one specific controller trying to INSERT instead
> > > of UPDATE and I am getting duplicate entry errors. the "$this->data"
> > > variable contains the correct primary key of table I'm trying to
> > > update, but still tries to INSERT instead. Most notable text message
> > > is this in the debug dump: SELECT COUNT(*) AS `count` FROM `employees`
> > > AS `Employee` WHERE `Employee`.`id` IS NULL. Apparently its not
> > > getting the id at all?
>
> > > Code:
>
> > >         function        edit( $id = null )
> > >         {
> > >         pr( $id );
> > >         pr( $this->data );
> > >         $this->Employee->id = $id;
>
> > >         if( !empty( $this->data ) )
> > >         {
> > >             if( $this->Employee->save( $this->data ) )
> > >             {
> > >             }
>
> > >         } else {
> > >             $this->data = $this->Employee->read( null, $id );
> > >         }
> > >         }
>
> > > Both the pr functions display the correct data that suggests it should
> > > be doing an UPDATE instead of INSERT.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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