Hello.

I am going to ilustrate my point with an example. I have these tables:

##########################
# BEGIN SQL STATEMENTS
##########################
CREATE TABLE `imagenes` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `nombre` tinytext collate utf8_spanish_ci NOT NULL,
  `ruta` tinytext collate utf8_spanish_ci NOT NULL,
  `esPpal` tinyint(1) NOT NULL default '0',
  `item_id` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `item_id` (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci  ;

CREATE TABLE `items` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `nombre` tinytext collate utf8_spanish_ci,
  `codigo` tinytext collate utf8_spanish_ci,
  `tallas` tinytext collate utf8_spanish_ci,
  `referencia` tinytext collate utf8_spanish_ci,
  `descripcion` text collate utf8_spanish_ci,
  `activo` tinyint(1) NOT NULL default '0',
  `categoria_id` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `categoria_id` (`categoria_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci  ;
ALTER TABLE `imagenes`
  ADD CONSTRAINT `imagenes_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES
`items` (`id`);
##########################
# END SQL STATEMENTS
##########################

With these models:

##########################
# BEGIN item.php
##########################
<?php
        class Item extends AppModel
        {
                var $name = 'Item';

                var $belongsTo = array( 'Categoria' => array('className'  =>
'Categoria',
                                                                                
                'foreignKey' => 'categoria_id'
                                                                                
                )
                                                          );

                var $hasMany = array('Imagen' => array('className' => 'Imagen',
                                                                                
                'foreignKey'  => 'item_id',
                                                                                
                'dependent'   => true
                                                                                
          )
                                                        );
        }
?>
##########################
# END item.php
##########################

##########################
# BEGIN imagen.php
##########################
<?php
        class Imagen extends AppModel
        {
                var $name = 'Imagen';

                var $useTable = 'imagenes';

                var $belongsTo = array( 'Item' => array('className'  => 'Item',
                                                                                
                 'foreignKey' => 'item_id'
                                                                                
                )
                                                          );
        }
?>
##########################
# END item.php
##########################

So, let's say that item 1 has many imagenes and I try to delete it from
a controller line this:

$this->Item->del(1,true);

The problem is that cake tries to delete the item and then it tries to
delete the images associated with the item which throws a foreign key
database engine error. I changed this behaviour by changing these lines
inside the del() function definition in /cake/libs/model/model_php4.php
and /cake/libs/model/model_php5.php:

                        if ($this->id && $db->delete($this)) {
                                $this->_deleteMulti($id);
                                $this->_deleteHasMany($id, $cascade);
                                $this->_deleteHasOne($id, $cascade);
                                $this->afterDelete();
                                $this->_clearCache();
                                $this->id = false;
                                return true;
                        }

With these ones:

                        if ($this->id) {
                                $this->_deleteMulti($id);
                                $this->_deleteHasMany($id, $cascade);
                                $this->_deleteHasOne($id, $cascade);
                                $db->delete($this);
                                $this->afterDelete();
                                $this->_clearCache();
                                $this->id = false;
                                return true;
                        }

What do you guys think? Should I report this as a bug so it will be
considered to be "fixed" in future releases? Should I stick with MyISAM
tables instead of having referential integrity in the database engine
(InnoDB tables and foreign key constraints) ?? Should I be tampering
with the core files at all??

I would like to hear your opinion on this one. Thanks.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to