In the blog tutorial, they use the save method both to save or update
an existing record. I tried to take that idea for my application and
had some trouble:

My model is the following, with all default table names (i.e id is the
primary key)

class Manufacturer extends AppModel {
          var $name = "Manufacturer";
          var $validate = Array (/*validation stuff*/);

          //some other methods
}

And the controller is as follows

class ManufacturersController extends AppController {
        var $name = "Manufacturers";
        var $helpers = array('Html', 'Form','Javascript');
        var $components = array('Session');

       function edit($id = 0) {
            if ($id) {
                   $this->Manufacturer->set($this->data);
                   $this->Manufacturer->set('id',$id);

                   /*try to update the record*/
                   $this->Manufacturer->save();
            }
       }

}

In the edit function I set the id attribute for the Manufacturer model
as stated in the documentation; with this, the "save" method should
update rather than create a new records. Altough, the application
issues the following error message (here key 1 is the primary key, and
12 is a value of an existing id in the database table):

Warning (512): SQL Error: 1062: Duplicate entry '12' for key 1

$sql    =       "INSERT INTO `manufacturers`
(`titulo`,`descripcion_es`,`descripcion_uk`,`descripcion_it`,`id`)
VALUES ('F222','xxx,'xxx','xxxx',12)"

Wich attribute I have to set in order of the save method generate a
UPDATE query instead of an INSERT one?

Thanks in advice.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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