Was du beschreibst, ist eine Selbstassoziation, du musst also hasMany nur einmal aufrufen. Sequelize erstellt die Kreuzungstabelle für dich:
User.hasMany(User, { as: 'Contacts', joinTableName: 'userHasContacts'}) Was eine Tabelle dieser Form erzeugt:
CREATE TABLE IF NOT EXISTS `userHasContacts` (`userId` INTEGER , `ContactsId` INTEGER , `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`userId`,`ContactsId`)) ENGINE=InnoDB; Nutzer zusammen mit ihren Kontakten abzufragen wird dann zu:
User.find({ where: ..., include: [{model: User, as: 'Contacts'}]}) Beachte, dass die Assoziation gerichtet ist, sofern du nicht auch das umgekehrte belongsToMany deklarierst – Freundschaft ist also nicht automatisch gegenseitig.