Use Case
What are the use cases for creating a one-to-one relationship where the parent points to the child compared to a child pointing to the parent? If there is no difference, is one preferred over the other?
Example
+---------+ +-------+ +--------+ +----------+
+ Parent + + Child + + Parent + + Child +
+---------+ +-------+ vs. +--------+ +----------+
+ idChild + --> + id + + id + <-- + idParent +
+---------+ +-------+ +--------+ +----------+
I suspect that you’d choose between these relationships depending on which entity is used first in the application. i.e. If the parent object always appears before the child object, then the relationship should be mapped from the parent to child.
1
It can effect the representation of your structure if you marshal it to XML or JSON. For example, do you want “parent” to be the top element or object, or do you want “child” to be the top element or object?
A lot of times it depends on how the application uses the data. If the primary users of a system are children, it may be more convenient to represent child -> parent
because you’re doing the lookup starting with the child ID.
In terms of database design is quite more logical to have the child store the relationship back to the parent. Primarily, because keeping the information for each child in the parent’s is inflexible (assuming you use fields for child’s IDs), like in your first example, since you cannot dynamically allocate more than a single reference to a child.
2
I was working on a software project with one-to-one relationships, in our project was the child pointing on the parent, because it just is more logical, that the child shows its parent and not other way round.
2