How to implement a self referencing (parent_id) model in cakephp

后端 未结 6 1073
悲&欢浪女
悲&欢浪女 2021-02-06 06:35

I have a table called categories. The table holds categories and their sub(subsub)categories...

Its an easy table:

  • id
  • parent_id
  • title
6条回答
  •  庸人自扰
    2021-02-06 07:06

    Look at the tree behaviour; with MPTT logic. The link supplied to Oracle's website is dead; but you can find a bunch of material about how to use it on the cake manual and online.

    CREATE TABLE categories (
        id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
        parent_id INTEGER(10) DEFAULT NULL,
        lft INTEGER(10) DEFAULT NULL,
        rght INTEGER(10) DEFAULT NULL,
        name VARCHAR(255) DEFAULT '',
        PRIMARY KEY  (id)
    );
    

    Just make sure your table matches that structure for best results within Cake and it's baking.

提交回复
热议问题