Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用不同的表创建树cakephp_Cakephp - Fatal编程技术网

如何使用不同的表创建树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模型

祝你好运


有关更多信息,请参见

为什么不制作一张表?每一排都有自己的孩子和父母。。。