Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorraiho
     
    I have my simple model declared like this:

    class Addressbook extends ActiveRecord
    {
    var $belong_to = array('user');
    var $has_many = array('contacts');
    }

    class Contact extends ActiveRecord
    {
    var $belong_to = array('addressbook');
    }

    when I delete an addressbook the model doesn't remove automatically. It sets NULL contacts.addressbook_it (the foreingkey) only.
    I want that, besides deletes an addressbook, it deletes the associated contacts too.

    Does exists a way to declare the cascade in the model? ...such us this:

    ALTER TABLE `contacts`
    ADD CONSTRAINT `contacts_ibfk_1` FOREIGN KEY (`addressbook_id`) REFERENCES `addressbooks` (`id`)
    ON DELETE CASCADE ON UPDATE CASCADE;
    • CommentAuthorKaste
     

    hi, just define

    var $has_many = array('contacts'=>array('dependent'=>'destroy'));
    

    see docs at lib/AkActiveRecord/AkAssociations/AkHasMany.php