to back up what robert is saying in your function definition you are
declaring $id=null. if you 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 out 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 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
-~----------~----~----~----~------~----~------~--~---