Sails.js 复合唯一字段 [英] Sails.js composite unique field
本文介绍了Sails.js 复合唯一字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个模型以重复数据和一般丑陋为代价给了我想要的效果:
This model gives me the effect I want at the expense of duplicated data and general uglyness:
//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;
是否有更好的策略来创建复合唯一键?
Is there a better strategy for creating a composite unique key?
推荐答案
在sails 中没有办法直接做到这一点,参见https://github.com/balderdashy/waterline/issues/221.最好的解决方案是直接在您计划使用的数据库中执行此操作.
There's no way to do this directly in sails see https://github.com/balderdashy/waterline/issues/221. The best solution is to do this directly in the db you plan to use.
这篇关于Sails.js 复合唯一字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文