« first day (2095 days earlier)      last day (563 days later) » 

2:27 PM
Hi @TehShrike
Here is a strange question
referring to this post :
68
Q: Foreign key refering to primary keys across multiple tables?

I have to two tables namely employees_ce and employees_sn under the database employees. They both have their respective unique primary key columns. I have another table called deductions, whose foreign key column I want to reference to primary keys of employees_ce as well as employees_sn. Is ...

I do have this case in my database
I have several tables like
person, society, school
and contact data for these entities
between them, i do have a table like "entity_contact"
entity_contact holds these columns :
- id (serial pk)
- type (text, holding the table name for example)
- entity (the id of the entity in the corresponding table)
- contact (the id of the contact value in the contact table)
SO, if I do need to retrieve the contact information 7 in the "person" table for person number 12, I do have this in the entity_contact table :
- id : %%WHATEVER%%
- type : 'person'
- entity : 12
- contact : 7
BUT, problem is that, in my entity_contact table, I only have 1 foreign key !! the contact field pointing to the contact table
I can't declare foreign key entity since it can point to several tables
Is there any "official" way to solve this problem?
Like declaring the foreign key as a combination of both 2 fields (type + entity)?
thanks for reading/help :)
 
 
1 hour later…
3:47 PM
@Julo0sS How many entity types do you have?
I assume each entity type has its own table?
It sounds like in this case, the correct thing to do is describe each different many-to-many relationship in its own table. i.e. you would have a person_contact table with person_id and contact_id
And if you have any tables with a one-to-many relationship with contacts instead of many-to-many, you would just add a contact_id column to that table.
 
4:01 PM
hey
yeah, I thought about it...
So, you would make a join table for each "type"
instead of doing "entity_contact" you would do : "entity_type_contact", "entity_type_contact", ...
what I thought about, (this mecanism) is to help adding new types easily later
If I want to add a new entity type like "nurseries" or "hospitals" or "anything"
then I change nothing in my structure, I just add the "nursery" table and add a new "entity_type" value
 
Any experts on MySQL database replication?
1
Q: MySQL - PhpMyAdmin Replication Reset Master Configuration to retrieve server-id

Bassem LhmMySQL server + phpmyadmin On the replication tab, it looks like someone already configured the master replication: However, I do not see the following lines in my.cnf, which should have been added at the time the master was configured : server-id=***** log-bin=****** log-error=***** How d...

 
then my "entity_contact" does not change...
 
 
1 hour later…
5:07 PM
@Julo0sS that's the traditional way to represent a many-to-many relationship between tables, yes
@Julo0sS if you're creating a new table, you'll need a new table for each many-to-many relationship that table has with other tables.
You should consider doing what the top answer in that question you linked to recommended - instead of having a different table for nursery, hospital, school, you should have one table "building" or "location" or whatever, and give it a "type" column that would describe if the building was a nursery/hospital/school
then you would have a single building_contact table describing the many-to-many relationship between buildings and contacts
and any columns specific to nurseries would go in a building_type_nursery table
@BassemLhm Shouldn't the my.cnf file have a server_id line instead of server-id? I thought the dash-separated syntax was just for the command-line
 

« first day (2095 days earlier)      last day (563 days later) »