I have this stru开发者_Python百科cture...
grandpa hasMany children, children hasMany kids
can i make a tree of those 3 tables? I think my question really is, can i use only those tables without creating another one to make a tree structure?
I don't think you can, because a tree behavior is for 1 table.
But you could use a table persons
, persons_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
+--------------------+
Both parent_id
and kid_id
would point to person_id
You could do differents model that points to differents foreign key in the persons_kids
table.
Good luck.
For more info see the Cookbook
精彩评论