升级到v1.0后,Sails停止工作。我面临着一对一协会的问题。
module.exports = {
attributes: {
id: {
type: 'number',
autoIncrement: true
},
name: {
type: 'string',
required: true,
description: 'Full representation of the user\'s name',
maxLength: 120,
example: 'Lisa Microwave van der Jenny'
},
hospitals: {
collection: 'hospital',
via: 'users'
},
profile: {
collection: 'profile',
via: 'userId'
}
}
};
轮廓
module.exports = {
attributes: {
id: {
type: 'number',
autoIncrement: true
},
type: {
type: 'string',
required: true,
},
userId: {
model: 'user'
}
},
};
之前我通过在用户数据中传递个人资料来存储用户个人资料,如下所示。
const userParams = {
"name": "farhan1",
"hospitals": [1],
"profile": {
"type": "Cool"
}
};
User.create(userParams, (err, created) => {
console.log(err, created, 'COOL');
if(err) {return res.serverError(err);}
return res.ok(created);
});
但是使用sails v1它不允许我这样做,它会抛出错误
UsageError: Invalid new record.
Details:
Could not use specified `profile`. If specified, expected profile`
to be an array of ids (representing the records to associate). But
instead, got: { type: 'Cool' }
如果我错过了什么或做错了什么,请告诉我?
由于