2011年2月21日星期一

Re: [fw-db] Zend_Db_Table Issue

I coded the cascading functionality in Zend_Db_Table. I don't
recommend using it for any RDBMS, whether the RDBMS supports DRI or not.

It is not possible to implement cascading referential integrity in a
safe manner in any application-space code. It's not a matter of the
PHP code in Zend_Db_Table being good enough, it's simply not a task
that can work outside the database engine. You need to enforce
consistency through the RDBMS engine.

If your application requires cascading referential integrity, use a
storage engine that supports it, such as InnoDB, and declare RDBMS
constraints.

If you use a database engine that doesn't support DRI constraints,
then you can't rely on referential integrity and cannot use cascading
RI operations. Don't try to use application-space cascading DRI. It
doesn't work.

If I have not stated my recommendation plainly enough, feel free to
ask for clarification. :-)

Regards,
Bill Karwin

On Feb 21, 2011, at 8:39 AM, Rafael wrote:

>
> I have read but it says clearly "it is intended" it doesn't says it
> won't work. So I will test with MyISAM engine.
>
> Thanks
>
> Em 21/02/2011 13:27, Christian Proske escreveu:
>> Hy Rafael,
>>
>> have u read this:
>>
>> "Declaring cascading operations in Zend_Db_Table is intended only
>> for RDBMS brands that do not support declarative referential
>> integrity (DRI)."
>>
>> Source:http://framework.zend.com/manual/en/zend.db.table.relationships.html
>>
>> So I think that means it is NOT possible to implement DRI in ZF
>> with InnoDB, because InnoDB supportes DRI.
>>
>> Please correct me if I'm wrong.
>>
>> For more information on how to InnoDB& Foreign Key Constraints:http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
>>
>> Regards,
>> Chris
>>
>> Am 21.02.2011 um 17:12 schrieb Rafael:
>>
>>> > > Well, It doesn't thorows a exception but give that notice,
>>> my code to delete the row is below
>>> > > function deletarID($id) {
>>> > > $processo = $this->find($id);
>>> > > $result = $processo->current()->delete();
>>> > > return $result;
>>> > }
>>> > > > Em 21/02/2011 06:43, Joseph007 escreveu:
>>>> >> Hi,
>>>> >> >> Can you please provide an actual code used by you to
>>>> delete row, that
>>>> >> throws mentioned error?
>>>> >> >> Regards,
>>>> >> Joseph Chereshnovsky
>>>> >> >> On Wed, 2011-02-16 at 01:53 -0200, Rafael wrote:
>>>>> >>> Hello,
>>>>> >>> >>> I don't know if it is the right to ask however i have
>>>>> one issue that
>>>>> >>> nobody else managed to solve it.
>>>>> >>> >>> I'm using zend framework 1.11.3, PHP 5.3 and MySQL 5.1
>>>>> configured with
>>>>> >>> InnoDB engine. I'm trying to make a relationship between
>>>>> two tables
>>>>> >>> to apply cascade deletion but deletes only parental row and
>>>>> return me
>>>>> >>> >>> Notice: Undefined index: numero_atual in
>>>>> >>> C:\htdocs\Advocacia\library\Zend\Db\Table\Abstract.php on
>>>>> line 1197
>>>>> >>> >>> It happens when i try to delete one row from the model
>>>>> >>> Application_Model_ProcessosJudicial , I really can't see
>>>>> anything wrong
>>>>> >>> in the code or...
>>>>> >>> >>> I would be thankful if anyone check it for me
>>>>> >>> >>> class Application_Model_ProcessosJudicial extends
>>>>> Zend_Db_table {
>>>>> >>> >>> protected $_name = "processos_judicial";
>>>>> >>> protected $_dependentTables =
>>>>> array('Application_Model_Partes',
>>>>> >>> 'Application_Model_Andamentos');
>>>>> >>> >>> protected $_referenceMap = array(
>>>>> >>> 'Andamento' => array(
>>>>> >>> 'columns' => array('numero_atual'),
>>>>> >>> 'refColumns' => array('numero_atual'),
>>>>> >>> 'refTableClass' =>
>>>>> 'Application_Model_Andamentos',
>>>>> >>> 'onDelete' => self::CASCADE,
>>>>> >>> 'onUpdate' => self::RESTRICT
>>>>> >>> )
>>>>> >>> );
>>>>> >>> >>> }
>>>>> >>> >>> >>> class Application_Model_Andamentos extends
>>>>> Zend_Db_table {
>>>>> >>> >>> protected $_name =
>>>>> "processos_andamentos_judicial";
>>>>> >>> >>> protected $_referenceMap = array(
>>>>> >>> 'Andamento' => array(
>>>>> >>> 'refTableClass' =>
>>>>> 'Application_Model_ProcessosJudicial',
>>>>> >>> 'refColumns' => array('numero_atual'),
>>>>> >>> 'columns' => array('numero_atual'),
>>>>> >>> 'onDelete' => self::CASCADE,
>>>>> >>> 'onUpdate' => self::RESTRICT
>>>>> >>> )
>>>>> >>> );
>>>>> >>> >>> }
>>>>> >>> >>> My table structure
>>>>> >>> >>> >>> CREATE TABLE IF NOT EXISTS
>>>>> `processos_andamentos_judicial` (
>>>>> >>> `id` int(11) NOT NULL AUTO_INCREMENT,
>>>>> >>> `numero_atual` varchar(30) CHARACTER SET latin1 DEFAULT
>>>>> NULL,
>>>>> >>> `data` datetime DEFAULT NULL,
>>>>> >>> `andamento` varchar(60) CHARACTER SET latin1 DEFAULT
>>>>> NULL,
>>>>> >>> `complemento` varchar(60) CHARACTER SET latin1 DEFAULT
>>>>> NULL,
>>>>> >>> `observacao` longtext CHARACTER SET latin1,
>>>>> >>> `tipo_processo` varchar(45) CHARACTER SET latin1
>>>>> DEFAULT NULL,
>>>>> >>> PRIMARY KEY (`id`),
>>>>> >>> KEY `numero` (`numero_atual`)
>>>>> >>> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
>>>>> >>> >>> CREATE TABLE IF NOT EXISTS `processos_judicial` (
>>>>> >>> `id` int(11) NOT NULL AUTO_INCREMENT,
>>>>> >>> `numero_atual` varchar(30) CHARACTER SET latin1 DEFAULT
>>>>> NULL,
>>>>> >>> `numero_antigo` varchar(30) CHARACTER SET latin1
>>>>> DEFAULT '',
>>>>> >>> `data_distribuicao` date DEFAULT NULL,
>>>>> >>> `orgao` varchar(30) CHARACTER SET latin1 DEFAULT NULL,
>>>>> >>> `circunscricao` varchar(30) CHARACTER SET latin1
>>>>> DEFAULT NULL,
>>>>> >>> `local` varchar(30) CHARACTER SET latin1 DEFAULT NULL,
>>>>> >>> `feito` varchar(30) CHARACTER SET latin1 DEFAULT NULL,
>>>>> >>> `rito` varchar(45) CHARACTER SET latin1 DEFAULT NULL,
>>>>> >>> `fase` varchar(45) CHARACTER SET latin1 DEFAULT NULL,
>>>>> >>> `encerrado` tinyint(1) DEFAULT NULL,
>>>>> >>> `encerrado_data` date DEFAULT NULL,
>>>>> >>> `encerrado_motivo` varchar(45) CHARACTER SET latin1
>>>>> DEFAULT NULL,
>>>>> >>> `suspenso` tinyint(1) DEFAULT NULL,
>>>>> >>> `suspenso_data` date DEFAULT NULL,
>>>>> >>> `valor_causa` varchar(30) CHARACTER SET latin1 DEFAULT
>>>>> NULL,
>>>>> >>> `assistencia_gratuita` tinyint(1) DEFAULT NULL,
>>>>> >>> `percentual` varchar(30) CHARACTER SET latin1 DEFAULT
>>>>> NULL,
>>>>> >>> `resumo` varchar(30) CHARACTER SET latin1 DEFAULT NULL,
>>>>> >>> `ultima_modificao` datetime DEFAULT NULL,
>>>>> >>> `criacao` datetime DEFAULT NULL,
>>>>> >>> PRIMARY KEY (`id`),
>>>>> >>> KEY `numero_atual` (`numero_atual`)
>>>>> >>> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=43 ;
>>>>> >>> >>> >>>
>>>> >> >> >>
>>> >
>

没有评论: