We need to support an ENUM type and add it to all the major adapters as well as the waterline-adapter-tests
I added support for enums in validations. It's really just an alias for the in validation on strings.
I'm punting off native ENUM support in the adapters for now and will come back to it later. Too much other stuff that needs to be done before that.
Custom types might solve this, see https://github.com/balderdashy/waterline/pull/72
But to be fair, where: { foo: [a,b,c] } (IN) queries are already supported, and ENUM validations are supported in anchor, so IMO, ENUM type support is really more about the adapters optimizing the storage and indexing around values which must be members of a particular set.
Could the ENUM type process this?
attributes: {
state: {
type: 'int',
enum: {'pending':2, 'approved':3, 'denied':4]
}
}
Hi,
any updates on the last comment? ==>
attributes: {
state: {
type: 'int',
enum: {'pending':2, 'approved':3, 'denied':4]
}
}
Thanks
enum: {'pending':2, 'approved':3, 'denied':4]
How would this work, exactly? You set the value to "pending" and it stores in the database as 2? I suppose you could map this yourself in the beforeValidate lifecycle callback.
Yes. the string is used to display or assignment, but integer is stored in database.
This is can be general pattern defined in scheme. no need to write code again and again in the beforeValidate callback.
It could be a feature; I agree that it'd be a nice option to have. I can review a PR if you'd like to implement it.
+1 :)
In my case, run with:
status: {
type: 'STRING',
isIn: ['pending', 'approved'],
columnType: "enum('pending', 'approved')",
},
`status` enum('pending','approved') DEFAULT NULL,