*Table "Recharges"*

CREATE TABLE `recharges` (`id` INT(11) NOT NULL AUTO_INCREMENT,`name`
VARCHAR(45) NULL DEFAULT NULL,`created` DATETIME NULL DEFAULT
NULL,`modified` DATETIME NULL DEFAULT NULL,`type_recharge_id` INT(11)
NOT NULL,`date_achat` DATE NULL DEFAULT NULL,`montant_recharge_id`
INT(11) NOT NULL,`sn` VARCHAR(45) NULL DEFAULT NULL,`date_expiration`
DATE NULL DEFAULT NULL,`carte_sim` TEXT NULL,`validite_recharge_id`
INT(11) NOT NULL,`date_consommation` DATE NULL DEFAULT
NULL,`acheteur_id` INT(11) NULL DEFAULT NULL,`visible` TINYINT(4) NOT
NULL DEFAULT '0',`conso_suj_id` INT(10) NULL DEFAULT NULL,`creator_id`
INT(10) NULL DEFAULT NULL,`last_user_id` INT(10) NULL DEFAULT
NULL,PRIMARY KEY (`id`),INDEX `fk_recharges_type_recharges1`
(`type_recharge_id`),INDEX `fk_recharges_montant_recharges1`
(`montant_recharge_id`),INDEX `fk_recharges_validite_recharges1`
(`validite_recharge_id`),INDEX `fk_acheteur_recharges`
(`acheteur_id`),CONSTRAINT `fk_acheteur_recharges` FOREIGN KEY
(`acheteur_id`) REFERENCES `whos` (`id`),CONSTRAINT
`fk_montant_recharges` FOREIGN KEY (`montant_recharge_id`) REFERENCES
`montant_recharges` (`id`) ON UPDATE NO ACTION ON DELETE NO
ACTION,CONSTRAINT `fk_type_recharges_recharges` FOREIGN KEY
(`type_recharge_id`) REFERENCES `type_recharges` (`id`),CONSTRAINT
`fk_validite_recharge_recharges` FOREIGN KEY (`validite_recharge_id`)
REFERENCES `validite_recharges` (`id`)
)COLLATE='latin1_swedish_ci'ENGINE=InnoDBAUTO_INCREMENT=50;


*"Montant_recharges" Table*

CREATE TABLE `montant_recharges` (`id` INT(11) NOT NULL
AUTO_INCREMENT,`name` FLOAT NULL DEFAULT NULL,`created` DATE NULL
DEFAULT NULL,`modified` DATE NULL DEFAULT NULL,`creator_id` INT(11)
NULL DEFAULT NULL,`last_user_id` INT(11) NULL DEFAULT NULL,PRIMARY KEY
(`id`)
)COLLATE='latin1_swedish_ci'ENGINE=InnoDBAUTO_INCREMENT=16;

*rechargeModel*
public $belongsTo = array(
                'MontantRecharge' => array(
                        'className' =>  'MontantRecharge',
                        'foreignkey' => 'montant_recharge_id',
                        'conditions' => '',
                        'fields' => '',
                        'order' =>''
                        ));
*
montant_recharges Model
*
public $hasMany = array(
                                                        'Recharge' => array(
                                                        'className' => 
'Recharge',
                                                        'foreignKey' => 
'montant_recharge_id',
                                                        'conditions' => '',
                                                        'order' => '',
                                                        'limit' => '',
                                                        'dependent'=> true
                                                        )
                        );


*MontantRechargesController*
    function admin_delete( $id ){
        if($this->RequestHandler->isAjax()){
            $this->layout = null;
            if($this->{$this->modelClass}->delete( $id )){
                $this->Session->setFlash(
__('MontantRecharge_Delete_OK'),'notif',array('type' => 'success'));
                $this->Result['status'] = 1;
            }else{
                $this->Session->setFlash(
__('MontantRecharge_Delete_KO'),'notif',array('type' => 'error'));
                $this->Result['status'] = 0;
            }
            echo json_encode($this->Result);
            exit();

        }else{
            if($this->{$this->modelClass}->delete( $id )){
                $this->Session->setFlash(
__('MontantRecharge_Delete_OK'),'notif',array('type' => 'success'));
            }else{
                $this->Session->setFlash(
__('MontantRecharge_Delete_KO'),'notif',array('type' => 'error'));
            }
            $this->redirect( $this->referer() );
        }
    }



When I delete a montant_recharge even if it is use in the recharge table
the all row in recharge is deleted.

What is expected is that i can't delete a montant_recharge if it is used in
another table.

When i do the query directly in mysql it work
If i do delete from montant_recharge where id=xx
i can't the message
---------------------------
Error
---------------------------
SQL Error (1451): Cannot delete or update a parent row: a foreign key
constraint fails (`fournitures`.`recharges`, CONSTRAINT
`fk_montant_recharges` FOREIGN KEY (`montant_recharge_id`) REFERENCES
`montant_recharges` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)
---------------------------
OK
---------------------------















On Fri, Oct 12, 2012 at 2:02 PM, Jonathan Sundquist <[email protected]>wrote:

> What does the code look like?
>
> - "The cold winds are rising"
> On Oct 12, 2012 6:31 AM, "Webmaster Cosinus" <[email protected]> wrote:
>
>> I've a table called "recharges"  and onother called "montant_recharges"
>>
>> In the recharge table I've a filed called montant_recharge_id which link
>> the two tables.
>>
>> When I delete a row in "montant_recharges" the associated row in
>> recharges are deleted, i don't want rows in recharge to be deleted neither
>> in montant_recharges since they are linked
>>
>>
>> On Fri, Oct 12, 2012 at 1:02 PM, Tilen Majerle 
>> <[email protected]>wrote:
>>
>>> i don't understand what u want..
>>> --
>>> Lep pozdrav, Tilen Majerle
>>> http://majerle.eu
>>>
>>>
>>>
>>> 2012/10/12 cosinusweb <[email protected]>
>>>
>>>> Hello,
>>>>
>>>> I' ve a table "recharge" which contain an id field from an other table.
>>>>
>>>> When I try to delete the linked id from mysql it does not work which is
>>>> normal because this id is already in use bu if i delete the liked id with
>>>> cake php the all row from "recharges" is deleted
>>>>
>>>> It s like cake does not take into acount my constraint
>>>>
>>>> Why that ?
>>>>
>>>> --
>>>> Like Us on FaceBook https://www.facebook.com/CakePHP
>>>> Find us on Twitter http://twitter.com/CakePHP
>>>>
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "CakePHP" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>>>>
>>>>
>>>>
>>>
>>>  --
>>> Like Us on FaceBook https://www.facebook.com/CakePHP
>>> Find us on Twitter http://twitter.com/CakePHP
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "CakePHP" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>>>
>>>
>>>
>>
>>  --
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find us on Twitter http://twitter.com/CakePHP
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "CakePHP" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>>
>>
>>
>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.


Reply via email to