Node.js 水线方向DB-双向边缘

Node.js 水线方向DB-双向边缘,node.js,sails.js,orientdb,waterline,sails-orientdb,Node.js,Sails.js,Orientdb,Waterline,Sails Orientdb,我在Sails中声明了两个模型,我正在使用Waterline Orientdb适配器,不知道如何通过双向边缘连接它们 问题模型 var Waterline = require('waterline'); module.exports = Waterline.Collection.extend({ tableName: 'questionsTable', identity: 'questions', connection: 'associations', attributes

我在Sails中声明了两个模型,我正在使用Waterline Orientdb适配器,不知道如何通过双向边缘连接它们

问题模型

var Waterline = require('waterline');

module.exports = Waterline.Collection.extend({

  tableName: 'questionsTable',
  identity: 'questions',
  connection: 'associations',

  attributes: {
    id: { type: 'string', primaryKey: true, columnName: '@rid'},
    question  : { type: 'string'},
    user: { model: "User", required: true },
    answerOptions: {type: 'json'},
    imagefile: {type:'string'},
    answers: {
      collection: 'answer',
      via: 'questions',
      dominant:true
    }
  }

});
应答模型

var Waterline = require('waterline');

module.exports = Waterline.Collection.extend({

    tableName: 'answerTable',
    identity: 'answer',
    connection: 'associations',

    attributes: {
        id: {
            type: 'string',
            primaryKey: true,
            columnName: '@rid'
        },
        Answer: {
            type: 'string'
        },
        questions: {
            collection: 'questions',
            via: 'answer'
        }

    }
});

我希望能够在两个模型之间创建一条边。用户创建一个问题,然后用户可以发布响应

您的答案模型上有一个输入错误:

questions: {
  collection: 'questions',
  via: 'answer'
}
应该是

questions: {
  collection: 'questions',
  via: 'answers'  // answers as that is the attribute name in questions model
}
创建问题、答案并将其链接的示例:

var question1;
ontology.collections.questions.create({ question: 'question1' })
  .then(function(question){
    question1 = question;

    return ontology.collections.answer.create([{ answer: 'answer1' }, { answer: 'answer2' }]);
  })
  .then(function(answers){
    question1.answers.add(answers[0]);
    question1.answers.add(answers[1]);

    return question1.save();
  })
我在上创建了一个运行示例

问候


更新:水线定向数据库现在命名为sails定向数据库。

一个问题可以有许多答案,但一个答案只能有一个问题,似乎您需要将答案中的问题标签更改为
问题{model:'question'}
,这是正确的。但是我想对这个模型进行多对多的建模,并希望获得优势。我将如何做到这一点?