1

如果我的架构如下:

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 对象的数据创建以下表:

  1. 配置
  2. 网络服务
4

1 回答 1

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){

     });
});
于 2013-11-08T18:18:17.420 回答