Ir para a pagina inicial dos Grupos do Google    ArqHP - Arquitetura de home pages
Cake - Insert ao invez de update

João Vagner <joao.vag...@gmail.com>

Pessoal,

Estou fazendo uma galeria com o cake, e o que me ocorre é o seguinte, quando vou editar uma galeria, ao clicar em update, ele me faz um insert ao invez do update, olhem o action dentro do controller galleries_controller.php

function admin_edit($id = null) {
$this->layout='admin';
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Gallery', true));
$this->redirect(array('action'=>'index'));

}

if (!empty($this->data)) {
if ($this->Gallery->save($this->data)) {
$this->Session->setFlash(__('The Gallery has been saved', true));
$this->redirect(array('action'=>'index'));
} else {

$this->Session->setFlash(__('The Gallery could not be saved. Please, try again.', true));

}
}

if (empty($this->data)) {
$this->data = $this->Gallery->read(null, $id);

}

$categories = $this->Gallery->Category->find('list',array('fields'=>array('Category.id', 'Category.titulo'), 'value'=>'Category.id'));
$packages = $this->Package->find('list', array('fields'=>array('Package.id', 'Package.titulo'), 'value'=>'Package.id'));
$this->set(compact('categories', 'packages'));

}

Abaixo o Model para ver se algo esta errado com ele, pois verifiquei e não encontrei o motivo:

<?php
class Gallery extends AppModel {
var $name = 'Gallery';

//The Associations below have been created with all possible keys, those that are not needed can be removed

var $belongsTo = array(

'User' => array('className' => 'User',

'foreignKey' => 'user_id',

'conditions' => '',

'fields' => '',

'order' => ''

)

);

var $hasAndBelongsToMany = array(

'Category' => array('className' => 'Category',

'joinTable' => 'categories_galleries',

'foreignKey' => 'gallery_id',

'associationForeignKey' => 'category_id',

'unique' => true,

'conditions' => '',

'fields' => '',

'order' => '',

'limit' => '',

'offset' => '',

'finderQuery' => '',

'deleteQuery' => '',

'insertQuery' => ''

),

'Package' => array('className' => 'Package',

'joinTable' => 'galleries_packages',

'foreignKey' => 'gallery_id',

'associationForeignKey' => 'package_id',

'unique' => true,

'conditions' => '',

'fields' => '',

'order' => '',

'limit' => '',

'offset' => '',

'finderQuery' => '',

'deleteQuery' => '',

'insertQuery' => ''

)

);

}

?>

João Vagner
j...@iw2.com.br
www.iw2servers.com.br
#IW² blog [ http://iw2servers.com.br/blog ]

011 8923-9648