将树数据保存在数据库中(家谱)

发布于 2024-11-14 17:43:59 字数 1593 浏览 6 评论 0原文

我正在尝试存储一棵家谱。 这是我正在使用的平台,Zend框架,Mysql,Ajax 我搜索了 stackoverflow,发现了这篇文章,它对于处理对象数据非常有帮助。

“家谱”数据结构

我将简要说明我的用例。 用户可以根据数据库中定义的少量关系来创建家庭成员或朋友。我也有关系模型。用户可以创建家庭成员,例如离婚配偶、朋友。最大树的深度可以是我们为孙子的孩子假设的最大深度,但它的宽度也可以扩展。兄弟/姐妹&他们的家人。

我正在寻找一种有效的数据库设计来减少查询时间。如果我必须使用上面帖子中描述的数据结构,我必须保留它们,因为它们必须是模型。

为了表示,我计划使用可视化:组织结构图 http://code.google.com/apis/ Chart/interactive/docs/gallery/orgchart.html#Example

我将总结我需要什么

  1. 数据库设计
  2. 放置控制器(ajax)和模型
  3. 用户将创建的人不会是任何其他用户。只是一些其他数据

,是的,就是这样!当我完成该项目时,我将在此线程上发布完整的解决方案,当然是在你们的专业知识的帮助下

预先感谢

编辑我我将贡献更多内容来阐述我的情况

我有一个用户表,一个关系表,&最后一个家庭/家谱表

家庭表必须具有与以下类似的结构。

ID        userid              relation id             Name

1         34                   3 // for son             ABC
2         34                   4 // for Wife            XYZ
3         34                   3 // for Mom             PQR
4         34                   3 // for DAd             THE
5         34                   3 // for Daughter        GHI
6         34                   3 // for Brother         KLM

这种方法的缺点是生成与其他节点(如儿媳、妻子的兄弟和家庭)的关系。他们的家人。

理想的做法是,对于用户,我们可以添加父母、兄弟姐妹、孩子和父母。对于额外的关系,它们必须从家庭成员关系中衍生出来,即姐夫必须从姐妹的丈夫或妻子的兄弟中衍生出来。

这是我现在能想到的。我只需要实施指南。

希望这可以帮助你们提供更好的解决方案。

I am trying to store a family tree.
Here is the platform that I am using, Zend framework, Mysql, Ajax
I have searched stackoverflow I came across this post which is very helpful in handling data in terms of objects.

"Family Tree" Data Structure

I'll Illustrate my use case in brief.
User can create family members or friends based on few relations defined in database. I have Model for relations too. User can create family members like Divorced spouse, frineds. Max the Tree can be deep that we are assuming max to kids of the grandchildren but it can expand in width too. Brother/sister & their family.

I am looking an efficient database design for lesser query time. If I have to use the data structures described in above post where I must keep them as they necessary have to be a Model.

For representation I am planning to use Visualization: Organizational Chart from
http://code.google.com/apis/chart/interactive/docs/gallery/orgchart.html#Example

I'll summarize what I need

  1. Database design
  2. Placing of controllers (ajax) & models
  3. The people that the user will create they will not be any other users. just some another data

yeah thats it! I'll post a complete solution on this thread when I'll be completing the project, of course with help of expertise of u guys

Thanks in advance

EDIT I I'll Contribute more to elaborate my situation

I have a user table, a relation table, & last family/family tree table

the Family table must have similar structure to following

ID        userid              relation id             Name

1         34                   3 // for son             ABC
2         34                   4 // for Wife            XYZ
3         34                   3 // for Mom             PQR
4         34                   3 // for DAd             THE
5         34                   3 // for Daughter        GHI
6         34                   3 // for Brother         KLM

The drawback for this approach is generating relations to the other nodes like daughter-in-law, wifes brother & their family.

The ideal way of doing is for a user we can add Parents, siblings, children & for extra relations they must be derived from the family members relation i.e. Brother-in-law must be derived as sister's husband, or wife's brother.

THis is what I can think now. I just need Implementation guidelines.

Hope this helps u guys to provide a better solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许仙没带伞 2024-11-21 17:43:59

我想从数据库的角度来看,最好像

id | name | parent_male | parent_female

其他选项是字符串前缀

id | name | prefix 
1  | Joe  | 0001
2  | Jack | 000100001 //ie. Joes son
3  | Marry| 0001 //ie. Jacks mother
4  | Eve  | 0002 // new family tree
5  | Adam | 00020001 // ie. Eves son
6  | Mark | 000200010001 // ie. Adams son

一样实现它其他(更有效的)算法(如 MPTT)假设数据是一棵树,在本例中不是(它有圆圈) 。

为了证明它可行 - 选择马克的祖父母:

--Mark
SELECT prefix FROM family_tree WHERE id = 6; 
-- create substring - trim N 4-character groups from the end where N is N-th parent generation => 2 for grandparent ==> 0002
--grandparents
SELECT * FROM family_tree WHERE prefix = '0002' 
-- same for other side of family
-- cousins from one side of family
SELECT * FROM family_tree WHERE prefix LIKE '0002%' AND LENGTH(prefix) = 12 

I guess that from the database point of view it would be best to implement it like

id | name | parent_male | parent_female

Other option would be string prefixing

id | name | prefix 
1  | Joe  | 0001
2  | Jack | 000100001 //ie. Joes son
3  | Marry| 0001 //ie. Jacks mother
4  | Eve  | 0002 // new family tree
5  | Adam | 00020001 // ie. Eves son
6  | Mark | 000200010001 // ie. Adams son

Other (more effective) algorithms like MPTT assume that the data is a tree, which in this case is not (it has circles).

To show it would work - to select Mark's grandparents:

--Mark
SELECT prefix FROM family_tree WHERE id = 6; 
-- create substring - trim N 4-character groups from the end where N is N-th parent generation => 2 for grandparent ==> 0002
--grandparents
SELECT * FROM family_tree WHERE prefix = '0002' 
-- same for other side of family
-- cousins from one side of family
SELECT * FROM family_tree WHERE prefix LIKE '0002%' AND LENGTH(prefix) = 12 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文