问题标签 [junction-table]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
3407 浏览

php - php - 从mysql返回多个值

我正在处理产品和类别之间多对多关系的连接表。通过这个特定的函数,我试图接受一个 product_ID 变量并在一个数组中获取所有相关的类别名称。但是,在当前设置下,当我知道有几个产品 ID 有 2 个时,我只能获得每个产品 ID 的一个类别。有什么想法吗?还有人知道一个很好的简单解决方案,可以更直观地跟踪 mysql 中的 M2M 关系吗?

0 投票
2 回答
974 浏览

mysql - SQL n:n - 联结表中查询的最佳实践

我知道 SQL n:n 查询已经开始了很多问题。但是我找不到我的问题的解决方案。

我想创建一个类似于个人词库的项目。在其中,用户可以定义哪个单词与其他单词相关。我有两张桌子:

查找 house 的所有同义词相当容易:

但是,为了确保,我还找到了仅在“word2”列中列出的单词,我实际上需要 2 个查询:

如何将这 2 个查询放在一个查询中以获得更快的结果?

0 投票
2 回答
2734 浏览

junction-table - 配置 WebSEAL 联结映射

嗨,我正在尝试配置我的 jmt.conf 文件。尽管我在其中写了联结名称。当我尝试使用服务器任务命令加载表时,它让我无法访问服务器

0 投票
1 回答
1464 浏览

sql - What is the necessity of junction tables?

I have implemented the following ways of storing relational topology:

1.A general junction relation table:

Table: Relation

Columns: id parent_type parent_id parent_prop child_type child_id child_prop

On which joins are not generally capable of being executed against by most sql engines.

2.Relation specific junction tables

Table: Class2Student

Columns: id parent_id parent_prop child_id child_prop

On which joins are capable of being executed against.

3.Storing lists/string maps of related objects in a text field on both bidirectional objects.

Class: Class

Class properties: id name students

Table columns: id name students_keys

Rows: 1 "history" [{type:Basic_student,id:1},{type:Advanced_student,id:3}]

To enable joins by the sql engines, it would be possible to write a custom module which would be made even easier if the contents of students_keys was simply [1,3], ie that a relation was to the explicit Student type.

The questions are the following in the context of:

I fail to see what the point of a junction table is. For example, I fail to see that any problems the following arguments for a junction table claim to relieve, actually exist:

  • Inability to logically correctly save a bidirectional relations (eg there is no data orphaning in bidirectional relations or any relations with a keys field, because one recursively saves and one can enforce other operations (delete,update) quite easily)
  • Inability to join effectively

I am not soliciting opinions on your personal opinions on best practices or any cult-like statements on normalization.

The explicit question(s) are the following:

  1. What are the instances where one would want to query a junction table that is not provided by querying a owning object's keys field?
  2. What are logical implementation problems in the context of computation provided by the sql engine where the junction table is preferable?
  3. The only implementation difference with regards to a junction table vs a keys fields is the following:

When searching for a query of the following nature you would need to match against the keys field with either a custom indexing implementation or some other reasonable implementation:

class_dao.search({students:advanced_student_3,name:"history"});

search for Classes that have a particular student and name "history"

As opposed to searching the indexed columns of the junction table and then selecting the approriate Classes.

I have been unable to identify answers why a junction table is logically preferable for quite literally any reason. I am not claiming this is the case or do I have a religious preference one way or another as evidenced by the fact that I implemented multiple ways of achieving this. My problem is I do not know what they are.

0 投票
0 回答
195 浏览

database-design - 关系数据库:具有第三个外键的联结表仍然是联结表..还是实体?

我有一个联结表(Actor_Character),其中一个复合键由另外两个表(Actor & Character)的主键组成。因为它是一个联结表 Actor 和 Character 也都是外键。现在,如果我向此联结表添加第三个外键 (DVD),它会成为一个实体吗?通常,如果您将新的非键属性添加到联结表,它确实会成为一个实体。但是,在这种情况下,我没有添加非键属性(它是外键),它也不是真正的新属性——DVD 实体已经存在于其他地方,其中 DVD_ID 作为它的主键。

我要解决的整体业务问题是:

如果客户有一张 DVD 并且知道里面有哪些演员,他们如何找出其中一位演员在 DVD 中扮演的角色。

我的解决方案是通过以下方式查询这两个联结表 (DVD_Actor) & (Actor_Character):

我遇到的问题是:如何在我的 ER 图中表示这一点?它是实体还是连接表?

0 投票
1 回答
632 浏览

database-design - 三通接线表好吗?或者它是一个实体?

是否允许具有三个主键/外键的连接表?或者,当我添加第三个主键/外键时,我原来的仅链接两个表的连接表是否会成为一个实体。

我需要知道它是实体还是三向连接表,因为连接表未显示在 ER 图上。

0 投票
1 回答
154 浏览

mysql - 使用联结表的查询交集

我用谷歌搜索,但找不到合适的回复。

我有两张桌子 -

我创建了一个连接表,看起来像 -

在联结表中,两个值的组合是主键。我想找出哪些学生参加了第 1 和第 2 课,即他们在表格连接中有一个条目,上面写着同一个学生 ID 的教室 ID = 1 和教室 ID = 2。

我尝试在互联网上查找,但找不到实现此目的的方法。

我不是在寻找直接的答案。任何指向正确方向的指针也足够了。

谢谢!

0 投票
2 回答
1299 浏览

c# - NHibernate - 使用连接/连接表的多对多查询

我在这里发现了非常相似的问题,但没有一个与我正在寻找的完全匹配。我发现的两个最接近的线程是(是的,它们是不同的线程):

NHibernate 多对多标准(1)

NHibernate 多对多标准(2)

但是,我认为这两者都使用直接的多对多关系。我实际上是通过与联结表建立两个一对多关系来模拟多对多关系,这是非常标准的做法。这是我的 NHibernate 映射:

文件:

属性:

细木工:

所以我的问题与上面的第二个链接完全一样,但使用连接表完成。所以:

给定一组属性 ID,我希望运行一个查询,为我提供具有所有这些匹配属性的文件。我可以轻松地为集合中的每个属性 ID 运行“n”个查询,并比较每个列表中出现在每个列表中的文件 ID,但我觉得应该有一种更简单的方法可以通过一个查询一次完成所有操作。

例子:

鉴于这些属性:mode = read-onlyand view = visible,我只想返回foo.txtand goose.txt

谁能帮我这个?谢谢。

0 投票
1 回答
197 浏览

c# - 使用 LINQ 获取连接表中的最大计数

我在 Stackoverflow 上经历了很多问题,恐怕我仍然找不到答案。我正在使用实体框架。使用 LINQ,我试图找到过去 7 天内最受欢迎的课程。我有四个表参与查询,Schedules、Sessions、Locations 和联结表 ClientSessions

时间表的模型是

会话模型

Junction ClientSession 表

我编写了以下 SQL 代码,它按预期工作,但恐怕我没有足够的知识或经验将其转换为 Linq。

这是我设法得到的

向我展示如何完成其​​余部分的任何帮助将不胜感激。

提前感谢您的任何帮助。

0 投票
1 回答
311 浏览

doctrine - 与 Doctrine 连接表中的鉴别器

我有许多不相关的实体,我希望能够将 FileAttachment 实体添加到其中。我正在使用 Doctrine2(在 Symfony 项目的上下文中)。

在我开始使用 Doctrine 之前,我会制作一个带有鉴别器列的连接表,如下所示:

据我所知,对于 Doctrine,我需要为每个具有 FileAttachment 关联的实体类型提供一个联结表。如果可能的话,我宁愿避免这种情况。我在这里找到了 NHibernate 解决方案。是否有可能用 Doctrine 做类似的事情,有人可以指点我一些文档吗?我已经阅读(现在很多次了!)Doctrine 手册的第6章和第7章。但我没有找到我要找的东西。