开发者

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 interg开发者_如何学JAVArity? 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜