Got a bit of a problem here, and one of my difficulties is that I just don’t know the right terms to search for. Also, late at night here, so I apologize for any rambling and/or conceptual confusion. Not drunk -- just tired.
Let’s use a drop-down select menu as an example. We have six entries, drawn from a lookup table, and four of those entries need to hide or show different content on the page itself, such as additional or fewer form fields. Two don’t do anything explicit to the rest of the page content (as an example of null cases).
I would like to know what you use to “flag” those four entries such that the in-page code knows what to do when any one of those four items are selected in the drop-down menu.
The actions themselves are irrelevant, but could be as simple as expanding the form to include additional fields to fill out or select, or hiding parts of the form that are no longer relevant. The key thing is, however, that each of the four do something unique and different.
Up until now, I have used either one of two different methods.
One method is to add additional boolean columns to the lookup table that ends up populating the drop-down select menu. These additional columns would be specially and specifically named, and if these columns are ever exposed to the end-user admin in any sort of a CRUD functionality, the business logic of the site would ensure that for any one column, only one row had it checked off, and for any one row, only one column could be checked off (to ensure vertical and horizontal uniqueness).
The one benefit to these columns is that the code in the web page is somewhat easy to program for. Since we are bringing in the lookup table as a list to populate the drop-down select menu, we are also able to write out the array (including the boolean columns) into an inline piece of JQuery that can pair up the ID (which could be anything) with a boolean value for a specific column name. Once the drop-down select menu has focused on that specific ID, the JQuery would then know what to do because that ID has the boolean value of TRUE for a specific column that is associated with a specific chuck of JQuery actions.
The drawback is that any sort of a well-populated lookup table would then have many, many boolean columns. And adding a value to that lookup table (when it has added associated on-page functionality) would require both a code change and a database change (to add a new column). This is also brittle in that the code needs to explicitly know the column names (the boolean values) to pair up primary keys with actions.
My other method is a little simpler: adding the actual IDs of the lookup table items (the relevant ones with additional actions, that is) to a Resources file. This lets the code look at the resources file, bring that into the same JQuery script as above, and do the same thing.
This has the additional benefit of needing only a code change; there is no change to the structure of the database, and so it is simpler. However, in this case the actual ID of the lookup table items that change page functionality are being added directly to a resource file - this makes it brittle. If an item gets deleted out of the lookup table and re-created, there will be no way for an end-user admin to update the resource file on their own, unlike an admin backend with the appropriate CRUD interface that can re-associate that entry with its needed action (the boolean column in the first example).
I am hoping that someone out there might know of a third path that fully decouples the recognition of the data from either the code or the database structure, such that a more flexible, less brittle option can be constructed.
[DotNet MVC 5] Question: how to decouple the identification of specific data from both code and DB structure -- how to tell code when data is special without hard-coding the data’s primary keys into the code or relying on special database structure to annotate each row.