我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