我想列出所有用户 ConversationData(一个用户有很多 CovnresationData),但是当我按照官方网站上的教程进行操作时,我得到了“未定义”。帮助,伙计们!
var User = db.define("user", {
name : String,
surname : String,
avatar : String,
username : String,
token : String
}, {
autoSave: true
});
var Conversation = db.define("conversations", {
name : Number,
createdAt : Date,
updatedAt : Date
});
var ConversationData = db.define("conversation_data", {
user_id : Number,
conversation_id : Number
});
db.sync();
User.hasMany('conversationsData', ConversationData, {}, {
autoFetch: true
});
User.find({id: 1}).first(function(err, asda) {
cconsole.log(asda.conversationsData);
});
输出:
(orm/postgres) SELECT "t1"."user_id", "t1"."conversation_id", "t1"."id" FROM "conversation_data" "t1" JOIN "user_conversationsData" "t2" ON "t2"."conversationsdata_id" = "t1"."id" WHERE "t2"."user_id" = 1
undefined
在我看来,请求完全错误。据我了解,它必须加入用户和对话数据表。