Optional one-to-one relationships

Optional one-to-one relationship are more common than mandatory one-to-one relationships, both in life and in data modelling.
Sometimes an object may be optionally connected to at least one other object. One example is a car, which may be registered or licensed for use on the road or it may be allowed to be kept only for display or show purposes. The car is one object, the registration or licence is an optional extra.

Sub-classing

The other common use is in sub-classing which can be very similar in application. Imagine that information about all the dogs that live in a particular area is stored by the local government department. In the wisdom of this department, some breeds of dog are considered dangerous and more information must be stored about them. Various details about all dogs might be stored in one table (including dangerous dogs), while some extra information would be stored in another table about ‘dangerous dogs’.

Each dangerous dog will have a row in each of the two tables, and the two tables may even use the same unique object identifier for the rows that describe a particular dog in each table.

Examples / Test

We have looked at one-to-one relationships, so now let’s do a quick self-test to get you thinking. Here is a list of items that are, or may be related in some way. I have used the singular throughout, but don’t let that mislead you. Read through them quickly and decide whether they are genuine or contrived, optional or mandatory, one-to-one or something else. They are all numbered for ease of reference.

  1. bed base and mattress
  2. person and head
  3. day and evening
  4. watch and watch-bandDoes a compass have an optional one-to-one relationship with direction?
  5. camera and flash
  6. dog and leash
  7. climber and mountain
  8. key and lock
  9. flower and petal
  10. bee and beehive
  11. car and engine
  12. aeroplane and pilot
  13. scientist and theory
  14. film and heroine
  15. doctor and nurse
  16. sentence and verb
  17. prison and prisoner
  18. TV and watcher
  19. power cord and plug
  20. light and switch
  21. Bible and reader
  22. phone and SIM
  23. flower and stem
  24. milk and cow
  25. east and west
  26. child and parent

Some of these stand out from the others as just a little strange. Is there really a relationship between east and west? Instead of there being any sort of object relationship, east and west are, if you like, simply different values of an attribute “direction”.

In the above, did you find any mandatory or optional one-to-one relationships? If you did, were they genuine or contrived? A person isn’t a person without a head. A power cord isn’t a power cord without a plug. Would you say a flower is complete without a stem?