Answer the question
In order to leave comments, you need to log in
How to make a multi-level referral system using SequelizeJs?
Hello, how can I implement a multi-level referral system using SequelizeJs?
Now I have a single-level one, in the table with the user there is a ref field, and a link has been added. Thus, I can get a user and a referral, but I can no longer get a referral of a referral.
const users = sequelize.define('users', {
login: {
type: Sequelize.STRING,
allowNull: false,
unique: true
},
password: {
type: Sequelize.STRING,
allowNull: false
},
ref: {
type: Sequelize.INTEGER ,
allowNull: true,
foreignKey : true
}
})
users.hasMany(users, {foreignKey: 'ref', as: 'userRefList'})
users.belongsTo(users, {foreignKey : 'ref', as: 'userRef'})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question