简体   繁体   English

PHP + MySQL-一个表保存对多个表中ID的引用

[英]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 我可以吗

  • store the particular table name in the notes table? 将特定的表名存储在notes表中? But that name can change later and the system will break 但是该名称以后可能会更改,并且系统会崩溃
  • introduce something like UNIQUE ID or a hash to all of my modules, which would be unique among different tables and store it's id in the notes table? 在我的所有模块中引入诸如UNIQUE ID或哈希值之类的东西,这在不同的表之间是唯一的,并将其ID存储在notes表中?
  • create separate notes table for every module and don't worry about code/class/table duplication? 为每个模块创建单独的注释表,不用担心代码/类/表的重复吗?

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.

相关问题 从具有相同列名 MYSQL/PHP 的引用表上的多个表中选择 - Select from multiple tables on reference table with same column name MYSQL/PHP 使用php中的mysql中的一个表从多个表中检索数据 - retrieveing data from multiple tables using one table in mysql using php 如何将数据从一个mySQL表显示到php中的多个表中? - How do I display data from one mySQL table into multiple tables in php? 如何将一个表中另一个表具有多个ID的两个表联接在一起? - How to join two tables with multiple IDs from one table used in other table? PHP从其他表的ID查询MySQL表 - PHP Query MySQL Tables from IDs from other tables 使用MySQL创建新闻流,基于提供表名和ID的一个表从3个表中进行选择 - Creation of a news flux with MySQL, select from 3 tables based on one providing table names and ids 使用PHP和来自多个表(包括“ id”参考表)的多个HTML下拉框查询MySQL结果 - Query MySQL results using PHP and multiple HTML dropdown boxes from multiple tables including 'id' reference tables 使用php和mysql从另一个表使用多个ID从表中获取数据 - get data from table using multiple IDs from another table using php and mysql 从一个数据库中的多个表中选择最新记录(MYSQL PHP) - selecting the latest record from multiple tables in one database (MYSQL PHP) 使用PHP和MySQL从多个表中选择一个唯一ID的信息 - Selecting info from multiple tables for one unique ID with PHP and MySQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM