Say I have two classes Laptop and Lcd. Let’s now assume each Laptop can have only one Lcd and an Lcd can only be installed on one Laptop at any time. Let’s also assume an Lcd can be removed from one Laptop and installed on another. So this is a one-to-one association from Laptop to Lcd.
Now the question is, how to design the db schema for this one-to-one relationship?
Many thanks,
Bryan
The easiest way to model this would be to place a foreign key in the LCD table that links back to the Laptop table. Make that column non-nullable and unique.
(It’s also worth noting that this same approach would work the other way around–with the
Laptoptable having a non-nullable unique foreign key to theLCDtable).