dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

Enum values are not checked when using sqlite driver #654

Open rhodri opened 8 years ago

rhodri commented 8 years ago

When using the sqlite driver:

var model = db.define('MyModel', {
  thing: { type: 'enum', values: ['myValue'], required: true }
});

model.create({ thing: 'invalidValue' }, function (err, created) {
  // This succeeds... but it shouldn't
});

I realise that enum types are not available in SQLite – but surely the ORM should be verifying it, not the driver!

dxg commented 8 years ago

I whole heartedly agree. There are other problems with the current enum situation - namely that once created they can be difficult to change or drop.

I use a different approach alltogether:

var THINGS = ['cat', 'dog'];

# properties
thing:                    { type: 'text', defaultValue: 'cat',  required: true }
# validations
thing: orm.validators.insideList(THINGS, "Invalid thing")

It's much easier to work with and I don't have so many columns in the table for space to be a problem.