如何将链接图中的元素作为javascript函数中的链接值放置? 我已经尝试过(.getRecord()。field('@ rid'))
我正在尝试在时间序列数据中添加一些条目:
var db = orient.getDatabase();
var createdYear = db.save({ "@class" : "Year", year : year});
var createdMonth = db.save({ "@class" : "Month", month : month});
var createdDay = db.save({ "@class" : "Day", day : day});
var createdHour = db.save({ "@class" : "Hour", hour : hour});
var createdMinute = db.save({ "@class" : "Minute", minute : minute});
db.command( "update Year put month = \"?\", ? where year = ?", [ month, createdMonth.getRecord(), year ] );
db.command( "update ? put day = \"?\", ?", [ createdMonth.getRecord(), day, createdDay.getRecord() ] );
db.command( "update ? put hour = \"?\", ?", [ createdDay.getRecord(), hour, createdHour.getRecord() ] );
db.command( "update ? put minute = \"?\", ?", [ createdHour.getRecord(), minute, createdMinute.getRecord() ] );
return true;
我收到以下错误:
{
"errors": [
{
"code": 500,
"reason": 500,
"content": "com.orientechnologies.orient.core.exception.OCommandExecutionException: field day defined of type LINKMAP accept only link values\r\n\tStorage URL=\"plocal:/Users/alexandre/Desktop/prototype-api/orientdb-community-2.2.0/bin/~/orientdb/databases/prototype\""
}
]
}
我的数据库架构:
create class Year extends V;
create class Month extends V;
create class Day extends V;
create class Hour extends V;
create class Minute extends V;
create property Year.year integer;
create index Year.year ON Year(year) UNIQUE_HASH_INDEX;
create property Year.month LINKMAP Month;
create property Month.day LINKMAP Day;
create property Day.hour LINKMAP Hour;
create property Hour.minute LINKMAP Minute;
create property Minute.log LINKMAP V;
create property Minute.minute integer;
答案 0 :(得分:0)
查询构建器不格式化@rid字段,因此使用sql命令的字符串可以工作:
var db = orient.getDatabase();
var createdYear = db.save({ "@class" : "Year", year : year});
var createdMonth = db.save({ "@class" : "Month", month : month});
var createdDay = db.save({ "@class" : "Day", day : day});
var createdHour = db.save({ "@class" : "Hour", hour : hour});
var createdMinute = db.save({ "@class" : "Minute", minute : minute});
var updateYearString = "update Year put month = \""+month+"\", "+ createdMonth.getRecord().field('@rid') + " where year = "+year;
var updateMonthString = "update "+ createdMonth.getRecord().field('@rid') + " put day = \""+day+"\", "+ createdDay.getRecord().field('@rid');
var updateDayString = "update "+ createdDay.getRecord().field('@rid') + " put hour = \""+hour+"\", "+ createdHour.getRecord().field('@rid');
var updateHourString = "update "+ createdHour.getRecord().field('@rid') + " put minute = \""+minute+"\", "+ createdMinute.getRecord().field('@rid');
db.command(updateYearString);
db.command(updateMonthString);
db.command(updateDayString);
db.command(updateHourString);
return true;