CakePHP 中的自引用多对多约定 [英] Self-Referential ManyToMany Convention in CakePHP

查看:25
本文介绍了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)

文档暗示它应该是什么:

And what the documentation implies it should be:

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 中执行此操作的文章.这里就是其中之一,以用户 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天全站免登陆