当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - CakePHP and referential integrity

问题描述:

My DB server doesn't support innodb engine, so I can't use Foreign key

costraints at DB level.

How can I assure referential intergrity? Can I do this using cakephp model,

how?

网友答案:

As long as you define your model associations properly, you should be ok. If you're worried about orphan records when deleting records, you can set 'dependent'=> true in your associations.

http://book.cakephp.org/view/1039/Associations-Linking-Models-Together#hasMany-1043

网友答案:

I'm using myISAM engine on my tables with cakePHP, had no problems so far =).

foreign keys are defined in model like this:

// this is a property of Post Model

    var $belongsTo = array(
    'PostCategory' => array(
        'className' => 'PostCategory',
        'foreignKey' => 'post_category_id',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);  

this means that current model is associated with PostCategory model using post_category_id column as a foreign key.

分享给朋友:
您可能感兴趣的文章:
随机阅读: