鍍金池/ 問(wèn)答/Linux  數(shù)據(jù)庫(kù)  HTML/ sequelize hasMany 查詢

sequelize hasMany 查詢

app.model.Article.hasMany(app.model.ArticleComment);
app.model.User.hasMany(app.model.ArticleComment);
ctx.model.Article.findById(id,{include:[{model:ctx.model.ArticleComment}]});

查出了文章和文章的評(píng)論。但我還想查出評(píng)論對(duì)應(yīng)的會(huì)員信息。

ctx.model.Article.findById(id,{include:[{model:ctx.model.ArticleComment,include:[ctx.model.User]}]});

我這樣查又會(huì)報(bào)user is not associated to article_comment!
但我的article_comment表明明有userId啊

回答
編輯回答
局外人
ctx.model.Article.findById(id,{include:[{model:ctx.model.ArticleComment,include:[{model:ctx.model.User]}]});

一級(jí)model怎么include,子級(jí)就怎么include

2017年10月12日 01:16