Question

I often write code that has a dependency on a database entity. I want to minimize the coupling between those different systems (or make it explicit and robust).

Example: I have a dropdown list of error categories, the users can define new categories, but one category is special in that errors belonging to it get an extra input field. So the system needs to know when the user has selected the special category and this special category is not allowed to just disappear.

How would you handle that special category? Would you match on on the category name or id? would you put the entity in the migration or have your code regenerate it as needed? Do you omit it from the database and have it only exist in your code? I find myself picking new solutions every time this problem presents itself, but I'm never quite satisfied with them.

Has anyone found a satisfactory solution? What drawbacks have you found and how have you mitigated them?

Was it helpful?

Solution

I dislike special case code, so I would design it to all be in the data model. The database would get a can delete field, and a has special entry field with some way to describe what that special input is. I would also try to make sure that I didn't over design the special input stuff since there is only this case so far.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top