[英]PHP + MySQL - one table holding reference to IDs from multiple tables
I just would like to know what are the most common approaches to get a table to hold a reference to IDs from multiple tables. 我只想知道最常用的方法是使一个表包含多个表中对ID的引用。
I have a system with modules like customers, suppliers, orders, etc. and I would like to add a "Notes" functionality to all of those modules to be able to add/read notes. 我有一个包含客户,供应商,订单等模块的系统,并且我想向所有这些模块添加“便笺”功能,以便能够添加/阅读便笺。
As one customer/supplier/order can have multiple notes, I have chosen the one-to-many relation way and so the notes in their table should refer to the particular item id in a separate column. 由于一个客户/供应商/订单可以有多个注释,因此我选择了一对多的联系方式,因此,他们表中的注释应在单独的列中引用特定的物料ID。 But as I will refer to IDs from multiple tables, their IDs will be overlapping and I need a way to say in which particular table to search for that ID. 但是,当我从多个表中引用ID时,它们的ID将重叠,因此我需要一种方法来说明要在哪个特定表中搜索该ID。
I don't want to create exact the same notes module for each of my modules and here I could concentrate notes in one table. 我不想为每个模块创建完全相同的便笺模块,在这里我可以将便笺集中在一个表中。 Those notes differ only in the fact, to which module they belong to. 这些注释仅在事实上有所不同,它们属于哪个模块。
Shall I 我可以吗
Thanks for your ideas! 感谢您的想法!
We do something similar with notes that can be attached to many objects. 我们对可以附加到许多对象的注释进行了类似的处理。 Each of our objects has a unique class id (we store each type of object in it's own table), and we store the unique class id + specific object id in the notes table. 我们的每个对象都有一个唯一的类ID(我们将每种类型的对象存储在其自己的表中),并且将唯一的类ID +特定的对象ID存储在notes表中。
We then just have to maintain a lookup of unique class id -> table name. 然后,我们只需要维护唯一类ID->表名的查找。 By using the unique class id + object id as the key we ensure that the same id in different tables isn't an issue. 通过使用唯一的类ID +对象ID作为键,我们确保不同表中的相同ID不成问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.