我MongooseJS架构如下:MongooseJS架构关系
var UserSchema = new Schema({
name : String,
app_key : String,
app_secret : String,
tasks : [{ type : Schema.ObjectId,
ref : 'Task'}]
})
var ActionSchema = new Schema({
name : String,
description : String,
module : String
})
var enumTaskState = ['New', 'Indexing', 'Idle', 'In Queue', 'Working'];
var TaskSchema = new Schema({
name : String,
lastPerformed : Date,
folder : String,
actions : [{type : Schema.ObjectId,
ref : 'Task'}],
user : { type : Schema.ObjectId,
ref : 'User'},
status : { type : String,
enum : enumTaskState,
default : 'New'}
})
问题是,当我设置任务的用户,我必须手动去用户和添加任务有太多?这似乎是额外的工作(冗余),mongoosejs中是否有一个选项可以让我指定它将自己处理所有事情的关系? 谢谢。
如何创建新任务并将其关联到用户? – chovy 2012-09-28 19:40:21
'var newTask = new Task({....,user:user._id}); newTask.save(savedTask);''' – staackuser2 2012-09-28 22:59:23