PS
Size: a a a
PS
PS
PS
User.belongsToMany(User, {
foreignKey: 'userId',
as: 'followers',
through: 'Following'
});
User.belongsToMany(User, {
foreignKey: 'followerId',
as: 'followings',
through: 'Following'
});
User.hasMany(Post, {
foreignKey: 'userId'
});
Post.belongsTo(User, {
foreignKey: 'userId'
});
GS
GS
User.belongsToMany(User, {
foreignKey: 'userId',
as: 'followers',
through: 'Following'
});
User.belongsToMany(User, {
foreignKey: 'followerId',
as: 'followings',
through: 'Following'
});
User.hasMany(Post, {
foreignKey: 'userId'
});
Post.belongsTo(User, {
foreignKey: 'userId'
});
PS
GS
GS
news = await Post.findAll({
where: {category},
include: [{
model: User,
where: {userId},
include: [{
model: User,
as: 'followings'
}]
}, 'post']
});
Post.findAll({
where: {category},
include: [{
model: User,
required: true,
include: [{
association: 'followings',
required: true,
through: {
where: { userId }
}
}]
}, 'post'] // зачем тут post?
});
GS
PS
GS
PS
PS
PS
W
‹
V
GS
V
V