Have a table that has two three fields.Originally posted by: krwell
I'm storing this in a relational database and these will be about up to 8 levels deep.
Two problems with that:Originally posted by: EagleKeeper
Have a table that has two three fields.
First field is the primary node
Second field is for any parent nodes.
Third field is for any child nodes.
Originally posted by: kamper
Two problems with that:Originally posted by: EagleKeeper
Have a table that has two three fields.
First field is the primary node
Second field is for any parent nodes.
Third field is for any child nodes.
-putting multiple values in a single field is not a good thing
-duplicating the data about parent/child relationship is a bad idea. What if record A thinks it's the parent of record B but record B doesn't think it's a child of record A?
My suggestion is that you look at this more like a directed graph than a hierarchy, if that's appropriate. Have a table with all the info you need in it but with no information about relationships. Have a second table with two fields called "parent" and "child" and make them foreign keys back to the primary key of the main table. The one problem I see with that is that there's no guarantee against loops, but that's a pretty hard thing to do with a relational database anyway, I think.
Incest no, but denial of relationship is a nobrainer. You either allow nodes to dicate who their parents are or who their children are but not both. Duplicating information is one of the first things every programmer should learn not to do.Originally posted by: EagleKeeper
As you agree, there is no way to prevent an incest relationship or a denial of relationship between the two relatives.
No, it's quite different. The parent/child relationships have nothing to do with primary keys and I don't see why you want to make it part of the key. Where the data for the relationship is stored is very relevant because many-to-one relationships should not be modeled in a single table.The people impilmenting the database will have to make sure that the rules are follwed by the user or the implimentation.
What you are talking about foriegn keys seems to be juut a differnt sysntax/implimention of my schema option. You end up with 3 keys to create a single unique record. Where that data for that record is stored should become irrelevant.