Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymorphic Lists and relational database

I've got an issue modelling a database to store some Java Objects (classical problem of mapping objects to a relational database). A example beeing far better than a long description, here's the stuff.

List of avaliable classes :
- Class A contains an array of doubles
- Class B contains an array of A
- Class C contains an array of B and an array of A (it can go on like that...)

All the objects implements the same parent (let's say StorableObject). There can be as many combinaisons as possible.

How can I store all theses values, and moreover, how can I create a model using some FK that deletes all its child when a parent object is deleted. I mean, since the childs can be stored in various tables, there's no way I can put a simple FK on the parent's field.

Thanks ;)

like image 216
radada Avatar asked Feb 26 '23 05:02

radada


1 Answers

You've read too many OO books and not one RDB book. Model the data, as data, first. Ensure all your data requirements (as per your question) are satisfied. Then model your objects after the entities.

There are hundreds of identical questions on SO, by people who have arrived at the exact same obstacle. Different table and column names, but the same identical problem. Fowler brought all of you here.

To examine your data closely and provide a useful answer, we need to see your DDL or class diagram or whatever you have.

like image 63
PerformanceDBA Avatar answered Mar 07 '23 15:03

PerformanceDBA