I've been struggling with a problem for a little bit now. Help would be much appreciated.
Here it is:
I have two data structures, ObjClass and Obj, where Obj is an specialization of ObjClass. An Obj may have multiple "Slots", each with its own type. The total Slots an Obj has is the Union of his own Slots with the Slots of his ObjClass. Here's the simplified schema(bear with me if it has syntax errors):
create table ObjClass(
ObjClassId integer not null primary key
)
create table Obj(
ObjId integer not null primary key,
ParentClass integer,
foreign key(ParentClass) references ObjClass(ObjClassId)
)
create table Slot(
SlotId integer not null primary key,
SlotType integer
)
What I'm asking is: the Slot table has a 1-n relationship with ObjClass OR Obj, but never both. How do I enforce this on SQLite?
P.S.: I can guess this problem is probably caused by bad database design. Any thoughts on how to achieve a similar structure with a better design are also appreciated.
Thanks!