Thursday 1 June 2017

sequelize - how to do add additional fields to through

either the docs are old or I'm misunderstanding, or there's a bug. In any case:

const User = sequelize.define('user', {})
const Project = sequelize.define('project', {})
const UserProjects = sequelize.define('userProjects', {
    status: Sequelize.STRING
})

User.belongsToMany(Project, { through: UserProjects })
Project.belongsToMany(User, { through: UserProjects })

sequelize.sync().then(v => {

    var user, project;
    User.create({}).then(_user => {
        user = _user;

        Project.create({}).then(_project => {
            project = _project;
            // project.addUser(user, { through: { status: 'started' } })
            user.addProject(project, { through: { status: 'started' } });


        })
    })

})

The following should create an association with the status field populated, however it's null.

AM I missing something



via Ahmed-Anas

No comments:

Post a Comment