Sails.js composite unique field

百般思念 提交于 2019-12-04 18:21:49

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/24923750/sails-js-composite-unique-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!