Last spring I developed a small project which had some types which were
basically enumerations (e.g., user roles: "student, teacher, admin" and
multiple choice question categories). I had them listed as
relationships to other entities (a user had a role, a question had a
category) and I set up the relationship to use the ids of the entities.
Now, however, I'm revisiting this project and when I started it, I
realized my roles had not been loaded into the database. I can do that
manually, but if I give my students this code to work on, they'll all
have to populate the database manually, too. In addition, if I add new
roles, I'll need to make sure their ids are different than the old
ones. If I were to accidentally muff the role table, I would have to
make sure that when I recreated it, the ids of the roles matched the
previous ones.
So, here's what I'm wondering:
Should I, instead, have the relationship key on the values of the
enumerated objects (which are just Strings) so that, as long as I don't
change them, they are interchangeable without even knowing what the PKs
are. Currently, these are all subclasses of an Enum object which has a
convenience method to get an object given the class and value I'm
looking for. I was thinking of creating a static initializer for the
classes that checks to make sure the number of values matches the
number defined in the class and inserts any that are missing. That way,
I can add categories,
This archive was generated by hypermail 2.0.0 : Tue Aug 03 2004 - 19:56:59 EDT