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 に答える