水线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' } } });
我希望能够在两个模型之间创造一个边缘。 用户创build一个问题,然后用户可以发布一个响应。
你的答案有一个错字:
questions: { collection: 'questions', via: 'answer' }
应该
questions: { collection: 'questions', via: 'answers' // answers as that is the attribute name in questions model }
示例来创build问题,答案然后链接它们:
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上创build了一个运行示例。
问候
更新: waterline-orientdb现在被命名为sails-orientdb。
- 一起添加一个hex值的数组
- Nodejs – HTTP范围支持/部分文件下载
- 我得到的消息:“(#100)没有find匹配的用户”,当使用facebook messenger bot示例教程代码
- Node.jsselect.msi或.exe
- 当有两个使用variables时,node.js减less了背景属性
- testingREST API – req.body undefined(Node.js / Express / Mocha / Supertest)
- 如何禁用socket.io中的客户端日志logging
- nodejs sessionStore与cloudant app.use不一致的执行
- 从SQL中的序列获取最后一个值并将其插入到另一个表(Oracle)中