自我参照许多许多公约在CakePHP [英] Self-Referential ManyToMany Convention in CakePHP

查看:212
本文介绍了自我参照许多许多公约在CakePHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的数据模型,我可以自由地重命名以匹配 CakePHP的约定。我有一个类型的图节点,其中节点可以有任意数量的子节点和任意数量的父节点(单向关系)。

I have an existing data model where I can rename things freely to match CakePHP's conventions. I have a type of graph node, where a node can have an arbitrary number of child nodes and an arbitrary number of parent nodes (uni-directional relationships).

按照CakePHP的约定:

Here's the table of nodes, following CakePHP's conventions:

Table: nodes
Column: node_id (INT)
Column: description (TEXT)

我的问题是连接表应该是什么样子?下面是现在的样子:

My question is what the join table should look like? Here is what it looks like now:

Table: nodes_nodes
Column: parent_node_id (INT)
Column: child_node_id (INT)

文档意味着它应该是:

Table: nodes_nodes
Column: node_id (INT)
Column: node_id (INT)

请注意,两个列名称是相同的,这显然不会工作。这两列应该叫什么?或者CakePHP的约定不会处理这种情况,没有配置?

Notice that two column names are the same, which obviously won't work. What should these two columns be called? Or can CakePHP's conventions not handle this situation without configuration?

推荐答案

正如neilcrookes指出,在CakePHP中这样做。 这里是其中之一,使用User HABTM用户(朋友)作为例子。

As neilcrookes noted, there are some articles on this on the web about doing this in CakePHP. Here is one of them, using User HABTM User (friends) as an example.

在这个链接的文章中,你可以忽略User类定义后的一切,如果你不打算模型。

In that linked article, you can ignore everything after the User class definition if you aren't going to be paginating on the model.

这篇关于自我参照许多许多公约在CakePHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆