'Relational schema for a book graph
I have the following diagram that I made to show Books and People that have relationships to them:
There are two nodes:
- Person
- Book
And Three relationships (with their properties, not shown in the graph):
- Read (date, num_stars)
- Wrote (date)
- Reviewed (date, num_stars, text_review)
If this were to be modeled in a relational database, what might the schema look like? My thought was breaking out every relationship and node out, something like:
NodePerson
- PersonID
- Name
NodeBook
- BookID
- Title
EdgeRead
- FromPersonID
- ToBookID
- date
- num_stars
EdgeWrote
- FromPersonID
- ToBookID
- date
EdgeReviewed
- FromPersonID
- ToBookID
- date
- num_stars
- text_review
Or, should all nodes be a single table? If we were to add Movies as another node, how would we show that an Review edge may go from a Person->Book OR a Person->Movie. It seems maybe a more generic way to do it might be:
Node:
- ID
- Type
- // FK from specific Edge table
Edge:
- FromID
- ToID
- Type
- // FK from specific Edge table
Are there any disadvantages of using this later approach instead?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

