I saw this issue on the official redis-om repository (here: redis/redis-om-node#86) and got a bit confused.
Today while writing some code i got an idea on how to do it that i will probably implement in the future:
// create a enum on the schema
somefield: {
type: "enum",
fields: [
"FieldWithValue0",
"FieldWithValue1",
// You could also use strings as values
{ FieldWithValue300: 300 },
"FieldWithValue301"
]
}
// using it (this is the complicated part)
// the database would return a number which would need to be mapped back
const data = await model.get(someId)
data.somefield // this is a number (lets say 1 for the sake of the example)
// this is how you would map it back
model.enums.somefield[data.somefield] // returns "FieldWithValue1"
I saw this issue on the official redis-om repository (here: redis/redis-om-node#86) and got a bit confused.
Today while writing some code i got an idea on how to do it that i will probably implement in the future: