Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I was wonder what people do in this situation.

You have an admin area of a system where you let users define a list of values they want to see in a dropdowns across the system.

What do you do in your application is a user wants to delete this option?

What do you do with data records which already use this value?

share|improve this question
1  
How have you stored the data? Are there foreign key constraints? What are the requirements for how the system works? –  MichaelT Apr 9 '13 at 20:02
    
My example is MS SQL server with entity framework code first and i should really have constraints. –  Jonathan D Apr 9 '13 at 20:08
    
Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask –  gnat Apr 10 '13 at 4:53
1  
Are you talking about deleting a single item or the whole edit section? If it's a single item: check if it's used and give an error message (either plain reject deletion or offer to remove together with the connections it has if that's technically possible) –  thorsten müller Apr 10 '13 at 7:38

2 Answers 2

up vote 3 down vote accepted

One option is to implement a "no longer in use" flag. Existing records remain the same (& the value continues to be visible where it was used), but it's no longer available as an option on the dropdowns.

share|improve this answer
    
+1. We use this pattern (called "soft-deleting") extensively at work, and it's probably the best way to handle a situation like this. –  Mason Wheeler Apr 9 '13 at 20:18
    
Same here. Taking it one step further, we often have start and end dates for items as well. –  jmo21 Apr 9 '13 at 20:22

I've had good experiences using a IsVisible flag. A bit like this (consider the following to be pseudocode):

public class CustomLookup
{
    public int ID { get; set; }
    public string Title { get; set; } // drop down text
    public string Description { get; set; } // hover text
    public bool IsVisible { get; set; }

    // this method is likely a repository method, but here for convenience
    public static IEnumerable<CustomLookup> LookupValues()
    {
        return repo.CustomLookups.Where(lookup => lookup.IsVisible);
    }
}

Some notes:

  • It's really simple and easy to maintain in my experience.
  • When making a lookup item invisible, there needs to be business rules to determine what happens to items that are flagged with that lookup item. Do you force them all into a new/existing one? Do nothing? That's a bit up to your business and the specific information that the lookup represents.
  • This permits the ability to keep historical information without much worry or fuss for reporting and whatnot, while still permitting the user to do what you describe.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.