2017-12-06 14 views
0

工場の女の子のインスタンスを作成します。これは私のデータは、データベースのように見えるものである別の工場の女の子のインスタンスを作成するための内部

{ 
    "id": 4, 
    "name": "New Sad", 
    "open": true, 
    "description": "The happiest place on earth!", 
    "gps": "133.232, 121.021", 
    "regionId": 1, 
    "location": "{\"regionName\":\"Bishop\",\"regionId\":1}", 
    "updatedAt": "2017-12-06T05:24:44.683Z", 
    "createdAt": "2017-12-06T05:24:44.683Z" 
} 

私はjsonb列をHAVA、これは、クエリその理由を検索するための場ですべての親テーブルですは私がfactory.assocを使用していない理由です。私はassocを使用してすぐに作成するものを参照することはできません。

私の工場-女の子を定義するには、私はちょうどこの操作を行うと考えていた:

module.exports = async factory => { 
    const region = await factory.create('region'); 
    const area = factory.define('area', Area,() => { 
    return { 
     name: factory.chance('first'), 
     open: true, 
     description: factory.chance('sentence', {words: 5}), 
     gps: '122.123, 123.342', 
     regionId: factory.assoc('region', 'id'), 
     location: JSON.stringify({ 
     regionName: region.dataValues.name, 
     regionId: region.dataValues.id, 
     }), 
    }; 
    }); 
    return area; 
}; 

エラーメッセージ:それは私がそれを試みた最初の時間を動作しませんでした

(node:49078) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Invalid factory 'region requested (node:49078) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

答えて

0

わからない理由これは今のように機能します:

const Area = require('../../src/models').Area; 

module.exports = factory => { 
    const area = factory.define('area', Area, async() => { 
    const region = await factory.create('region'); 
    return { 
     name: factory.chance('first'), 
     open: true, 
     description: factory.chance('sentence', {words: 5}), 
     gps: '122.123, 123.342', 
     regionId: region.dataValues.id, 
     location: JSON.stringify({ 
     regionName: region.dataValues.name, 
     regionId: region.dataValues.id, 
     }), 
    }; 
    }); 
    return area; 
}; 
関連する問題