mysql - How to join twice a single table in sequelize using following and followers example -


this code running perfectly. can following , followers need see followers getting following them ?

this question how can make query/subquery followers table , see following followers.

follower table

export default function(sequelize, datatypes) {   return sequelize.define('follower', {     _id: {       type: datatypes.integer,       allownull: false,       primarykey: true,       autoincrement: true     },     userid: {       type: datatypes.integer,       allownull: false     },     followingid: {       type: datatypes.integer,       allownull: false     }   }); } 

association

db.follower.belongsto(db.user, {as:'following', foreignkey: 'followingid'}); db.follower.belongsto(db.user, {as:'follower', foreignkey: 'userid'}); 

query

follower.findall({         where: {             followingid: userid         },         attributes: ['_id'],         include: [           {             model: user,             attributes: ['fullname', 'username', '_id', 'picture'],             as: 'follower'           }         ]     }) 

update

i have achieve desired result form row query :

select  f.userid, f.`followingid` , f1.`followingid` isfollowing , u.`fullname` followers f  inner join users u on userid = u._id  left join followers f1 on f.userid = f1.followingid  f.followingid = 142  

still struggling in sequelize.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -