解决方法:
利用实例的 get set方法,代码如下:
const sequelize = require('../db');
const { DataTypes } = require('sequelize');
const Line = sequelize.define('Line',{
value:{
type:DataTypes.STRING,
allowNull:false
},
dataOne:{
type:DataTypes.STRING,
allowNull:false,
get(){
return this.getDataValue('dataOne').split(',');
},
set(value){
return this.setDataValue('dataOne',value.join(','))
}
},
}
创建实例的时候直接写数组,代码如下:
const Mock = require('mockjs');
const data = Mock.mock({
'items|3':[
{
'value|+1':0,
'dataOne|30':['@float(0,0.9,1,1)'],
}
]
}).items;
const Line = require('../../models/home/Line');
Line.bulkCreate(data);