hi folks,
i'm puzzled over this one, anyone with some solid db experience might be
able to enlighten me here.
i'm modelling a file system in a database as follows, and i can't figure out
to cleanly implement an inheritance mechanism.
i have a hierarchy of folders in an sql table. every folder has a
parentFolderID, if this value is 0 then it means it's a root folder.
then, in a 'files' table, every file has a parentFolderID to give it a
location in the structure. fairly basic.
the hard part is that each file record has an attribute 'STYLE' that can be
explicitly specified, or inherited from it's parent folder, or it's parents
parent folder, or.. all the way back to the root.
the 2 ways i've come up with representing it are:
1) if the style is being inherited, enter a null value in the STYLE field.
then to figure out what style applies to a file or folder, i trace back
through it's parentFolderID records until i find a style attribute that is
not null.
the good thing about this is that if i change the style that is applied to
the entire filesystem, it only takes one update.
the bad thing is when i want to figure out what style applies to a file, i
have to traverse back through possibly several records to locate the folder
that actually specifies the style being inherited by the file.
2) explicitly state all style values in each record.
this is good for accessing the style of a file or folder because you get it
straight out first time from the db.
the bad thing is if i update the entire file system, i might have several
hundred / thousand update sql statements to execute to update all the values
in every folder and every file. nasty!
thanks for any help, i'm really stumped with this and i'm thinking there
must be a more elegant way to implement inheritance.
thanks
tim