1

I want to persist contact details for persons. This contact details can belong to a client, or a next of kin member, or whatever other entity. I'll be using Doctrine2 in a Symfony project, that will handle the data integrity.

It is a good practice to have such contact table which stores contacts for any kind of 'parent' entity or should a I have different tables like client_contact & next of kin?

enter image description here

  • You can add a column on contact as id_contact_type and just make a table contact_type that would have id_contact_type and desc_contact_type. – oNare Aug 6 '15 at 15:39
  • I'm using Doctrine so it will handle relationships on update/delete operations, I guess I can't keep agnostic of which kind of "parent" the contact has – luso Aug 6 '15 at 15:48
2

Your current diagram is great as long as everyone only has one address, and a max of two phone numbers (apart from a fax).

One simple way this schema falls apart is if you have a client with a street address for their location, but a PO Box for their mailing address. This is a fairly common setup for rural communities in the United States. When I lived in Jackson, Wyoming I had a street address which had a different zip code from my PO Box. In addition my work address was in another city. The core point is people can easily have more than one address, which conflicts with your schema.

Personally I would break apart the address from the phone number. This gives you more freedom over your data. Entities can have addresses without phone numbers and phone numbers without addresses without risking a foreign key to a row full of nulls. Furthermore I would add a foreign key to the address and phone number tables that is just a link to a description. That way you don't need to remember "PhoneNumber2 is always a cell phone, unless this is a business in which case it is the point of contact's direct line" or other such nonsense. The foreign key to the description table will make it clear that Client X has two home landlines and no cell phones. You gain flexibility and clarity.

Overall, I still would keep one address and one phone number table that the various entities would link to via foreign keys. There is no need to duplicate schema. Keep in mind it might be advantageous to have the foreign key to the address/phone table on the entity for some entities and other entities might use a join table instead. That can be a per entity judgment call which can be adjusted over time with relatively little pain.

Also you might want to associate the "next_of_kin" table with someone (your clients?), because it seems kind of weird for them not to have kin... :)

  • thank you Erik, yes, NOK has Kins, this model is not the valid one ;) This data is actually used for filling a form which is not mine. An official form, so as long as they don't have space for more than one address, I won't need it. Thank you for the tip in the telephones, but is the same case. Just two phones. – luso Aug 7 '15 at 10:16
  • If sole goal is to match the forms then I think you are good to go with what you have. Like @EmacsUser mentioned you don't seem to have a compelling security reason to duplicate the tables, and you said all contact information will follow this same format due to the data collection method. Stick a fork in it. You're done! :) – Erik Aug 7 '15 at 14:11
1

I want to persist contact details for persons.

Since persons could include both staff and clients, the natural step would be to have a single table of contacts for all persons. As oNare suggested in a comment above, just create a contactType field in which you can assign either person type. This solution has the benefit of adding in future, if a need arises, any new person types or subtypes.

The only reason you should have clientContact and staffContact in separate tables is some compelling business reason that suggests those contacts have to be isolated from each other for security, data compatibility, access rights, data entry, and so forth.

EDITS

I still don't see the benefit of contactType, as any entry in 'contact' will be referenced by a FK either in 'staff' or 'client'.

Which table has the 'staff'? If 'staff' and 'client' are in the same table, sure there is no benefit as long as you have another way of distinguishing the two. Your schema does not show 'staff'.

If a client or staff entry is removed, its contact will be deleted using the FK.

That can be controlled depending on the database design and maintenance. Look into enabling/disabling cascading deletes whether you want to keep such records or not. Depends on your apps requirements.

0

What you have in the image is great. It's a place to put contact information for both of those other entities. I don't even understand why you'd need to have a contact type... You don't want to create two tables that contain the same columns under almost any circumstances.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.