Waterline-OrientDB - 双向边
Waterline-OrientDB - Bi-Directional Edge
我在 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'
}
}
});
我希望能够在两个模型之间创建一个边缘。用户创建一个问题,然后用户可以 post 回复。
您的答案模型有错别字:
questions: {
collection: 'questions',
via: 'answer'
}
应该是
questions: {
collection: 'questions',
via: 'answers' // answers as that is the attribute name in questions model
}
创建问题、答案然后 link 它们的示例:
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();
})
我在 github.com/appscot/waterline-orientdb 创建了一个 运行 示例。
此致
更新: waterline-orientdb 现在命名为 sails-orientdb。
我在 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'
}
}
});
我希望能够在两个模型之间创建一个边缘。用户创建一个问题,然后用户可以 post 回复。
您的答案模型有错别字:
questions: {
collection: 'questions',
via: 'answer'
}
应该是
questions: {
collection: 'questions',
via: 'answers' // answers as that is the attribute name in questions model
}
创建问题、答案然后 link 它们的示例:
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();
})
我在 github.com/appscot/waterline-orientdb 创建了一个 运行 示例。
此致
更新: waterline-orientdb 现在命名为 sails-orientdb。