Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/11/2011, 19:19
opzina
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Problemas inserciones.

El problema radica cuando subo mas de un adjunto, asi queda la tabla
cuando inserto 3 adjuntos:
Donde Tabla adjuntos
id, product_id, file_dir, file_name, file_code
1, 0, img, imagename1.jpg, 0000
2, 0, img, imagename2.jpg, 0000
3, 1, img, imagename2.jpg, 0000
Y lo que necesito yo es lo siguiente:
Donde Tabla adjuntos
id, product_id, file_dir, file_name, file_code
1, 1, img, imagename1.jpg, 0000
2, 1, img, imagename2.jpg, 0000
3, 1, img, imagename2.jpg, 0000
Donde uno hace referencia al id del producto. (hasMany: 1 Producto
muchos Adjuntos).
Probe con saveAll(), pero no me da el resultado esperado.
Ese es el codigo del metodo add:
Código PHP:
Ver original
  1. function add() {
  2.                 if (!empty($this->data)) {
  3.                         if ($this->data['Attachment']['File'][0]['error'] == 4) {
  4.                                 $this->Guitar->create();
  5.                                 if ($this->Guitar->save($this->data)) {
  6.                                         $this->Session->setFlash(__('The notice has been saved', true));
  7.                                         $this->redirect(array('action' => 'index'));
  8.                                 } else {
  9.                                         $this->Session->setFlash(__('The notice could not be saved.
  10. Please, try again.', true));
  11.                                         }
  12.                         } else {
  13.                                 if ($this->FileUpload->success) {
  14.                                         $this->Guitar->create();
  15.                                         if ($this->Guitar->save($this->data)) {
  16.                                                 $this->data['Attachment']['guitar_id'] = $this->Guitar->id;  //
  17. Aca recupero el id del producto.
  18.                                                 $this->Guitar->Attachment->save($this->data); //Aca lo inserta
  19. en el modelo Adjunto
  20.                                                         $this->Session->setFlash(__('The notice has been saved',
  21. true));
  22.                                                 } else {
  23.                                                         $this->Session->setFlash(__('The notice could not be saved.
  24. Please, try again.', true));
  25.                                                         }
  26.                                 }
  27.                         }
  28.                 }
  29.         }
__________________
_