如何使用不同的表创建树cakephp
我有这个结构 爷爷有很多孩子,孩子们有很多孩子如何使用不同的表创建树cakephp,cakephp,Cakephp,我有这个结构 爷爷有很多孩子,孩子们有很多孩子 我能把那三张桌子做成一棵树吗?我想我的问题是,我可以只使用这些表而不创建另一个表来创建树结构吗 我认为您不能,因为树行为适用于1个表 但是您可以使用表persons,persons\u kids +--------------------+ | persons | +--------------------+ | id | Name | +--------------------+ | 1 | Gr
我能把那三张桌子做成一棵树吗?我想我的问题是,我可以只使用这些表而不创建另一个表来创建树结构吗 我认为您不能,因为树行为适用于1个表 但是您可以使用表
persons
,persons\u kids
+--------------------+
| persons |
+--------------------+
| id | Name |
+--------------------+
| 1 | Grandpa |
+--------------------+
| 2 | Dad |
+--------------------+
| 3 | Me |
+--------------------+
| 5 | MyChildren |
+--------------------+
| 4 | MyBrother |
+--------------------+
+--------------------+
| persons_kids |
+--------------------+
| parent_id | kid_id |
+--------------------+
| 1 | 2 | // Grandpa -> Dad
+--------------------+
| 2 | 3 | // Dad -> Me
+--------------------+
| 2 | 3 | // Dad -> MyBrother
+--------------------+
| 3 | 5 / // Me -> MyChildren
+--------------------+
parent\u id
和kid\u id
都指向person\u id
您可以在persons\u kids
表中创建指向不同外键的differents模型
祝你好运
有关更多信息,请参见为什么不制作一张表?每一排都有自己的孩子和父母。。。