如果我的架构如下:
var Configuration = describe('Configuration', function () {
property('name', String);
set('restPath', pathTo.configurations);
});
var Webservice = describe('Webservice', function () {
property('wsid', String);
property('url', String);
});
Configuration.hasMany(Webservice, { as: 'webservices', foreignKey: 'cid'});
反映了这样的数据:
var configurationJson = {
"name": "SafeHouseConfiguration2",
"webServices": [
{"wsid": "mainSectionWs", "url":"/apiAccess/getMainSection" },
{"wsid": "servicesSectionWs", "url":"/apiAccess/getServiceSection" }
]
};
我不应该使用以下内容来播种mongoDB:
var configSeed = configurationJson;
Configuration.create(configSeed, function (err, configuration) {
)};
将使用json对象中的数据创建以下表:
答案 0 :(得分:0)
由于这不像我预期的那样有效,我的种子文件最终如下:
/db/seeds/development/Configuration.js
var configurationJson = {
"name": "SafeHouseConfiguration2",
"webServices": [
{"wsid": "mainSectionWs", "url":"/apiAccess/getMainSection" },
{"wsid": "servicesSectionWs", "url":"/apiAccess/getServiceSection" }
]
};
Configuration.create(configurationJson, function (err, configuration) {
//Webservices config
var webservicesConfig = configSeed.webServices;
webservicesConfig.forEach(function(wsConfig){
configuration.webservices.create(wsConfig, function(err){
});
});