Node/Koa2[63]:首页功能
·
Yin灏
-
修改数据模型:Blog 关联 UserRelation
-
查看模板代码
-
开发路由(渲染页面)& 加载更多
-
单元测试
数据模型
// src/db/model/index.js
//...
const User = require("./User");
const Blog = require("./Blog");
const UserRelation = require("./UserRelation");
//...
Blog.belongsTo(User, {
foreignKey: "UserId",
});
UserRelation.belongsTo(User, {
foreignKey: "followerId",
});
User.hasMany(UserRelation, {
foreignKey: "userId",
});
Blog.belongsTo(UserRelation, {
foreignKey: "userId",
targetKey: "followerId",
});
//...
module.exports = {
User,
Blog,
UserRelation,
};
同步数据库
node src/db/sync.js