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.
- bed base and mattress
- person and head
- day and evening
- watch and watch-band
- camera and flash
- dog and leash
- climber and mountain
- key and lock
- flower and petal
- bee and beehive
- car and engine
- aeroplane and pilot
- scientist and theory
- film and heroine
- doctor and nurse
- sentence and verb
- prison and prisoner
- TV and watcher
- power cord and plug
- light and switch
- Bible and reader
- phone and SIM
- flower and stem
- milk and cow
- east and west
- 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?
Leave A Comment