该模型以重复数据和总体丑陋为代价,给了我想要的效果:
//Example var Example = { attributes: { foo: { type: 'string', required: true }, bar: { type: 'string', required: true, }, baz: { type: 'integer', required: true, min: 1 }, foobar: { type: 'string', unique: true } }, beforeValidation : function(values,cb) { values.foobar = values.foo+values.bar; cb(); } }; module.exports = Example;
是否有更好的策略来创建复合唯一密钥?
没有办法直接在帆上做这件事 https://github.com/balderdashy/waterline/issues/221 。最好的解决方案是直接在计划使用的数据库中执行此操作。