database design - How to model an attribute with ordered states? -


Working with the state with features is something that I have done many times, for example, a problem Any problem in tracker can be open , pending , or off . To make sorting and easy to ask questions, it is fascinating to store the state as an integer. However, does it make it less trivial to add new states? For example, a new state, delayed , which comes between pending and off , will present problems when the state has an integer Is stored in the form.

Is there an integer like an integer to use a type or type to accumulate a problem without compromising compatibility?

One approach comes to mind avoiding the latter values ​​ 0 to open and 1 Instead of specifying pending , 10 to open and 20 to pending to expandability Is it a normal pattern to leave the room?

I think the use of integer with a certain offset (like 10, 20, ..) There is only one hack, but there is no general conceptual solution to your problem.

A common solution is to use two positive-integer values ​​in a class (such as state ) properties (like enumNo and seqNo < / Code>), to provide an identifier for the state (identifying code), and to define a linear order.


Comments